Skip to content

Commit

Permalink
[~] The git branch is now recursive
Browse files Browse the repository at this point in the history
  • Loading branch information
toro-nicolas committed May 7, 2024
1 parent 935db2b commit d5669f7
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions src/prompt/git_repository.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,40 @@ static void current_branch(void)
close(fd);
}

/**
* @brief Change the path to the previous folder
* @param path The path to change
* @return <b>void</b>
*/
static void previous_folder(char *path)
{
for (int index = my_strlen(path) - 1; index >= 0; index--) {
if (path[index] == '/') {
path[index] = '\0';
break;
}
}
}

/**
* @brief Check if we are in a git repository and display the branch
* @return <b>void</b>
*/
void is_git_repository(void)
{
if (access(".git", X_OK) == 0) {
my_printf("\033[32m 🐱\033[0m");
current_branch();
char *pwd = getcwd(NULL, 0);
char *path = my_strdup(pwd);

while (my_str_contains(path, "/")) {
if (access(".git", X_OK) == 0) {
my_printf("\033[32m 🐱\033[0m");
current_branch();
break;
}
previous_folder(path);
chdir(path);
}
chdir(pwd);
FREE(pwd);
FREE(path);
}

0 comments on commit d5669f7

Please sign in to comment.