Skip to content

Commit d896351

Browse files
author
Chandra Pratap
committedDec 14, 2023
Teach git apply to respect core.fileMode settings
CC: Johannes Schindelin <johannes.schindelin@gmail.com> Signed-off-by: Chandra Pratap <chandrapratap3519@gmail.com>
1 parent 1a87c84 commit d896351

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed
 

‎apply.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3778,8 +3778,11 @@ static int check_preimage(struct apply_state *state,
37783778
return error_errno("%s", old_name);
37793779
}
37803780

3781-
if (!state->cached && !previous)
3782-
st_mode = ce_mode_from_stat(*ce, st->st_mode);
3781+
if (!state->cached && !previous) {
3782+
if (!trust_executable_bit && patch->old_mode)
3783+
st_mode = patch->old_mode;
3784+
else st_mode = ce_mode_from_stat(*ce, st->st_mode);
3785+
}
37833786

37843787
if (patch->is_new < 0)
37853788
patch->is_new = 0;

‎t/t4129-apply-samemode.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,19 @@ test_expect_success POSIXPERM 'do not use core.sharedRepository for working tree
101101
)
102102
'
103103

104+
test_expect_success FILEMODE 'ensure git apply respects core.fileMode' '
105+
test_config core.fileMode false &&
106+
echo true >script.sh &&
107+
git add --chmod=+x script.sh &&
108+
test_tick && git commit -m "Add script" &&
109+
110+
echo true >>script.sh &&
111+
test_tick && git commit -m "Modify script" script.sh &&
112+
git format-patch -1 --stdout >patch &&
113+
114+
git switch -c branch HEAD^ &&
115+
git apply patch 2>err &&
116+
! test_grep "has type 100644, expected 100755" err
117+
'
118+
104119
test_done

0 commit comments

Comments
 (0)