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

Skip to content

Commit 4e4771d

Browse files
committed
checkout test: further ensure workdir perms are updated
When both the index _and_ the working directory has changed permissions on a file permissions on a file - but only the permissions, such that the contents of the file are identical - ensure that `git_checkout` updates the permissions to match the checkout target.
1 parent 8858a68 commit 4e4771d

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

tests/checkout/head.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,3 +156,28 @@ void test_checkout_head__typechange_workdir(void)
156156

157157
git_object_free(target);
158158
}
159+
160+
void test_checkout_head__typechange_index_and_workdir(void)
161+
{
162+
git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
163+
git_object *target;
164+
git_index *index;
165+
struct stat st;
166+
167+
opts.checkout_strategy = GIT_CHECKOUT_FORCE;
168+
169+
cl_git_pass(git_revparse_single(&target, g_repo, "HEAD"));
170+
cl_git_pass(git_reset(g_repo, target, GIT_RESET_HARD, NULL));
171+
172+
cl_must_pass(p_chmod("testrepo/new.txt", 0755));
173+
cl_git_pass(git_repository_index(&index, g_repo));
174+
cl_git_pass(git_index_add_bypath(index, "new.txt"));
175+
cl_git_pass(git_index_write(index));
176+
cl_git_pass(git_checkout_head(g_repo, &opts));
177+
178+
cl_git_pass(p_stat("testrepo/new.txt", &st));
179+
cl_assert(!GIT_PERMS_IS_EXEC(st.st_mode));
180+
181+
git_object_free(target);
182+
git_index_free(index);
183+
}

0 commit comments

Comments
 (0)