threads / discuss / 40351

Patches generated by "git format-patch -M -B" can't be applied with "git apply"?

Subject: Patches generated by "git format-patch -M -B" can't be applied with "git apply"?

## tl;dr

3 messages between Sep 14, 2015 and Sep 14, 2015.

replies: 2people: 2as markdown or json

Dan Kegel· Sep 14, 2015, 22:21 UTC · lore
A bot I wrote uses 'git format-patch -M -B' to generate a patch
to send off to be applied with 'git am' on a remote machine.
Alas, renames do not appear to work; git am rejects them with
 error: file2: already exists in working directory
This happens both with the git that ships with Ubuntu 14.04
and with master ( git version 2.6.0.rc1.16.g1962994 ).
I noticed that git has a similar test case already,
t4130-apply-criss-cross-rename.sh
so I munged that to reproduce the error,
http://kegel.com/git/t4154-apply-half-criss-cross-rename.sh.txt
Running
 ./t4154-apply-half-criss-cross-rename.sh -v
fails for me reliably with
 error: file2: already exists in working directory
with either v2.6.0-rc2 or random local git on local Mac and Linux.
is this behavior indeed a bug, or am I breaking some rule?
Thanks!
- Dan

p.s. Here's the test case inline, but if email munges whitespace, the url above might be better.

#!/bin/sh

test_description='git apply handling half-criss-cross rename patch.' . ./test-lib.sh

create_file() {
        cnt=0
        while test $cnt -le 100
        do
                cnt=$(($cnt + 1))
                echo "$2" >> "$1"
        done
}
test_expect_success 'setup' '
        create_file file1 "File1 contents" &&
        create_file file2 "File2 contents" &&
        git add file1 file2 &&
        git commit -m 1
'
test_expect_success 'half criss-cross rename' '
        mv file1 file2 &&
        git rm file1 &&
        git add file2 &&
        git commit -m 2
'
test_expect_success 'diff -M -B' '
        git format-patch -M -B HEAD^ --stdout > diff &&
        git reset --hard HEAD^
'
test_expect_success 'apply' '
        git apply --check diff
'
test_done
Junio C Hamano· Sep 14, 2015, 22:32 UTC · re: Dan Kegel · lore

Re: Patches generated by "git format-patch -M -B" can't be applied with "git apply"?

Dan Kegel <dank@kegel.com> writes:

Yes, "diff -M -B" is known to be problematic, unfortunately. It incorrectly creates an irreversible patch under certain conditions.

http://thread.gmane.org/gmane.linux.kernel/1879635
Junio C Hamano· Sep 14, 2015, 22:32 UTC · re: Dan Kegel · lore

Re: Patches generated by "git format-patch -M -B" can't be applied with "git apply"?

Yes, "diff -M -B" is known to be problematic, unfortunately. It incorrectly creates an irreversible patch under certain conditions.

http://thread.gmane.org/gmane.linux.kernel/1879635

← back to recent threads