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

Skip to content

Commit 275693e

Browse files
committed
checkout test: ensure workdir mode is simplified
Ensure that when examining the working directory for checkout that the mode is correctly simplified. Git only pays attention to whether a file is executable or not. When examining a working directory, we should coalesce modes in the working directory to either `0755` (indicating that a file is executable) or `0644` (indicating that it is not). Test this by giving the file an exotic mode, and ensuring that when checkout out a branch that changes the file's contents, that we do not have a checkout conflict.
1 parent ec96db5 commit 275693e

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

tests/checkout/head.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,33 @@ void test_checkout_head__typechange_index_and_workdir(void)
182182
git_index_free(index);
183183
}
184184

185+
void test_checkout_head__workdir_filemode_is_simplified(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+
cl_git_pass(git_revparse_single(&target, g_repo, "a38d028f71eaa590febb7d716b1ca32350cf70da"));
193+
cl_git_pass(git_reset(g_repo, target, GIT_RESET_HARD, NULL));
194+
195+
cl_must_pass(p_chmod("testrepo/branch_file.txt", 0666));
196+
197+
/*
198+
* Checkout should not fail with a conflict; though the file mode
199+
* on disk is literally different to the base (0666 vs 0644), Git
200+
* ignores the actual mode and simply treats both as non-executable.
201+
*/
202+
cl_git_pass(git_revparse_single(&branch, g_repo, "099fabac3a9ea935598528c27f866e34089c2eff"));
203+
204+
opts.checkout_strategy &= ~GIT_CHECKOUT_FORCE;
205+
opts.checkout_strategy |= GIT_CHECKOUT_SAFE;
206+
cl_git_pass(git_checkout_tree(g_repo, branch, NULL));
207+
208+
git_object_free(branch);
209+
git_object_free(target);
210+
}
211+
185212
void test_checkout_head__obeys_filemode_true(void)
186213
{
187214
git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;

0 commit comments

Comments
 (0)