Patchwork D3950: shelve: pick the most recent shelve if none specified for --patch/--stat

login
register
mail settings
Submitter phabricator
Date July 16, 2018, 10:10 p.m.
Message ID <9a890b74f8632003c7e9b62a86e2b7da@localhost.localdomain>
Download mbox | patch
Permalink /patch/32883/
State Not Applicable
Headers show

Comments

phabricator - July 16, 2018, 10:10 p.m.
This revision was automatically updated to reflect the committed changes.
Closed by commit rHG905b66681004: shelve: pick the most recent shelve if none specified for --patch/--stat (authored by hooper, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D3950?vs=9603&id=9605

REVISION DETAIL
  https://phab.mercurial-scm.org/D3950

AFFECTED FILES
  hgext/shelve.py
  tests/test-shelve.t

CHANGE DETAILS




To: hooper, #hg-reviewers, pulkit
Cc: mercurial-devel

Patch

diff --git a/tests/test-shelve.t b/tests/test-shelve.t
--- a/tests/test-shelve.t
+++ b/tests/test-shelve.t
@@ -1057,8 +1057,33 @@ 
   $ hg shelve --patch default nonexistentshelf
   abort: cannot find shelf nonexistentshelf
   [255]
+
+when the user asks for a patch, we assume they want the most recent shelve if
+they don't provide a shelve name
+
   $ hg shelve --patch
-  abort: --patch expects at least one shelf
+  default-01      (*)* changes to: create conflict (glob)
+  
+  diff --git a/shelf-patch-b b/shelf-patch-b
+  new file mode 100644
+  --- /dev/null
+  +++ b/shelf-patch-b
+  @@ -0,0 +1,1 @@
+  +patch b
+
+  $ cd ..
+
+you shouldn't be able to ask for the patch/stats of the most recent shelve if
+there are no shelves
+
+  $ hg init noshelves
+  $ cd noshelves
+
+  $ hg shelve --patch
+  abort: there are no shelves to show
+  [255]
+  $ hg shelve --stat
+  abort: there are no shelves to show
   [255]
 
   $ cd ..
diff --git a/hgext/shelve.py b/hgext/shelve.py
--- a/hgext/shelve.py
+++ b/hgext/shelve.py
@@ -594,10 +594,15 @@ 
                 for chunk, label in patch.diffstatui(difflines, width=width):
                     ui.write(chunk, label=label)
 
-def patchcmds(ui, repo, pats, opts, subcommand):
+def patchcmds(ui, repo, pats, opts):
     """subcommand that displays shelves"""
     if len(pats) == 0:
-        raise error.Abort(_("--%s expects at least one shelf") % subcommand)
+        shelves = listshelves(repo)
+        if not shelves:
+            raise error.Abort(_("there are no shelves to show"))
+        mtime, name = shelves[0]
+        sname = util.split(name)[1]
+        pats = [sname]
 
     for shelfname in pats:
         if not shelvedfile(repo, shelfname, patchextension).exists():
@@ -1082,10 +1087,8 @@ 
         return deletecmd(ui, repo, pats)
     elif checkopt('list'):
         return listcmd(ui, repo, pats, opts)
-    elif checkopt('patch'):
-        return patchcmds(ui, repo, pats, opts, subcommand='patch')
-    elif checkopt('stat'):
-        return patchcmds(ui, repo, pats, opts, subcommand='stat')
+    elif checkopt('patch') or checkopt('stat'):
+        return patchcmds(ui, repo, pats, opts)
     else:
         return createcmd(ui, repo, pats, opts)