-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
114 lines (109 loc) · 5.04 KB
/
Main.java
File metadata and controls
114 lines (109 loc) · 5.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package gitlet;
/** Driver class for Gitlet, a subset of the Git version-control system.
* @author TODO
*/
public class Main {
/** Usage: java gitlet.Main ARGS, where ARGS contains
* <COMMAND> <OPERAND1> <OPERAND2> ...
*/
public static void main(String[] args) {
if (args.length == 0) {
System.out.println("Please enter a command.");
} else {
String firstArg = args[0];
switch (firstArg) {
case "add-remote":
Remote.newRemote(args[1], args[2]);
break;
case "rm-remote":
Remote.rmRemote(args[1]);
break;
case "fetch":
Remote.fetch(args[1], args[2]);
break;
default:
if (Repository.GITLET_DIR.exists()) {
switch (firstArg) {
case "add":
if (args.length == 2 && args[1] != null)
Repository.add(args[1]);
else {
System.out.println("Incorrect operands.");
}
break;
case "commit":
if (args.length == 2 && args[1] != null && !args[1].equals("")) {
Repository.commit(args[1], null);
} else {
System.out.println("Please enter a commit message.");
}
break;
case "log":
Repository.log();
break;
case "checkout":
if (args.length == 2) {
Repository.checkoutBranch(args[1]);
} else if (args.length == 3) {
Repository.headCheckout(args[2]);
} else if (args.length == 4 && args[2].equals("--")) {
Repository.checkoutByCommit(args[1], args[3]);
} else {
System.out.println("Incorrect operands.");
}
break;
case "find":
if (args.length == 2 && args[1] != null) {
Repository.find(args[1]);
} else {
System.out.println("Incorrect operands.");
}
break;
case "rm":
if (args.length == 2 && args[1] != null)
Repository.rm(args[1]);
else {
System.out.println("Incorrect operands.");
}
break;
case "global-log":
Repository.globalLog();
break;
case "status":
Repository.status();
break;
case "branch":
if (args.length == 2 && args[1] != null)
Repository.newBranch(args[1]);
else {
System.out.println("Incorrect operands.");
}
break;
case "rm-branch":
if (args.length == 2 && args[1] != null)
Repository.removeBranch(args[1]);
else {
System.out.println("Incorrect operands.");
}
break;
case "reset":
if (args.length == 2 && args[1] != null) {
Repository.reset(args[1]);
} else {
System.out.println("Incorrect operands."); }
break;
case "merge":
Repository.merge(args[1]);
break;
case "test":
break;
default:
System.out.println("No command with that name exists.");
}
} else {
System.out.println("Not in an initialized Gitlet directory.");
}
}
}
}
}