forked from SJTUJohnClass/gitlite
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
126 lines (119 loc) · 3.57 KB
/
main.cpp
File metadata and controls
126 lines (119 loc) · 3.57 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
115
116
117
118
119
120
121
122
123
124
125
126
#include <iostream>
#include <vector>
#include <string>
#include "include/SomeObj.h"
#include "include/Repository.h"
#include "include/Utils.h"
void checkCWD() {
if (!Utils::isDirectory(Repository::getGitliteDir())) {
Utils::exitWithMessage("Not in an initialized Gitlite directory.");
}
}
void checkNoArgs(const std::vector<std::string>& args) {
if (args.empty()) {
Utils::exitWithMessage("Please enter a command.");
}
}
void checkArgsNum(const std::vector<std::string>& args, int n) {
if (static_cast<int>(args.size()) != n) {
Utils::exitWithMessage("Incorrect operands.");
}
}
int main(int argc, char* argv[]) {
std::vector<std::string> args;
for (int i = 1; i < argc; ++i) {
args.push_back(std::string(argv[i]));
}
checkNoArgs(args);
SomeObj bloop;
std::string firstArg = args[0];
if (firstArg == "init") {
checkArgsNum(args, 1);
bloop.init();
} else if (firstArg == "add-remote") {
checkCWD();
checkArgsNum(args, 3);
bloop.addRemote(args[1], args[2]);
} else if (firstArg == "rm-remote") {
checkCWD();
checkArgsNum(args, 2);
bloop.rmRemote(args[1]);
} else if (firstArg == "add") {
checkCWD();
checkArgsNum(args, 2);
bloop.add(args[1]);
} else if (firstArg == "commit") {
checkCWD();
checkArgsNum(args, 2);
bloop.commit(args[1]);
} else if (firstArg == "rm") {
checkCWD();
checkArgsNum(args, 2);
bloop.rm(args[1]);
} else if (firstArg == "log") {
checkCWD();
checkArgsNum(args, 1);
bloop.log();
} else if (firstArg == "global-log") {
checkCWD();
checkArgsNum(args, 1);
bloop.globalLog();
} else if (firstArg == "find") {
checkCWD();
checkArgsNum(args, 2);
bloop.find(args[1]);
} else if (firstArg == "status") {
checkCWD();
checkArgsNum(args, 1);
bloop.status();
} else if (firstArg == "checkout") {
checkCWD();
if (args.size() == 2) {
bloop.checkoutBranch(args[1]);
} else if (args.size() == 3) {
if (args[1] != "--") {
Utils::exitWithMessage("Incorrect operands.");
}
bloop.checkoutFile(args[2]);
} else if (args.size() == 4) {
if (args[2] != "--") {
Utils::exitWithMessage("Incorrect operands.");
}
bloop.checkoutFileInCommit(args[1], args[3]);
} else {
Utils::exitWithMessage("Incorrect operands.");
}
} else if (firstArg == "branch") {
checkCWD();
checkArgsNum(args, 2);
bloop.branch(args[1]);
} else if (firstArg == "rm-branch") {
checkCWD();
checkArgsNum(args, 2);
bloop.rmBranch(args[1]);
} else if (firstArg == "reset") {
checkCWD();
checkArgsNum(args, 2);
bloop.reset(args[1]);
} else if (firstArg == "merge") {
checkCWD();
checkArgsNum(args, 2);
bloop.merge(args[1]);
} else if (firstArg == "push") {
checkCWD();
checkArgsNum(args, 3);
bloop.push(args[1], args[2]);
} else if (firstArg == "fetch") {
checkCWD();
checkArgsNum(args, 3);
bloop.fetch(args[1], args[2]);
} else if (firstArg == "pull") {
checkCWD();
checkArgsNum(args, 3);
bloop.pull(args[1], args[2]);
} else {
std::cout << "No command with that name exists." << std::endl;
return 0;
}
return 0;
}