1
0
mirror of https://github.com/git/git synced 2024-06-30 22:54:27 +00:00

Merge branch 'cp/apply-core-filemode'

"git apply" on a filesystem without filemode support have learned
to take a hint from what is in the index for the path, even when
not working with the "--index" or "--cached" option, when checking
the executable bit match what is required by the preimage in the
patch.

* cp/apply-core-filemode:
  apply: code simplification
  apply: correctly reverse patch's pre- and post-image mode bits
  apply: ignore working tree filemode when !core.filemode
This commit is contained in:
Junio C Hamano 2024-02-26 18:10:24 -08:00
commit cf47fb7ec7
2 changed files with 40 additions and 3 deletions

16
apply.c
View File

@ -2219,7 +2219,8 @@ static void reverse_patches(struct patch *p)
struct fragment *frag = p->fragments;
SWAP(p->new_name, p->old_name);
SWAP(p->new_mode, p->old_mode);
if (p->new_mode)
SWAP(p->new_mode, p->old_mode);
SWAP(p->is_new, p->is_delete);
SWAP(p->lines_added, p->lines_deleted);
SWAP(p->old_oid_prefix, p->new_oid_prefix);
@ -3777,8 +3778,17 @@ static int check_preimage(struct apply_state *state,
return error_errno("%s", old_name);
}
if (!state->cached && !previous)
st_mode = ce_mode_from_stat(*ce, st->st_mode);
if (!state->cached && !previous) {
if (*ce && !(*ce)->ce_mode)
BUG("ce_mode == 0 for path '%s'", old_name);
if (trust_executable_bit)
st_mode = ce_mode_from_stat(*ce, st->st_mode);
else if (*ce)
st_mode = (*ce)->ce_mode;
else
st_mode = patch->old_mode;
}
if (patch->is_new < 0)
patch->is_new = 0;

View File

@ -103,4 +103,31 @@ test_expect_success POSIXPERM 'do not use core.sharedRepository for working tree
)
'
test_expect_success 'git apply respects core.fileMode' '
test_config core.fileMode false &&
echo true >script.sh &&
git add --chmod=+x script.sh &&
git ls-files -s script.sh >ls-files-output &&
test_grep "^100755" ls-files-output &&
test_tick && git commit -m "Add script" &&
git ls-tree -r HEAD script.sh >ls-tree-output &&
test_grep "^100755" ls-tree-output &&
echo true >>script.sh &&
test_tick && git commit -m "Modify script" script.sh &&
git format-patch -1 --stdout >patch &&
test_grep "^index.*100755$" patch &&
git switch -c branch HEAD^ &&
git apply --index patch 2>err &&
test_grep ! "has type 100644, expected 100755" err &&
git reset --hard &&
git apply patch 2>err &&
test_grep ! "has type 100644, expected 100755" err &&
git apply --cached patch 2>err &&
test_grep ! "has type 100644, expected 100755" err
'
test_done