Merge pull request #3516 from libgit2/cmn/repository-state-sequencer repository: distinguish sequencer cherry-pick and revert
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
diff --git a/include/git2/repository.h b/include/git2/repository.h
index cf268ef..85b7e68 100644
--- a/include/git2/repository.h
+++ b/include/git2/repository.h
@@ -675,7 +675,9 @@ typedef enum {
GIT_REPOSITORY_STATE_NONE,
GIT_REPOSITORY_STATE_MERGE,
GIT_REPOSITORY_STATE_REVERT,
+ GIT_REPOSITORY_STATE_REVERT_SEQUENCE,
GIT_REPOSITORY_STATE_CHERRYPICK,
+ GIT_REPOSITORY_STATE_CHERRYPICK_SEQUENCE,
GIT_REPOSITORY_STATE_BISECT,
GIT_REPOSITORY_STATE_REBASE,
GIT_REPOSITORY_STATE_REBASE_INTERACTIVE,
diff --git a/src/refs.h b/src/refs.h
index f78ea06..fda9532 100644
--- a/src/refs.h
+++ b/src/refs.h
@@ -44,6 +44,11 @@
#define GIT_REBASE_APPLY_APPLYING_FILE GIT_REBASE_APPLY_DIR "applying"
#define GIT_REFS_HEADS_MASTER_FILE GIT_REFS_HEADS_DIR "master"
+#define GIT_SEQUENCER_DIR "sequencer/"
+#define GIT_SEQUENCER_HEAD_FILE GIT_SEQUENCER_DIR "head"
+#define GIT_SEQUENCER_OPTIONS_FILE GIT_SEQUENCER_DIR "options"
+#define GIT_SEQUENCER_TODO_FILE GIT_SEQUENCER_DIR "todo"
+
#define GIT_STASH_FILE "stash"
#define GIT_REFS_STASH_FILE GIT_REFS_DIR GIT_STASH_FILE
diff --git a/src/repository.c b/src/repository.c
index c61d0e4..6234cd5 100644
--- a/src/repository.c
+++ b/src/repository.c
@@ -2222,11 +2222,17 @@ int git_repository_state(git_repository *repo)
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))
+ 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_CHERRYPICK_HEAD_FILE))
+ if (git_path_contains_file(&repo_path, GIT_SEQUENCER_TODO_FILE)) {
+ state = GIT_REPOSITORY_STATE_REVERT_SEQUENCE;
+ }
+ } else if (git_path_contains_file(&repo_path, GIT_CHERRYPICK_HEAD_FILE)) {
state = GIT_REPOSITORY_STATE_CHERRYPICK;
- else if(git_path_contains_file(&repo_path, GIT_BISECT_LOG_FILE))
+ if (git_path_contains_file(&repo_path, GIT_SEQUENCER_TODO_FILE)) {
+ state = GIT_REPOSITORY_STATE_CHERRYPICK_SEQUENCE;
+ }
+ } else if (git_path_contains_file(&repo_path, GIT_BISECT_LOG_FILE))
state = GIT_REPOSITORY_STATE_BISECT;
git_buf_free(&repo_path);
@@ -2271,6 +2277,7 @@ static const char *state_files[] = {
GIT_BISECT_LOG_FILE,
GIT_REBASE_MERGE_DIR,
GIT_REBASE_APPLY_DIR,
+ GIT_SEQUENCER_DIR,
};
int git_repository_state_cleanup(git_repository *repo)
diff --git a/tests/repo/state.c b/tests/repo/state.c
index bf2633c..7f20eeb 100644
--- a/tests/repo/state.c
+++ b/tests/repo/state.c
@@ -57,6 +57,15 @@ void test_repo_state__revert(void)
assert_repo_state(GIT_REPOSITORY_STATE_NONE);
}
+void test_repo_state__revert_sequence(void)
+{
+ setup_simple_state(GIT_REVERT_HEAD_FILE);
+ setup_simple_state(GIT_SEQUENCER_TODO_FILE);
+ assert_repo_state(GIT_REPOSITORY_STATE_REVERT_SEQUENCE);
+ cl_git_pass(git_repository_state_cleanup(_repo));
+ assert_repo_state(GIT_REPOSITORY_STATE_NONE);
+}
+
void test_repo_state__cherry_pick(void)
{
setup_simple_state(GIT_CHERRYPICK_HEAD_FILE);
@@ -65,6 +74,15 @@ void test_repo_state__cherry_pick(void)
assert_repo_state(GIT_REPOSITORY_STATE_NONE);
}
+void test_repo_state__cherrypick_sequence(void)
+{
+ setup_simple_state(GIT_CHERRYPICK_HEAD_FILE);
+ setup_simple_state(GIT_SEQUENCER_TODO_FILE);
+ assert_repo_state(GIT_REPOSITORY_STATE_CHERRYPICK_SEQUENCE);
+ cl_git_pass(git_repository_state_cleanup(_repo));
+ assert_repo_state(GIT_REPOSITORY_STATE_NONE);
+}
+
void test_repo_state__bisect(void)
{
setup_simple_state(GIT_BISECT_LOG_FILE);