[PATCH 1 of 1] Fix issue1495, corner case of adding empty files via patching

Vsevolod Solovyov vsevolod.solovyov at gmail.com
Tue Mar 24 18:30:50 CDT 2009


# HG changeset patch
# User Vsevolod Solovyov <vsevolod.solovyov at gmail.com>
# Date 1237937335 0
# Node ID 2b49f9a9b45d297f8f32cfe40d81f1e3f1155a8b
# Parent  c2ecaf63badee4e973c4d843121139d4d3269f12
Fix issue1495, corner case of adding empty files via patching

diff --git a/mercurial/patch.py b/mercurial/patch.py
--- a/mercurial/patch.py
+++ b/mercurial/patch.py
@@ -910,7 +910,7 @@
                 # else error?
                 # copy/rename + modify should modify target, not source
                 gp = changed.get(bfile)
-                if gp and gp.op in ('COPY', 'DELETE', 'RENAME'):
+                if gp and gp.op in ('COPY', 'DELETE', 'RENAME', 'ADD'):
                     afile = bfile
                     gitworkdone = True
             newfile = True
diff --git a/tests/test-import b/tests/test-import
--- a/tests/test-import
+++ b/tests/test-import
@@ -313,3 +313,22 @@
 hg import --no-commit -v -s 100 ../rename.diff
 hg st -C
 cd ..
+
+
+echo '% add empty file from the end of patch (issue 1495)'
+hg init addemptyend
+cd addemptyend
+touch a
+hg addremove
+hg ci -m "commit"
+cat > a.patch <<EOF
+diff --git a/a b/a
+--- a/a
++++ b/a
+@@ -0,0 +1,1 @@
++a
+diff --git a/b b/b
+new file mode 100644
+EOF
+hg import --no-commit a.patch
+cd ..
diff --git a/tests/test-import.out b/tests/test-import.out
--- a/tests/test-import.out
+++ b/tests/test-import.out
@@ -293,3 +293,6 @@
 adding b
 A b
 R a
+% add empty file from the end of patch (issue 1495)
+adding a
+applying a.patch


More information about the Mercurial-devel mailing list