]> git.proxmox.com Git - libgit2.git/blob - tests/repo/state.c
fb8949775a55b2e3fdf70ef011fd0bd463e192c0
[libgit2.git] / tests / repo / state.c
1 #include "clar_libgit2.h"
2 #include "buffer.h"
3 #include "refs.h"
4 #include "posix.h"
5 #include "fileops.h"
6
7 static git_repository *_repo;
8 static git_buf _path;
9
10 void test_repo_state__initialize(void)
11 {
12 _repo = cl_git_sandbox_init("testrepo.git");
13 }
14
15 void test_repo_state__cleanup(void)
16 {
17 cl_git_sandbox_cleanup();
18 git_buf_dispose(&_path);
19 }
20
21 static void setup_simple_state(const char *filename)
22 {
23 cl_git_pass(git_buf_joinpath(&_path, git_repository_path(_repo), filename));
24 git_futils_mkpath2file(git_buf_cstr(&_path), 0777);
25 cl_git_mkfile(git_buf_cstr(&_path), "dummy");
26 }
27
28 static void assert_repo_state(git_repository_state_t state)
29 {
30 cl_assert_equal_i(state, git_repository_state(_repo));
31 }
32
33 void test_repo_state__none_with_HEAD_attached(void)
34 {
35 assert_repo_state(GIT_REPOSITORY_STATE_NONE);
36 }
37
38 void test_repo_state__none_with_HEAD_detached(void)
39 {
40 cl_git_pass(git_repository_detach_head(_repo));
41 assert_repo_state(GIT_REPOSITORY_STATE_NONE);
42 }
43
44 void test_repo_state__merge(void)
45 {
46 setup_simple_state(GIT_MERGE_HEAD_FILE);
47 assert_repo_state(GIT_REPOSITORY_STATE_MERGE);
48 cl_git_pass(git_repository_state_cleanup(_repo));
49 assert_repo_state(GIT_REPOSITORY_STATE_NONE);
50 }
51
52 void test_repo_state__revert(void)
53 {
54 setup_simple_state(GIT_REVERT_HEAD_FILE);
55 assert_repo_state(GIT_REPOSITORY_STATE_REVERT);
56 cl_git_pass(git_repository_state_cleanup(_repo));
57 assert_repo_state(GIT_REPOSITORY_STATE_NONE);
58 }
59
60 void test_repo_state__revert_sequence(void)
61 {
62 setup_simple_state(GIT_REVERT_HEAD_FILE);
63 setup_simple_state(GIT_SEQUENCER_TODO_FILE);
64 assert_repo_state(GIT_REPOSITORY_STATE_REVERT_SEQUENCE);
65 cl_git_pass(git_repository_state_cleanup(_repo));
66 assert_repo_state(GIT_REPOSITORY_STATE_NONE);
67 }
68
69 void test_repo_state__cherry_pick(void)
70 {
71 setup_simple_state(GIT_CHERRYPICK_HEAD_FILE);
72 assert_repo_state(GIT_REPOSITORY_STATE_CHERRYPICK);
73 cl_git_pass(git_repository_state_cleanup(_repo));
74 assert_repo_state(GIT_REPOSITORY_STATE_NONE);
75 }
76
77 void test_repo_state__cherrypick_sequence(void)
78 {
79 setup_simple_state(GIT_CHERRYPICK_HEAD_FILE);
80 setup_simple_state(GIT_SEQUENCER_TODO_FILE);
81 assert_repo_state(GIT_REPOSITORY_STATE_CHERRYPICK_SEQUENCE);
82 cl_git_pass(git_repository_state_cleanup(_repo));
83 assert_repo_state(GIT_REPOSITORY_STATE_NONE);
84 }
85
86 void test_repo_state__bisect(void)
87 {
88 setup_simple_state(GIT_BISECT_LOG_FILE);
89 assert_repo_state(GIT_REPOSITORY_STATE_BISECT);
90 cl_git_pass(git_repository_state_cleanup(_repo));
91 assert_repo_state(GIT_REPOSITORY_STATE_NONE);
92 }
93
94 void test_repo_state__rebase_interactive(void)
95 {
96 setup_simple_state(GIT_REBASE_MERGE_INTERACTIVE_FILE);
97 assert_repo_state(GIT_REPOSITORY_STATE_REBASE_INTERACTIVE);
98 cl_git_pass(git_repository_state_cleanup(_repo));
99 assert_repo_state(GIT_REPOSITORY_STATE_NONE);
100 }
101
102 void test_repo_state__rebase_merge(void)
103 {
104 setup_simple_state(GIT_REBASE_MERGE_DIR "whatever");
105 assert_repo_state(GIT_REPOSITORY_STATE_REBASE_MERGE);
106 cl_git_pass(git_repository_state_cleanup(_repo));
107 assert_repo_state(GIT_REPOSITORY_STATE_NONE);
108 }
109
110 void test_repo_state__rebase(void)
111 {
112 setup_simple_state(GIT_REBASE_APPLY_REBASING_FILE);
113 assert_repo_state(GIT_REPOSITORY_STATE_REBASE);
114 cl_git_pass(git_repository_state_cleanup(_repo));
115 assert_repo_state(GIT_REPOSITORY_STATE_NONE);
116 }
117
118 void test_repo_state__apply_mailbox(void)
119 {
120 setup_simple_state(GIT_REBASE_APPLY_APPLYING_FILE);
121 assert_repo_state(GIT_REPOSITORY_STATE_APPLY_MAILBOX);
122 cl_git_pass(git_repository_state_cleanup(_repo));
123 assert_repo_state(GIT_REPOSITORY_STATE_NONE);
124 }
125
126 void test_repo_state__apply_mailbox_or_rebase(void)
127 {
128 setup_simple_state(GIT_REBASE_APPLY_DIR "whatever");
129 assert_repo_state(GIT_REPOSITORY_STATE_APPLY_MAILBOX_OR_REBASE);
130 cl_git_pass(git_repository_state_cleanup(_repo));
131 assert_repo_state(GIT_REPOSITORY_STATE_NONE);
132 }