diff options
author | Squibid <me@zacharyscheiman.com> | 2024-12-19 09:12:37 -0600 |
---|---|---|
committer | Squibid <me@zacharyscheiman.com> | 2024-12-19 09:14:01 -0600 |
commit | fc0da57dff7d222a689e0c2ff13d0cd108f195f9 (patch) | |
tree | ff75b43b94f0fe7afd2527973c0c6521f249fd90 /XD.c | |
parent | 1a2fcaa6104caf3f9f06d6f4fdf20cc52e739075 (diff) | |
download | XD-fc0da57dff7d222a689e0c2ff13d0cd108f195f9.tar.gz XD-fc0da57dff7d222a689e0c2ff13d0cd108f195f9.tar.bz2 XD-fc0da57dff7d222a689e0c2ff13d0cd108f195f9.zip |
add nose for staged changes, and remove unnecessary includes
Diffstat (limited to 'XD.c')
-rw-r--r-- | XD.c | 40 |
1 files changed, 33 insertions, 7 deletions
@@ -7,12 +7,6 @@ #ifdef GIT #include <git2.h> -#include <git2/common.h> -#include <git2/errors.h> -#include <git2/global.h> -#include <git2/refs.h> -#include <git2/repository.h> -#include <git2/status.h> #endif enum face { EYES, NOSE, MOUTH }; @@ -126,6 +120,36 @@ has_untracked(git_repository *repo) git_status_list_free(list); return r; } + +int +has_staged(git_repository *repo) +{ + git_status_entry entry; + git_status_list *list = NULL; + int i, c, r = 0; + + if (git_status_list_new(&list, repo, NULL) < 0) { + l("Error checking for staged changes: %s", git_error_last()->message); + return 0; + } + + /* if any staged changes are found return 1 */ + if ((c = git_status_list_entrycount(list)) > 0) { + for (i = 0; i < c; i++) { + entry = *git_status_byindex(list, i); + + if (entry.status & GIT_STATUS_INDEX_NEW + || entry.status & GIT_STATUS_INDEX_DELETED + || entry.status & GIT_STATUS_INDEX_MODIFIED) { + r = 1; + break; + } + } + } + + git_status_list_free(list); + return r; +} #endif int @@ -153,7 +177,9 @@ main(int argc, char *argv[]) } /* change the nose depending on the current git repo's status */ - if (has_untracked(repo)) { + if (has_staged(repo)) { + face[NOSE] = '*'; /* change to broken nose for staged changes */ + } else if (has_untracked(repo)) { face[NOSE] = '^'; /* add a little nose when there are untracked changes in the repo */ } else if (git_repository_head_detached(repo)) { face[NOSE] = '-'; /* add a minus nose when the HEAD is detached */ |