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

Vsevolod Solovyov vsevolod.solovyov at gmail.com
Tue Mar 24 18:06:51 CDT 2009


# HG changeset patch
# User Vsevolod Solovyov <vsevolod.solovyov at gmail.com>
# Date 1237935990 0
# Node ID 360229b4e0983fa244465a3f8c7b663972249a60
# 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-patch-git b/tests/test-patch-git
new file mode 100755
--- /dev/null
+++ b/tests/test-patch-git
@@ -0,0 +1,20 @@
+#!/bin/sh
+
+hg init repo
+cd repo
+
+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 patch -m "commit2" a.patch
diff --git a/tests/test-patch-git.out b/tests/test-patch-git.out
new file mode 100644
--- /dev/null
+++ b/tests/test-patch-git.out
@@ -0,0 +1,2 @@
+adding a
+applying a.patch


More information about the Mercurial-devel mailing list