Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ec96db5

Browse files
committed
checkout test: add core.filemode checkout tests
Add two tests for filemode. The first ensures that `core.filemode=true` is honored: if we have changed the filemode such that a file that _was_ executable (mode 0755) is now executable (mode 0644) and we go to check out a branch that has otherwise changed the contents of the file, then we should raise a checkout conflict for that file. The second ensures that `core.filemode=false` is honored: in the same situation, we set a file that was executable to be non-executable, and check out the branch that changes the contents of the file. However, since `core.filemode` is false, we do not detect the filemode change. We run these tests on both operating systems that obey `core.filemode` (eg, POSIX) and those that have no conception of filemode (eg, Win32). This ensures that `core.filemode` is always honored, as it is a cache of the underlying filesystem's settings. This ensures that we do not make assumptions based on the operating system, and honor the configuration setting even if it were misconfigured.
1 parent 18d9c84 commit ec96db5

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

tests/checkout/head.c

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,3 +181,59 @@ void test_checkout_head__typechange_index_and_workdir(void)
181181
git_object_free(target);
182182
git_index_free(index);
183183
}
184+
185+
void test_checkout_head__obeys_filemode_true(void)
186+
{
187+
git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
188+
git_object *target, *branch;
189+
190+
opts.checkout_strategy = GIT_CHECKOUT_FORCE;
191+
192+
/* In this commit, `README` is executable */
193+
cl_git_pass(git_revparse_single(&target, g_repo, "f9ed4af42472941da45a3c"));
194+
cl_git_pass(git_reset(g_repo, target, GIT_RESET_HARD, NULL));
195+
196+
cl_repo_set_bool(g_repo, "core.filemode", true);
197+
cl_must_pass(p_chmod("testrepo/README", 0644));
198+
199+
/*
200+
* Checkout will fail with a conflict; the file mode is updated in
201+
* the checkout target, but the contents have changed in our branch.
202+
*/
203+
cl_git_pass(git_revparse_single(&branch, g_repo, "099fabac3a9ea935598528c27f866e34089c2eff"));
204+
205+
opts.checkout_strategy &= ~GIT_CHECKOUT_FORCE;
206+
opts.checkout_strategy |= GIT_CHECKOUT_SAFE;
207+
cl_git_fail_with(GIT_ECONFLICT, git_checkout_tree(g_repo, branch, NULL));
208+
209+
git_object_free(branch);
210+
git_object_free(target);
211+
}
212+
213+
void test_checkout_head__obeys_filemode_false(void)
214+
{
215+
git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
216+
git_object *target, *branch;
217+
218+
opts.checkout_strategy = GIT_CHECKOUT_FORCE;
219+
220+
/* In this commit, `README` is executable */
221+
cl_git_pass(git_revparse_single(&target, g_repo, "f9ed4af42472941da45a3c"));
222+
cl_git_pass(git_reset(g_repo, target, GIT_RESET_HARD, NULL));
223+
224+
cl_repo_set_bool(g_repo, "core.filemode", false);
225+
cl_must_pass(p_chmod("testrepo/README", 0644));
226+
227+
/*
228+
* Checkout will fail with a conflict; the file contents are updated
229+
* in the checkout target, but the filemode has changed in our branch.
230+
*/
231+
cl_git_pass(git_revparse_single(&branch, g_repo, "099fabac3a9ea935598528c27f866e34089c2eff"));
232+
233+
opts.checkout_strategy &= ~GIT_CHECKOUT_FORCE;
234+
opts.checkout_strategy |= GIT_CHECKOUT_SAFE;
235+
cl_git_pass(git_checkout_tree(g_repo, branch, NULL));
236+
237+
git_object_free(branch);
238+
git_object_free(target);
239+
}

0 commit comments

Comments
 (0)