Skip to content

Commit c23cd78

Browse files
committed
Merge branch 'jt/apply-reverse-twice'
"git apply -R" did not handle patches that touch the same path twice correctly, which has been corrected. This is most relevant in a patch that changes a path from a regular file to a symbolic link (and vice versa). * jt/apply-reverse-twice: apply: when -R, also reverse list of sections
2 parents 73af6a4 + b0f266d commit c23cd78

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

apply.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4699,8 +4699,13 @@ static int apply_patch(struct apply_state *state,
46994699
reverse_patches(patch);
47004700
if (use_patch(state, patch)) {
47014701
patch_stats(state, patch);
4702-
*listp = patch;
4703-
listp = &patch->next;
4702+
if (!list || !state->apply_in_reverse) {
4703+
*listp = patch;
4704+
listp = &patch->next;
4705+
} else {
4706+
patch->next = list;
4707+
list = patch;
4708+
}
47044709

47054710
if ((patch->new_name &&
47064711
ends_with_path_components(patch->new_name,

t/t4114-apply-typechange.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,13 @@ test_expect_success 'symlink becomes file' '
8888
'
8989
test_debug 'cat patch'
9090

91+
test_expect_success 'symlink becomes file, in reverse' '
92+
git checkout -f foo-symlinked-to-bar &&
93+
git diff-tree -p HEAD foo-back-to-file > patch &&
94+
git checkout foo-back-to-file &&
95+
git apply -R --index < patch
96+
'
97+
9198
test_expect_success 'binary file becomes symlink' '
9299
git checkout -f foo-becomes-binary &&
93100
git diff-tree -p --binary HEAD foo-symlinked-to-bar > patch &&

t/t4127-apply-same-fn.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ test_expect_success 'apply same filename with independent changes' '
3232

3333
test_expect_success 'apply same filename with overlapping changes' '
3434
git reset --hard &&
35+
36+
# Store same_fn so that we can check apply -R in next test
37+
cp same_fn same_fn1 &&
38+
3539
modify "s/^d/z/" same_fn &&
3640
git diff > patch0 &&
3741
git add same_fn &&
@@ -43,6 +47,11 @@ test_expect_success 'apply same filename with overlapping changes' '
4347
test_cmp same_fn same_fn2
4448
'
4549

50+
test_expect_success 'apply same filename with overlapping changes, in reverse' '
51+
git apply -R patch0 &&
52+
test_cmp same_fn same_fn1
53+
'
54+
4655
test_expect_success 'apply same new filename after rename' '
4756
git reset --hard &&
4857
git mv same_fn new_fn &&

0 commit comments

Comments
 (0)