[PATCH 4 of 5 resolve-ux] resolve: print warning when no work performed (issue4208)

Gregory Szorc gregory.szorc at gmail.com
Sat May 3 16:27:40 CDT 2014


# HG changeset patch
# User Gregory Szorc <gregory.szorc at gmail.com>
# Date 1397872586 25200
#      Fri Apr 18 18:56:26 2014 -0700
# Branch stable
# Node ID e6e8c42fe1c8d6bb71779466ae633771e046ac69
# Parent  df175a8704f7ab51eed349d5e166b40a1b414227
resolve: print warning when no work performed (issue4208)

Previously, if the paths specified as arguments to |hg resolve| were
invalid, they were silently ignored and a no-op would ensue.

This patch fixes that in some scenarios.

If none of the paths specified to |hg resolve| match a path that is in
mergestate, a warning will be emitted.

Ideally, a warning would be emitted for every path/pattern specified
that doesn't match anything. To achieve this would require significant
refactoring of the matching subsystem. That work is beyond the scope of
this patch series. Something is better than nothing and this patch
gets us something.

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -4930,20 +4930,23 @@ def resolve(ui, repo, *pats, **opts):
 
     if not ms.active():
         raise util.Abort(_('no merge in progress; '
                            'resolve command not applicable'))
 
     m = scmutil.match(repo[None], pats, opts)
     ret = 0
 
+    didwork = False
     for f in ms:
         if not m(f):
             continue
 
+        didwork = True
+
         if show:
             if nostatus:
                 ui.write("%s\n" % f)
             else:
                 ui.write("%s %s\n" % (ms[f].upper(), f),
                          label='resolve.' +
                          {'u': 'unresolved', 'r': 'resolved'}[ms[f]])
         elif mark:
@@ -4966,16 +4969,20 @@ def resolve(ui, repo, *pats, **opts):
             finally:
                 ui.setconfig('ui', 'forcemerge', '', 'resolve')
                 ms.commit()
 
             # replace filemerge's .orig file with our resolve file
             util.rename(a + ".resolve", a + ".orig")
 
     ms.commit()
+
+    if not didwork and pats:
+        ui.warn(_("no work performed. specified path(s) invalid?\n"))
+
     return ret
 
 @command('revert',
     [('a', 'all', None, _('revert all changes when no arguments given')),
     ('d', 'date', '', _('tipmost revision matching date'), _('DATE')),
     ('r', 'rev', '', _('revert to the specified revision'), _('REV')),
     ('C', 'no-backup', None, _('do not save backup copies of files')),
     ] + walkopts + dryrunopts,
diff --git a/tests/test-resolve.t b/tests/test-resolve.t
--- a/tests/test-resolve.t
+++ b/tests/test-resolve.t
@@ -26,16 +26,20 @@ failing merge
   use 'hg resolve' to retry unresolved file merges or 'hg update -C .' to abandon
   [1]
 
 resolve -l should contain an unresolved entry
 
   $ hg resolve -l
   U file
 
+resolving an unknown path emits a warning
+  $ hg resolve -m does-not-exist
+  no work performed. specified path(s) invalid?
+
 resolve the failure
 
   $ echo resolved > file
   $ hg resolve -m file
   $ hg commit -m 'resolved'
 
 resolve -l should error since no merge in progress
 


More information about the Mercurial-devel mailing list