feat: added a simple filesystem tree walk and the status cli command to get a list of untracked files

This commit is contained in:
lisk77 2025-08-20 21:44:04 +02:00
parent 8b862f8b87
commit c372a5f8bc
5 changed files with 174 additions and 7 deletions

View file

@ -9,6 +9,7 @@
#include "file.h"
#include "myers.h"
#include "utilities.h"
#include "tree.h"
static void usage(int exitcode) {
printf("usage: merk <command> [<args>]\n\n init Initializes a repository in the current directory\n diff Displays the difference between the given two files\n");
@ -22,7 +23,7 @@ int main(int argc, char **argv) {
const char* subcmd = argv[1];
if (strcmp(subcmd, "diff") != 0 && strcmp(subcmd, "init") != 0) {
if (strcmp(subcmd, "diff") != 0 && strcmp(subcmd, "init") != 0 && strcmp(subcmd, "status") != 0) {
fprintf(stderr, "ERROR: Unknown subcommand: '%s'\n", subcmd);
usage(2);
}
@ -55,7 +56,7 @@ int main(int argc, char **argv) {
// Prints out a visual representation of the diff of the files provided
else if (strcmp(subcmd, "diff") == 0) {
if (argc != 4) {
printf("ERROR: too many/too little arguments given!\n");
printf("ERROR: too many/little arguments given!\n");
printf("Usage: merk diff <PATH> <PATH>");
exit(1);
}
@ -82,6 +83,26 @@ int main(int argc, char **argv) {
if (!actions) printf("ERROR: something went wrong while taking the diff!");
else visualize_diff(file1, file2, actions);
}
// TODO: Make it repo specific and not universal
// Gives a list of untracked files in the filesystem
else if (strcmp(subcmd, "status") == 0) {
if (argc != 2) {
printf("ERROR: too many arguments given!\n");
printf("Usage: merk status");
exit(1);
}
printf("Untracked files:\n\n");
PathBuffer* files = new_path_buffer();
walk(".", "./", files);
for (size_t i = 0; i < files->len; i++) {
printf("%s\n", files->paths[i]);
}
free_path_buffer(files);
return 0;
}
else {
usage(1);
}