commands.resolve: don't allow users to mark or unmark driver-resolved files
authorSiddharth Agarwal <sid0@fb.com>
Thu, 15 Oct 2015 01:15:22 -0700
changeset 26784 c0aab5961876
parent 26783 50213e4d25bf
child 26785 e9a0d5f5c225
commands.resolve: don't allow users to mark or unmark driver-resolved files Users will often be in the habit of running 'hg resolve --mark --all' after resolving merge conflicts in source files. We need to make sure this doesn't cause driver-resolved files to be marked. 'hg resolve --all' will resolve driver-resolved files, though. The weird conditional structure is to accommodate an upcoming patch.
mercurial/commands.py
tests/test-resolve.t
--- a/mercurial/commands.py	Thu Oct 15 01:11:50 2015 -0700
+++ b/mercurial/commands.py	Thu Oct 15 01:15:22 2015 -0700
@@ -5617,6 +5617,19 @@
 
             didwork = True
 
+            # don't let driver-resolved files be marked
+            if ms[f] == "d":
+                exact = m.exact(f)
+                if mark:
+                    if exact:
+                        ui.warn(_('not marking %s as it is driver-resolved\n')
+                                % f)
+                elif unmark:
+                    if exact:
+                        ui.warn(_('not unmarking %s as it is driver-resolved\n')
+                                % f)
+                continue
+
             if mark:
                 ms.mark(f, "r")
             elif unmark:
--- a/tests/test-resolve.t	Thu Oct 15 01:11:50 2015 -0700
+++ b/tests/test-resolve.t	Thu Oct 15 01:15:22 2015 -0700
@@ -53,6 +53,58 @@
   arguments do not match paths that need resolving
   $ hg resolve -l does-not-exist
 
+don't allow marking or unmarking driver-resolved files
+
+  $ cat > $TESTTMP/markdriver.py << EOF
+  > '''mark and unmark files as driver-resolved'''
+  > from mercurial import cmdutil, merge, scmutil
+  > cmdtable = {}
+  > command = cmdutil.command(cmdtable)
+  > @command('markdriver',
+  >   [('u', 'unmark', None, '')],
+  >   'FILE...')
+  > def markdriver(ui, repo, *pats, **opts):
+  >     wlock = repo.wlock()
+  >     try:
+  >         ms = merge.mergestate(repo)
+  >         m = scmutil.match(repo[None], pats, opts)
+  >         for f in ms:
+  >             if not m(f):
+  >                 continue
+  >             if not opts['unmark']:
+  >                 ms.mark(f, 'd')
+  >             else:
+  >                 ms.mark(f, 'u')
+  >         ms.commit()
+  >     finally:
+  >         wlock.release()
+  > EOF
+  $ hg --config extensions.markdriver=$TESTTMP/markdriver.py markdriver file1
+  $ hg resolve --list
+  D file1
+  U file2
+  $ hg resolve --mark file1
+  not marking file1 as it is driver-resolved
+this should not print out file1
+  $ hg resolve --mark --all
+  (no more unresolved files -- run "hg resolve --all" to conclude)
+  $ hg resolve --mark 'glob:file*'
+  (no more unresolved files -- run "hg resolve --all" to conclude)
+  $ hg resolve --list
+  D file1
+  R file2
+  $ hg resolve --unmark file1
+  not unmarking file1 as it is driver-resolved
+  (no more unresolved files -- run "hg resolve --all" to conclude)
+  $ hg resolve --unmark --all
+  $ hg resolve --list
+  D file1
+  U file2
+  $ hg --config extensions.markdriver=$TESTTMP/markdriver.py markdriver --unmark file1
+  $ hg resolve --list
+  U file1
+  U file2
+
 resolve the failure
 
   $ echo resolved > file1