diff options
author | nulltoken <emeric.fermas@gmail.com> | 2012-10-27 09:30:03 +0200 |
---|---|---|
committer | nulltoken <emeric.fermas@gmail.com> | 2012-10-27 16:45:59 +0200 |
commit | 31966d20e3fcfb7283884e477fbbaf0cffd81c37 (patch) | |
tree | 6adcc122f19ea3aca47f3ff844c385899a2c1dd5 /src | |
parent | 00e161b977e9ca8529736e8222dff50111b6f898 (diff) | |
download | libgit2-31966d20e3fcfb7283884e477fbbaf0cffd81c37.tar.gz |
repo: enhance git_repository_state() detection
Diffstat (limited to 'src')
-rw-r--r-- | src/refs.h | 6 | ||||
-rw-r--r-- | src/repository.c | 21 |
2 files changed, 26 insertions, 1 deletions
diff --git a/src/refs.h b/src/refs.h index 58e2fd558..3a1f8cf33 100644 --- a/src/refs.h +++ b/src/refs.h @@ -33,6 +33,12 @@ #define GIT_MERGE_HEAD_FILE "MERGE_HEAD" #define GIT_REVERT_HEAD_FILE "REVERT_HEAD" #define GIT_CHERRY_PICK_HEAD_FILE "CHERRY_PICK_HEAD" +#define GIT_BISECT_LOG_FILE "BISECT_LOG" +#define GIT_REBASE_MERGE_DIR "rebase-merge/" +#define GIT_REBASE_MERGE_INTERACTIVE_FILE GIT_REBASE_MERGE_DIR "interactive" +#define GIT_REBASE_APPLY_DIR "rebase-apply/" +#define GIT_REBASE_APPLY_REBASING_FILE GIT_REBASE_APPLY_DIR "rebasing" +#define GIT_REBASE_APPLY_APPLYING_FILE GIT_REBASE_APPLY_DIR "applying" #define GIT_REFS_HEADS_MASTER_FILE GIT_REFS_HEADS_DIR "master" #define GIT_REFNAME_MAX 1024 diff --git a/src/repository.c b/src/repository.c index fa4604bee..0e416e0b8 100644 --- a/src/repository.c +++ b/src/repository.c @@ -1541,6 +1541,10 @@ cleanup: return error; } +/** + * Loosely ported from git.git + * https://github.com/git/git/blob/master/contrib/completion/git-prompt.sh#L198-289 + */ int git_repository_state(git_repository *repo) { git_buf repo_path = GIT_BUF_INIT; @@ -1548,15 +1552,30 @@ int git_repository_state(git_repository *repo) assert(repo); + if (!git_repository_head_detached(repo)) + return state; + if (git_buf_puts(&repo_path, repo->path_repository) < 0) return -1; - if (git_path_contains_file(&repo_path, GIT_MERGE_HEAD_FILE)) + if (git_path_contains_file(&repo_path, GIT_REBASE_MERGE_INTERACTIVE_FILE)) + state = GIT_REPOSITORY_STATE_REBASE_INTERACTIVE; + else if (git_path_contains_dir(&repo_path, GIT_REBASE_MERGE_DIR)) + state = GIT_REPOSITORY_STATE_REBASE_MERGE; + else if (git_path_contains_file(&repo_path, GIT_REBASE_APPLY_REBASING_FILE)) + state = GIT_REPOSITORY_STATE_REBASE; + else if (git_path_contains_file(&repo_path, GIT_REBASE_APPLY_APPLYING_FILE)) + state = GIT_REPOSITORY_STATE_APPLY_MAILBOX; + else if (git_path_contains_dir(&repo_path, GIT_REBASE_APPLY_DIR)) + state = GIT_REPOSITORY_STATE_APPLY_MAILBOX_OR_REBASE; + else if (git_path_contains_file(&repo_path, GIT_MERGE_HEAD_FILE)) state = GIT_REPOSITORY_STATE_MERGE; else if(git_path_contains_file(&repo_path, GIT_REVERT_HEAD_FILE)) state = GIT_REPOSITORY_STATE_REVERT; else if(git_path_contains_file(&repo_path, GIT_CHERRY_PICK_HEAD_FILE)) state = GIT_REPOSITORY_STATE_CHERRY_PICK; + else if(git_path_contains_file(&repo_path, GIT_BISECT_LOG_FILE)) + state = GIT_REPOSITORY_STATE_BISECT; git_buf_free(&repo_path); return state; |