Patchwork [v2] resolve: when pats do not match, hint about path:

login
register
mail settings
Submitter timeless@mozdev.org
Date March 2, 2016, 11:24 p.m.
Message ID <ca46c80b3a467484a951.1456961040@waste.org>
Download mbox | patch
Permalink /patch/13575/
State Accepted
Delegated to: Yuya Nishihara
Headers show

Comments

timeless@mozdev.org - March 2, 2016, 11:24 p.m.
# HG changeset patch
# User timeless <timeless@mozdev.org>
# Date 1450931494 0
#      Thu Dec 24 04:31:34 2015 +0000
# Node ID ca46c80b3a467484a951ee6c0bf9ae3063e91d8a
# Parent  c7f89ad87baef87f00c507545dfd4cc824bc3131
resolve: when pats do not match, hint about path:

Suggest a command that would probably work.
Yuya Nishihara - March 5, 2016, 8:44 a.m.
On Wed, 02 Mar 2016 17:24:00 -0600, timeless wrote:
> # HG changeset patch
> # User timeless <timeless@mozdev.org>
> # Date 1450931494 0
> #      Thu Dec 24 04:31:34 2015 +0000
> # Node ID ca46c80b3a467484a951ee6c0bf9ae3063e91d8a
> # Parent  c7f89ad87baef87f00c507545dfd4cc824bc3131
> resolve: when pats do not match, hint about path:
> 
> Suggest a command that would probably work.
> 
> diff --git a/mercurial/commands.py b/mercurial/commands.py
> --- a/mercurial/commands.py
> +++ b/mercurial/commands.py
> @@ -5939,8 +5939,9 @@
>      Returns 0 on success, 1 if any files fail a resolve attempt.
>      """
>  
> +    flaglist = 'all mark unmark list no_status'.split()
>      all, mark, unmark, show, nostatus = \
> -        [opts.get(o) for o in 'all mark unmark list no_status'.split()]
> +        [opts.get(o) for o in flaglist]
>  
>      if (show and (mark or unmark)) or (mark and unmark):
>          raise error.Abort(_("too many options specified"))
> @@ -6069,7 +6070,22 @@
>          ms.recordactions()
>  
>          if not didwork and pats:
> +            hint = None
> +            if not any([p for p in pats if p.find(':') >= 0]):
> +                pats = ['path:%s' % p for p in pats]
> +                m = scmutil.match(wctx, pats, opts)
> +                for f in ms:
> +                    if not m(f):
> +                        continue
> +                    flags = ''.join(['-%s ' % o[0] for o in flaglist
> +                                                   if opts.get(o)])
> +                    hint = _("(try: hg resolve %s%s)\n") % (
> +                             flags,
> +                             ' '.join(pats))
> +                    break
>              ui.warn(_("arguments do not match paths that need resolving\n"))
> +            if hint:
> +                ui.warn(hint)

I don't get the point. "hg resolve" does nothing special on paths handling.
Is it common to specify a repository path in place of a relative path?
timeless - March 7, 2016, 5:06 p.m.
> I don't get the point. "hg resolve" does nothing special on paths handling.
> Is it common to specify a repository path in place of a relative path?

It's common to do:
`hg resolve --list`

Having manually fixed things, it's reasonable to try:

`hg resolve an-entry-from-resolve-list`

But, if your current directory is not the repository root, then it won't work.
Yuya Nishihara - March 8, 2016, 3:31 p.m.
On Mon, 7 Mar 2016 12:06:21 -0500, timeless wrote:
> > I don't get the point. "hg resolve" does nothing special on paths handling.
> > Is it common to specify a repository path in place of a relative path?
> 
> It's common to do:
> `hg resolve --list`
> 
> Having manually fixed things, it's reasonable to try:
> 
> `hg resolve an-entry-from-resolve-list`
> 
> But, if your current directory is not the repository root, then it won't work.

Doh, so "hg resolve" has the same issue as "hg status". That's unfortunate.

I'm not excited about this patch, but your opinion seems legit. I'll queue this
if there's no -1.
Pierre-Yves David - March 9, 2016, 5:23 p.m.
On 03/08/2016 03:31 PM, Yuya Nishihara wrote:
> On Mon, 7 Mar 2016 12:06:21 -0500, timeless wrote:
>>> I don't get the point. "hg resolve" does nothing special on paths handling.
>>> Is it common to specify a repository path in place of a relative path?
>>
>> It's common to do:
>> `hg resolve --list`
>>
>> Having manually fixed things, it's reasonable to try:
>>
>> `hg resolve an-entry-from-resolve-list`
>>
>> But, if your current directory is not the repository root, then it won't work.
>
> Doh, so "hg resolve" has the same issue as "hg status". That's unfortunate.
>
> I'm not excited about this patch, but your opinion seems legit. I'll queue this
> if there's no -1.

I'm sad about the situation and not exited about the fix. However, 
timeless hint still seems an improvement to the current situation. I 
think we should probably take it. As yuya seems to agree I've pushed it 
to the clowncopter.

Cheers.

Patch

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -5939,8 +5939,9 @@ 
     Returns 0 on success, 1 if any files fail a resolve attempt.
     """
 
+    flaglist = 'all mark unmark list no_status'.split()
     all, mark, unmark, show, nostatus = \
-        [opts.get(o) for o in 'all mark unmark list no_status'.split()]
+        [opts.get(o) for o in flaglist]
 
     if (show and (mark or unmark)) or (mark and unmark):
         raise error.Abort(_("too many options specified"))
@@ -6069,7 +6070,22 @@ 
         ms.recordactions()
 
         if not didwork and pats:
+            hint = None
+            if not any([p for p in pats if p.find(':') >= 0]):
+                pats = ['path:%s' % p for p in pats]
+                m = scmutil.match(wctx, pats, opts)
+                for f in ms:
+                    if not m(f):
+                        continue
+                    flags = ''.join(['-%s ' % o[0] for o in flaglist
+                                                   if opts.get(o)])
+                    hint = _("(try: hg resolve %s%s)\n") % (
+                             flags,
+                             ' '.join(pats))
+                    break
             ui.warn(_("arguments do not match paths that need resolving\n"))
+            if hint:
+                ui.warn(hint)
         elif ms.mergedriver and ms.mdstate() != 's':
             # run conclude step when either a driver-resolved file is requested
             # or there are no driver-resolved files
diff --git a/tests/test-resolve.t b/tests/test-resolve.t
--- a/tests/test-resolve.t
+++ b/tests/test-resolve.t
@@ -53,6 +53,34 @@ 
   arguments do not match paths that need resolving
   $ hg resolve -l does-not-exist
 
+tell users how they could have used resolve
+
+  $ mkdir nested
+  $ cd nested
+  $ hg resolve -m file1
+  arguments do not match paths that need resolving
+  (try: hg resolve -m path:file1)
+  $ hg resolve -m file1 filez
+  arguments do not match paths that need resolving
+  (try: hg resolve -m path:file1 path:filez)
+  $ hg resolve -m path:file1 path:filez
+  $ hg resolve -l
+  R file1
+  U file2
+  $ hg resolve -m filez file2
+  arguments do not match paths that need resolving
+  (try: hg resolve -m path:filez path:file2)
+  $ hg resolve -m path:filez path:file2
+  (no more unresolved files)
+  $ hg resolve -l
+  R file1
+  R file2
+
+cleanup
+  $ hg resolve -u
+  $ cd ..
+  $ rmdir nested
+
 don't allow marking or unmarking driver-resolved files
 
   $ cat > $TESTTMP/markdriver.py << EOF