FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
gitlet/gitlet/gitlet/Main.java at master · xUser5000/gitlet · GitHub
xUser5000
/
gitlet
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
6
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
gitlet
/
gitlet
/
gitlet
/
Main.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
135 lines (128 loc) · 4.65 KB
Breadcrumbs
gitlet
/
gitlet
/
gitlet
/
Main.java
Copy path
File metadata and controls
135 lines (128 loc) · 4.65 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package
gitlet
;
import
static
gitlet
.
Utils
.*;
/** Driver class for Gitlet, a subset of the Git version-control system.
* @author xUser5000
*/
public
class
Main
{
/** Usage: java gitlet.Main ARGS, where ARGS contains
* <COMMAND> <OPERAND1> <OPERAND2> ...
*/
public
static
void
main
(
String
[]
args
) {
if
(
args
.
length
==
0
) {
exitWithMessage
(
"Please enter a command."
);
}
Repository
repository
=
new
Repository
(
System
.
getProperty
(
"user.dir"
));
String
command
=
args
[
0
];
String
fileName
;
String
message
;
String
commitHash
;
String
branchName
;
String
remoteName
;
String
remoteURI
;
try
{
switch
(
command
) {
case
"init"
:
validateNumArgs
(
args
,
1
);
repository
.
init
();
break
;
case
"add"
:
validateNumArgs
(
args
,
2
);
fileName
=
args
[
1
];
repository
.
add
(
fileName
);
break
;
case
"commit"
:
validateNumArgs
(
args
,
2
);
message
=
args
[
1
];
repository
.
commit
(
message
);
break
;
case
"rm"
:
validateNumArgs
(
args
,
2
);
fileName
=
args
[
1
];
repository
.
rm
(
fileName
);
break
;
case
"log"
:
validateNumArgs
(
args
,
1
);
repository
.
log
();
break
;
case
"global-log"
:
validateNumArgs
(
args
,
1
);
repository
.
globalLog
();
break
;
case
"find"
:
validateNumArgs
(
args
,
2
);
message
=
args
[
1
];
repository
.
find
(
message
);
break
;
case
"status"
:
validateNumArgs
(
args
,
1
);
repository
.
status
();
break
;
case
"checkout"
:
switch
(
args
.
length
) {
case
2
:
branchName
=
args
[
1
];
repository
.
checkoutBranch
(
branchName
);
break
;
case
3
:
if
(!
args
[
1
].
equals
(
"--"
))
incorrectOperands
();
fileName
=
args
[
2
];
repository
.
checkoutFile
(
fileName
);
break
;
case
4
:
if
(!
args
[
2
].
equals
(
"--"
))
incorrectOperands
();
commitHash
=
args
[
1
];
fileName
=
args
[
3
];
repository
.
checkoutFile
(
commitHash
,
fileName
);
break
;
default
:
incorrectOperands
();
}
break
;
case
"branch"
:
validateNumArgs
(
args
,
2
);
branchName
=
args
[
1
];
repository
.
branch
(
branchName
);
break
;
case
"rm-branch"
:
validateNumArgs
(
args
,
2
);
branchName
=
args
[
1
];
repository
.
rmBranch
(
branchName
);
break
;
case
"reset"
:
validateNumArgs
(
args
,
2
);
commitHash
=
args
[
1
];
repository
.
reset
(
commitHash
);
break
;
case
"merge"
:
validateNumArgs
(
args
,
2
);
branchName
=
args
[
1
];
repository
.
merge
(
branchName
);
break
;
case
"add-remote"
:
validateNumArgs
(
args
,
3
);
remoteName
=
args
[
1
];
remoteURI
=
args
[
2
];
repository
.
addRemote
(
remoteName
,
remoteURI
);
break
;
case
"rm-remote"
:
validateNumArgs
(
args
,
2
);
remoteName
=
args
[
1
];
repository
.
rmRemote
(
remoteName
);
break
;
default
:
exitWithMessage
(
"No command with that name exists."
);
}
}
catch
(
Exception
exception
) {
exception
.
printStackTrace
();
System
.
exit
(
0
);
}
}
public
static
void
validateNumArgs
(
String
[]
args
,
int
n
) {
if
(
args
.
length
!=
n
) {
incorrectOperands
();
}
}
public
static
void
incorrectOperands
() {
exitWithMessage
(
"Incorrect operands."
);
}
}
Back
|
FazBrowse Home
|
New Git URL