patch: do not patch unknown files (issue752)

This commit is contained in:
Patrick Mezard 2011-05-27 21:50:11 +02:00
parent d4b7db6294
commit ab82a700d3
3 changed files with 73 additions and 15 deletions

View File

@ -445,13 +445,19 @@ class workingbackend(fsbackend):
self.changed = set()
self.copied = []
def _checkknown(self, fname):
if self.repo.dirstate[fname] == '?' and self.exists(fname):
raise PatchError(_('cannot patch %s: file is not tracked') % fname)
def setfile(self, fname, data, mode, copysource):
self._checkknown(fname)
super(workingbackend, self).setfile(fname, data, mode, copysource)
if copysource is not None:
self.copied.append((copysource, fname))
self.changed.add(fname)
def unlink(self, fname):
self._checkknown(fname)
super(workingbackend, self).unlink(fname)
self.removed.add(fname)
self.changed.add(fname)

View File

@ -0,0 +1,67 @@
$ cat <<EOF >> $HGRCPATH
> [extensions]
> purge =
> EOF
$ hg init test
$ cd test
$ echo a > changed
$ echo a > removed
$ echo a > source
$ hg ci -Am addfiles
adding changed
adding removed
adding source
$ echo a >> changed
$ echo a > added
$ hg add added
$ hg rm removed
$ hg cp source copied
$ hg diff --git > ../unknown.diff
Test adding on top of an unknown file
$ hg up -qC 0
$ hg purge
$ echo a > added
$ hg import --no-commit ../unknown.diff
applying ../unknown.diff
file added already exists
1 out of 1 hunks FAILED -- saving rejects to file added.rej
abort: patch failed to apply
[255]
Test modifying an unknown file
$ hg revert -aq
$ hg purge
$ hg rm changed
$ hg ci -m removechanged
$ echo a > changed
$ hg import --no-commit ../unknown.diff
applying ../unknown.diff
abort: cannot patch changed: file is not tracked
[255]
Test removing an unknown file
$ hg up -qC 0
$ hg purge
$ hg rm removed
$ hg ci -m removeremoved
created new head
$ echo a > removed
$ hg import --no-commit ../unknown.diff
applying ../unknown.diff
abort: cannot patch removed: file is not tracked
[255]
Test copying onto an unknown file
$ hg up -qC 0
$ hg purge
$ echo a > copied
$ hg import --no-commit ../unknown.diff
applying ../unknown.diff
abort: cannot create copied: destination already exists
[255]

View File

@ -106,18 +106,3 @@ replace broken symlink with another broken symlink
now at: movelink
$ $TESTDIR/readlink.py linkb
linkb -> linkb
check patch does not overwrite untracked symlinks
$ hg qpop
popping movelink
now at: link
$ ln -s linkbb linkb
$ hg qpush
applying movelink
cannot create linkb: destination already exists
1 out of 1 hunks FAILED -- saving rejects to file linkb.rej
patch failed, unable to continue (try -v)
patch failed, rejects left in working dir
errors during apply, please fix and refresh movelink
[2]