Patches generated by "git format-patch -M -B" can't be applied with "git apply"?
- From
- Dan Kegel <dank@kegel.com>
- Date
- Sep 14, 2015, 22:21 UTC
- Message-ID
- <CAPF-yOb4dRWGLmL==x8=ifvU4Znsut9XQWMLPxBCPq7TzgJ84A@mail.gmail.com>
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