commands: don't infer repo for commands like update (issue2748)
authorSiddharth Agarwal <sid0@fb.com>
Tue, 16 Oct 2012 11:43:15 -0700
changeset 17773 434e5bd615fc
parent 17772 823a7d79ef82
child 17774 0496d4f73cf4
commands: don't infer repo for commands like update (issue2748) Maintain a whitelist of commands to infer the repo for instead. The whitelist contains those commands that take file(s) in the working dir as arguments.
hgext/children.py
hgext/churn.py
hgext/extdiff.py
hgext/graphlog.py
hgext/hgk.py
hgext/keyword.py
hgext/largefiles/lfcommands.py
hgext/mq.py
hgext/record.py
mercurial/commands.py
mercurial/dispatch.py
tests/test-update-branches.t
--- a/hgext/children.py	Mon Oct 15 09:43:34 2012 -0700
+++ b/hgext/children.py	Tue Oct 16 11:43:15 2012 -0700
@@ -14,7 +14,7 @@
 "children(REV)"` instead.
 '''
 
-from mercurial import cmdutil
+from mercurial import cmdutil, commands
 from mercurial.commands import templateopts
 from mercurial.i18n import _
 
@@ -48,3 +48,5 @@
          ] + templateopts,
          _('hg children [-r REV] [FILE]')),
 }
+
+commands.inferrepo += " children"
--- a/hgext/churn.py	Mon Oct 15 09:43:34 2012 -0700
+++ b/hgext/churn.py	Tue Oct 16 11:43:15 2012 -0700
@@ -197,3 +197,5 @@
           ] + commands.walkopts,
          _("hg churn [-d DATE] [-r REV] [--aliases FILE] [FILE]")),
 }
+
+commands.inferrepo += " churn"
--- a/hgext/extdiff.py	Mon Oct 15 09:43:34 2012 -0700
+++ b/hgext/extdiff.py	Tue Oct 16 11:43:15 2012 -0700
@@ -329,3 +329,5 @@
         cmdtable[cmd] = (save(cmd, path, diffopts),
                          cmdtable['extdiff'][1][1:],
                          _('hg %s [OPTION]... [FILE]...') % cmd)
+
+commands.inferrepo += " extdiff"
--- a/hgext/graphlog.py	Mon Oct 15 09:43:34 2012 -0700
+++ b/hgext/graphlog.py	Tue Oct 16 11:43:15 2012 -0700
@@ -52,3 +52,5 @@
     directory.
     """
     return cmdutil.graphlog(ui, repo, *pats, **opts)
+
+commands.inferrepo += " glog"
--- a/hgext/hgk.py	Mon Oct 15 09:43:34 2012 -0700
+++ b/hgext/hgk.py	Tue Oct 16 11:43:15 2012 -0700
@@ -350,3 +350,5 @@
           ('n', 'max-count', 0, _('max-count'))],
          _('hg debug-rev-list [OPTION]... REV...')),
 }
+
+commands.inferrepo += " debug-diff-tree debug-cat-file"
--- a/hgext/keyword.py	Mon Oct 15 09:43:34 2012 -0700
+++ b/hgext/keyword.py	Tue Oct 16 11:43:15 2012 -0700
@@ -728,3 +728,5 @@
             pass
 
     repo.__class__ = kwrepo
+
+commands.inferrepo += " kwexpand kwfiles kwshrink"
--- a/hgext/largefiles/lfcommands.py	Mon Oct 15 09:43:34 2012 -0700
+++ b/hgext/largefiles/lfcommands.py	Tue Oct 16 11:43:15 2012 -0700
@@ -12,7 +12,7 @@
 import shutil
 
 from mercurial import util, match as match_, hg, node, context, error, \
-    cmdutil, scmutil
+    cmdutil, scmutil, commands
 from mercurial.i18n import _
 from mercurial.lock import release
 
@@ -549,3 +549,5 @@
                   ],
                   _('hg lfconvert SOURCE DEST [FILE ...]')),
     }
+
+commands.inferrepo += " lfconvert"
--- a/hgext/mq.py	Mon Oct 15 09:43:34 2012 -0700
+++ b/hgext/mq.py	Tue Oct 16 11:43:15 2012 -0700
@@ -3602,3 +3602,5 @@
               'qseries.guarded': 'black bold',
               'qseries.missing': 'red bold',
               'qseries.unapplied': 'black bold'}
+
+commands.inferrepo += " qnew qrefresh qdiff qcommit"
--- a/hgext/record.py	Mon Oct 15 09:43:34 2012 -0700
+++ b/hgext/record.py	Tue Oct 16 11:43:15 2012 -0700
@@ -667,3 +667,5 @@
 def _wrapcmd(cmd, table, wrapfn, msg):
     entry = extensions.wrapcommand(table, cmd, wrapfn)
     entry[1].append(('i', 'interactive', None, msg))
+
+commands.inferrepo += " record qrecord"
--- a/mercurial/commands.py	Mon Oct 15 09:43:34 2012 -0700
+++ b/mercurial/commands.py	Tue Oct 16 11:43:15 2012 -0700
@@ -5911,3 +5911,5 @@
           " debugknown debuggetbundle debugbundle")
 optionalrepo = ("identify paths serve showconfig debugancestor debugdag"
                 " debugdata debugindex debugindexdot debugrevlog")
+inferrepo = ("add addremove annotate cat commit diff grep forget log parents"
+             " remove resolve status debugwalk")
--- a/mercurial/dispatch.py	Mon Oct 15 09:43:34 2012 -0700
+++ b/mercurial/dispatch.py	Tue Oct 16 11:43:15 2012 -0700
@@ -715,7 +715,8 @@
                 raise
             except error.RepoError:
                 if cmd not in commands.optionalrepo.split():
-                    if args and not path: # try to infer -R from command args
+                    if (cmd in commands.inferrepo.split() and
+                        args and not path): # try to infer -R from command args
                         repos = map(cmdutil.findrepo, args)
                         guess = repos[0]
                         if guess and repos.count(guess) == len(repos):
--- a/tests/test-update-branches.t	Mon Oct 15 09:43:34 2012 -0700
+++ b/tests/test-update-branches.t	Tue Oct 16 11:43:15 2012 -0700
@@ -12,6 +12,8 @@
 # |/
 # o  0:b608b9236435
 
+  $ mkdir b1
+  $ cd b1
   $ hg init
   $ echo foo > foo
   $ echo zero > a
@@ -47,6 +49,14 @@
   o  0:60829823a42a
   
 
+Make sure update doesn't assume b1 is a repository if invoked from outside:
+
+  $ cd ..
+  $ hg update b1
+  abort: no repository found in '$TESTTMP' (.hg not found)!
+  [255]
+  $ cd b1
+
 Test helper functions:
 
   $ revtest () {