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
This commit is contained in:
Junio C Hamano 2020-11-02 13:17:43 -08:00
commit c23cd78e81
3 changed files with 23 additions and 2 deletions

View file

@ -4699,8 +4699,13 @@ static int apply_patch(struct apply_state *state,
reverse_patches(patch);
if (use_patch(state, patch)) {
patch_stats(state, patch);
*listp = patch;
listp = &patch->next;
if (!list || !state->apply_in_reverse) {
*listp = patch;
listp = &patch->next;
} else {
patch->next = list;
list = patch;
}
if ((patch->new_name &&
ends_with_path_components(patch->new_name,

View file

@ -88,6 +88,13 @@ test_expect_success 'symlink becomes file' '
'
test_debug 'cat patch'
test_expect_success 'symlink becomes file, in reverse' '
git checkout -f foo-symlinked-to-bar &&
git diff-tree -p HEAD foo-back-to-file > patch &&
git checkout foo-back-to-file &&
git apply -R --index < patch
'
test_expect_success 'binary file becomes symlink' '
git checkout -f foo-becomes-binary &&
git diff-tree -p --binary HEAD foo-symlinked-to-bar > patch &&

View file

@ -32,6 +32,10 @@ test_expect_success 'apply same filename with independent changes' '
test_expect_success 'apply same filename with overlapping changes' '
git reset --hard &&
# Store same_fn so that we can check apply -R in next test
cp same_fn same_fn1 &&
modify "s/^d/z/" same_fn &&
git diff > patch0 &&
git add same_fn &&
@ -43,6 +47,11 @@ test_expect_success 'apply same filename with overlapping changes' '
test_cmp same_fn same_fn2
'
test_expect_success 'apply same filename with overlapping changes, in reverse' '
git apply -R patch0 &&
test_cmp same_fn same_fn1
'
test_expect_success 'apply same new filename after rename' '
git reset --hard &&
git mv same_fn new_fn &&