diff --git a/mercurial/patch.py b/mercurial/patch.py --- a/mercurial/patch.py +++ b/mercurial/patch.py @@ -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) diff --git a/tests/test-import-unknown.t b/tests/test-import-unknown.t new file mode 100644 --- /dev/null +++ b/tests/test-import-unknown.t @@ -0,0 +1,67 @@ + $ cat <> $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] diff --git a/tests/test-mq-symlinks.t b/tests/test-mq-symlinks.t --- a/tests/test-mq-symlinks.t +++ b/tests/test-mq-symlinks.t @@ -106,18 +106,3 @@ replace broken symlink with another brok 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]