[PATCH stable] patch: allow empty patches on existing files (issue2135)
Durham Goode
durham at fb.com
Fri Oct 26 02:42:28 UTC 2012
# HG changeset patch
# User Durham Goode <durham at fb.com>
# Date 1351103179 25200
# Node ID e010bb5b0ee2f9e9241a3dddb7faf0fe2f22a71f
# Parent 917a37b76845811aaea1dc9b1ad0a8110e8b7439
patch: allow empty patches on existing files (issue2135)
When applying a patch that added an empty file,
the patch would fail if the file already existed at the destination.
This changes patch.py to succeed in that scenario, and emits a
warning message notifying the user of this case. Example:
file foo.py not changed: file already exists and patch file is empty
Adds a test for this in the transplant test suite, since that's
where the issue was originally encountered.
diff -r 917a37b76845 -r e010bb5b0ee2 mercurial/patch.py
--- a/mercurial/patch.py Tue Oct 23 09:28:42 2012 +0200
+++ b/mercurial/patch.py Wed Oct 24 11:26:19 2012 -0700
@@ -1328,10 +1328,14 @@
# must be created
data = ''
if data or mode:
- if (gp.op in ('ADD', 'RENAME', 'COPY')
+ if (gp.op in ('RENAME', 'COPY')
and backend.exists(gp.path)):
raise PatchError(_("cannot create %s: destination "
"already exists") % gp.path)
+ if (gp.op == 'ADD' and backend.exists(gp.path)):
+ ui.warn(_('file %s not changed: file already exists '
+ 'and file patch is empty\n') % gp.path)
+ continue
backend.setfile(gp.path, data, mode, gp.oldpath)
continue
try:
diff -r 917a37b76845 -r e010bb5b0ee2 tests/test-transplant.t
--- a/tests/test-transplant.t Tue Oct 23 09:28:42 2012 +0200
+++ b/tests/test-transplant.t Wed Oct 24 11:26:19 2012 -0700
@@ -632,6 +632,22 @@
skipping emptied changeset 7a7d57e15850
$ cd ..
+Issue2135: test transplanting an added empty file onto an existing file
+
+ $ hg init emptyfilerepo
+ $ cd emptyfilerepo
+ $ touch b3
+ $ hg ci -Am addb3
+ adding b3
+ $ cd ../t
+ $ hg transplant -s ../emptyfilerepo 0
+ searching for changes
+ warning: repository is unrelated
+ applying 74c381100194
+ file b3 not changed: file already exists and file patch is empty
+ skipping emptied changeset 74c381100194
+ $ cd ..
+
Explicitly kill daemons to let the test exit on Windows
$ "$TESTDIR/killdaemons.py" $DAEMON_PIDS
More information about the Mercurial-devel
mailing list