-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.c
More file actions
40 lines (35 loc) · 1003 Bytes
/
Copy pathmain.c
File metadata and controls
40 lines (35 loc) · 1003 Bytes
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
#include <stdio.h>
#include <string.h>
#include "include/init.h"
#include "include/hash_object.h"
#include "include/tree.h"
#include "include/commit.h"
int main(int argc, char* argv[]){
if(argc <2){
printf("Usage: git<command>\n");
return 1;
}
if(strcmp(argv[1], "init") == 0){
git_init();
}else if(strcmp(argv[1], "hash-object") == 0){
hash_object("hello.txt");
}else if(strcmp(argv[1], "write-tree") == 0){
char sha1[41];
write_tree(".", sha1);
printf("tree: %s\n", sha1);
}else if(strcmp(argv[1], "commit") == 0){
if(argc <3){
printf("Usage: git commit <message>\n");
return 1;
}
char tree_hash[41];
write_tree(".", tree_hash);
char commit_hash[41];
write_commit(tree_hash, argv[2], commit_hash);
printf("commit: %s\n", commit_hash);
}else{
printf("Unknown command: %s\n", argv[1]);
return 1;
}
return 0;
}