diff --git a/include/utilities.h b/include/utilities.h index d2aaaa1..2d96e00 100644 --- a/include/utilities.h +++ b/include/utilities.h @@ -8,6 +8,7 @@ #include #include #include +#include #include "file.h" #include "action_list.h" diff --git a/src/main.c b/src/main.c index 1354654..35a6d4c 100644 --- a/src/main.c +++ b/src/main.c @@ -12,7 +12,11 @@ #include "tree.h" static void usage(int exitcode) { - printf("usage: merk []\n\n init Initializes a repository in the current directory\n diff Displays the difference between the given two files\n status Displays a list of modified and untracked files in the repository\n"); + printf("usage: merk []\n\ + \n init Initializes a repository in the current directory\ + \n diff Displays the difference between the given two files\ + \n files Displays a list of modified and untracked files in the repository\ + \n commit Record changes made to the repository\n"); exit(exitcode); } @@ -23,7 +27,11 @@ int main(int argc, char **argv) { const char* subcmd = argv[1]; - if (strcmp(subcmd, "diff") != 0 && strcmp(subcmd, "init") != 0 && strcmp(subcmd, "status") != 0) { + if (strcmp(subcmd, "diff") != 0 && + strcmp(subcmd, "init") != 0 && + strcmp(subcmd, "files") != 0 && + strcmp(subcmd, "commit") != 0 + ) { fprintf(stderr, "ERROR: Unknown subcommand: '%s'\n", subcmd); usage(2); } @@ -48,9 +56,13 @@ int main(int argc, char **argv) { } } - mkdir(".merk/files", 0700); - mkdir(".merk/trees", 0700); - mkdir(".merk/branches", 0700); + int fd = open(".merk/HEAD", O_WRONLY | O_CREAT, 0666); + if (fd < 0) return -1; + close(fd); + + mkdir(".merk/objects", 0755); + mkdir(".merk/refs", 0755); + mkdir(".merk/refs/branches", 0755); } // Prints out a visual representation of the diff of the files provided @@ -84,7 +96,7 @@ int main(int argc, char **argv) { else visualize_diff(file1, file2, actions); } // Gives a list of untracked files in the repo - else if (strcmp(subcmd, "status") == 0) { + else if (strcmp(subcmd, "files") == 0) { if (argc != 2) { printf("ERROR: too many arguments given!\n"); printf("Usage: merk status"); @@ -110,6 +122,13 @@ int main(int argc, char **argv) { free(root); return 0; } + else if (strcmp(subcmd, "commit") == 0) { + if (argc == 2) { + printf("ERROR: too little arguments given!\n"); + printf("Usage: merk commit [-m ] ..."); + exit(1); + } + } else { usage(1); }