feat: added a more general way to display relative paths for the status cli command
This commit is contained in:
parent
c372a5f8bc
commit
25480fc92f
4 changed files with 143 additions and 25 deletions
17
src/main.c
17
src/main.c
|
|
@ -12,7 +12,7 @@
|
|||
#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");
|
||||
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 status Displays a list of modified and untracked files in the repository\n");
|
||||
exit(exitcode);
|
||||
}
|
||||
|
||||
|
|
@ -83,8 +83,7 @@ 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
|
||||
// Gives a list of untracked files in the repo
|
||||
else if (strcmp(subcmd, "status") == 0) {
|
||||
if (argc != 2) {
|
||||
printf("ERROR: too many arguments given!\n");
|
||||
|
|
@ -92,15 +91,23 @@ int main(int argc, char **argv) {
|
|||
exit(1);
|
||||
}
|
||||
|
||||
printf("Untracked files:\n\n");
|
||||
PathBuffer* files = new_path_buffer();
|
||||
walk(".", "./", files);
|
||||
char relative[PATH_MAX] = "";
|
||||
char* root = find_root(relative);
|
||||
if (!root) {
|
||||
free_path_buffer(files);
|
||||
return 1;
|
||||
}
|
||||
|
||||
walk(root, relative, relative, files);
|
||||
|
||||
printf("Untracked files:\n\n");
|
||||
for (size_t i = 0; i < files->len; i++) {
|
||||
printf("%s\n", files->paths[i]);
|
||||
}
|
||||
|
||||
free_path_buffer(files);
|
||||
free(root);
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue