D781: merge: check for path conflicts when updating
mbthomas (Mark Thomas)
phabricator at mercurial-scm.org
Fri Sep 22 09:28:36 UTC 2017
mbthomas created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.
REVISION SUMMARY
When updating to a new revision, check for path conflicts caused by unknown
files in the working directory, and handle these by backing up the file or
directory and replacing it.
REPOSITORY
rHG Mercurial
REVISION DETAIL
https://phab.mercurial-scm.org/D781
AFFECTED FILES
mercurial/merge.py
tests/test-merge1.t
tests/test-pathconflicts-basic.t
tests/test-update-names.t
CHANGE DETAILS
diff --git a/tests/test-update-names.t b/tests/test-update-names.t
--- a/tests/test-update-names.t
+++ b/tests/test-update-names.t
@@ -50,7 +50,8 @@
$ hg st
? name/file
$ hg up 1
- abort: *: '$TESTTMP/r1/r2/name' (glob)
+ name: untracked file differs
+ abort: untracked files in working directory differ from files in requested revision
[255]
$ cd ..
diff --git a/tests/test-pathconflicts-basic.t b/tests/test-pathconflicts-basic.t
--- a/tests/test-pathconflicts-basic.t
+++ b/tests/test-pathconflicts-basic.t
@@ -37,7 +37,8 @@
$ mkdir a
$ echo 3 > a/b
$ hg up file
- abort: *: '$TESTTMP/repo/a' (glob)
+ a: untracked file differs
+ abort: untracked files in working directory differ from files in requested revision
[255]
$ hg up --clean file
abort: *: '$TESTTMP/repo/a' (glob)
diff --git a/tests/test-merge1.t b/tests/test-merge1.t
--- a/tests/test-merge1.t
+++ b/tests/test-merge1.t
@@ -30,17 +30,17 @@
$ mkdir b && touch b/nonempty
$ hg up
- abort: *: '$TESTTMP/t/b' (glob)
+ b: untracked file differs
+ abort: untracked files in working directory differ from files in requested revision
[255]
$ hg ci
- abort: last update was interrupted
- (use 'hg update' to get a consistent checkout)
- [255]
+ nothing changed
+ [1]
$ hg sum
parent: 0:538afb845929
commit #0
branch: default
- commit: 1 unknown (interrupted update)
+ commit: 1 unknown (clean)
update: 1 new changesets (update)
phases: 2 draft
$ rm b/nonempty
diff --git a/mercurial/merge.py b/mercurial/merge.py
--- a/mercurial/merge.py
+++ b/mercurial/merge.py
@@ -673,6 +673,7 @@
choose a different action.
"""
fileconflicts = set()
+ pathconflicts = set()
warnconflicts = set()
abortconflicts = set()
unknownconfig = _getcheckunknownconfig(repo, 'merge', 'checkunknown')
@@ -688,11 +689,15 @@
if m in ('c', 'dc'):
if _checkunknownfile(repo, wctx, mctx, f):
fileconflicts.add(f)
+ elif f not in wctx:
+ path = _checkunknowndirs(repo, f)
+ if path is not None:
+ pathconflicts.add(path)
elif m == 'dg':
if _checkunknownfile(repo, wctx, mctx, f, args[0]):
fileconflicts.add(f)
- allconflicts = fileconflicts
+ allconflicts = fileconflicts | pathconflicts
ignoredconflicts = set([c for c in allconflicts
if repo.dirstate._ignore(c)])
unknownconflicts = allconflicts - ignoredconflicts
@@ -742,8 +747,9 @@
repo.ui.warn(_("%s: replacing untracked file\n") % f)
for f, (m, args, msg) in actions.iteritems():
- backup = f in fileconflicts
if m == 'c':
+ backup = (f in fileconflicts or f in pathconflicts or
+ any(p in pathconflicts for p in util.finddirs(f)))
flags, = args
actions[f] = ('g', (flags, backup), msg)
To: mbthomas, #hg-reviewers
Cc: mercurial-devel
More information about the Mercurial-devel
mailing list