Skip to content

Commit

Permalink
Teach git apply to respect core.fileMode settings
Browse files Browse the repository at this point in the history
CC: Johannes Schindelin <johannes.schindelin@gmail.com>
Signed-off-by: Chandra Pratap <chandrapratap3519@gmail.com>
  • Loading branch information
Chandra Pratap committed Dec 14, 2023
1 parent 1a87c84 commit d896351
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
7 changes: 5 additions & 2 deletions apply.c
Original file line number Diff line number Diff line change
Expand Up @@ -3778,8 +3778,11 @@ 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 (!trust_executable_bit && patch->old_mode)
st_mode = patch->old_mode;
else st_mode = ce_mode_from_stat(*ce, st->st_mode);
}

if (patch->is_new < 0)
patch->is_new = 0;
Expand Down
15 changes: 15 additions & 0 deletions t/t4129-apply-samemode.sh
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,19 @@ test_expect_success POSIXPERM 'do not use core.sharedRepository for working tree
)
'

test_expect_success FILEMODE 'ensure git apply respects core.fileMode' '
test_config core.fileMode false &&
echo true >script.sh &&
git add --chmod=+x script.sh &&
test_tick && git commit -m "Add script" &&
echo true >>script.sh &&
test_tick && git commit -m "Modify script" script.sh &&
git format-patch -1 --stdout >patch &&
git switch -c branch HEAD^ &&
git apply patch 2>err &&
! test_grep "has type 100644, expected 100755" err
'

test_done

0 comments on commit d896351

Please sign in to comment.