patch: fix rename text to binary file (issue2400) stable
authorPatrick Mezard <pmezard@gmail.com>
Mon, 27 Sep 2010 22:47:10 +0200
branchstable
changeset 12574 77600d697d0e
parent 12571 2702bea2ee76
child 12575 9b3913baba0c
patch: fix rename text to binary file (issue2400)
mercurial/patch.py
tests/test-git-import
tests/test-git-import.out
--- a/mercurial/patch.py	Mon Sep 27 10:48:21 2010 -0500
+++ b/mercurial/patch.py	Mon Sep 27 22:47:10 2010 +0200
@@ -1184,7 +1184,9 @@
                 gp.path = pathstrip(gp.path, strip - 1)[1]
                 if gp.oldpath:
                     gp.oldpath = pathstrip(gp.oldpath, strip - 1)[1]
-                if gp.op in ('COPY', 'RENAME'):
+                # Binary patches really overwrite target files, copying them
+                # will just make it fails with "target file exists"
+                if gp.op in ('COPY', 'RENAME') and not gp.binary:
                     copyfn(gp.oldpath, gp.path, cwd)
                 changed[gp.path] = gp
         else:
--- a/tests/test-git-import	Mon Sep 27 10:48:21 2010 -0500
+++ b/tests/test-git-import	Mon Sep 27 22:47:10 2010 +0200
@@ -1,5 +1,7 @@
 #!/bin/sh
 
+. $TESTDIR/helpers.sh
+
 hg init a
 cd a
 
@@ -226,5 +228,20 @@
 copy to foo3
 EOF
 hg tip -q
+cat foo3
 
-cat foo3
+echo % move text file and patch as binary
+echo a > text2
+hg ci -Am0
+hg import -d "1000000 0" -m rename-as-binary - <<"EOF"
+diff --git a/text2 b/binary2
+rename from text2
+rename to binary2
+index 78981922613b2afb6025042ff6bd878ac1994e85..10efcb362e9f3b3420fcfbfc0e37f3dc16e29757
+GIT binary patch
+literal 5
+Mc$`b*O5$Pw00T?_*Z=?k
+
+EOF
+cat binary2 | repr
+hg st --copies --change .
\ No newline at end of file
--- a/tests/test-git-import.out	Mon Sep 27 10:48:21 2010 -0500
+++ b/tests/test-git-import.out	Mon Sep 27 22:47:10 2010 +0200
@@ -80,3 +80,10 @@
 applying patch from stdin
 14:c4cd9cdeaa74
 foo
+% move text file and patch as binary
+adding text2
+applying patch from stdin
+'a\nb\n\x00'
+A binary2
+  text2
+R text2