changeset 9:67c330feb23a

commands: add tmerge and tcommit
author jcoomes
date Sun, 11 Dec 2011 11:04:19 -0800
parents c2c8b5e8a941
children c571b4c35de6
files tests/test-trees-local.t trees.py
diffstat 2 files changed, 100 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/tests/test-trees-local.t	Mon Dec 05 08:14:27 2011 -0800
+++ b/tests/test-trees-local.t	Sun Dec 11 11:04:19 2011 -0800
@@ -697,20 +697,60 @@
   adding file changes
   added 1 changesets with 1 changes to 1 files (+1 heads)
   (run 'hg heads' to see heads, 'hg merge' to merge)
-  $ for r in r2
-  > do
-  >     for sr in s2 s2/s2.2 s2/s2.2/s2.2.1
-  >     do
-  >         hg -R $r/$sr merge
-  >         hg -R $r/$sr commit -m 'merge with r1'
-  >     done
-  > done
+  $ hg -R r2 tmerge
+  [$TESTTMP/r2]:
+  nothing to merge
+  
+  [$TESTTMP/r2/s1]:
+  nothing to merge
+  
+  [$TESTTMP/r2/s1/s1.1 with spaces]:
+  nothing to merge
+  
+  [$TESTTMP/r2/s1/s1.2]:
+  nothing to merge
+  
+  [$TESTTMP/r2/s1/s1.3 with spaces]:
+  nothing to merge
+  
+  [$TESTTMP/r2/s2]:
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  (branch merge, don't forget to commit)
+  
+  [$TESTTMP/r2/s2/s2.1]:
+  nothing to merge
+  
+  [$TESTTMP/r2/s2/s2.2]:
   1 files updated, 0 files merged, 0 files removed, 0 files unresolved
   (branch merge, don't forget to commit)
+  
+  [$TESTTMP/r2/s2/s2.2/s2.2.1]:
   1 files updated, 0 files merged, 0 files removed, 0 files unresolved
   (branch merge, don't forget to commit)
-  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
-  (branch merge, don't forget to commit)
+  $ hg -R r2 tcommit -d '0 0' -m 'merge with r1'
+  [$TESTTMP/r2]:
+  nothing to commit
+  
+  [$TESTTMP/r2/s1]:
+  nothing to commit
+  
+  [$TESTTMP/r2/s1/s1.1 with spaces]:
+  nothing to commit
+  
+  [$TESTTMP/r2/s1/s1.2]:
+  nothing to commit
+  
+  [$TESTTMP/r2/s1/s1.3 with spaces]:
+  nothing to commit
+  
+  [$TESTTMP/r2/s2]:
+  
+  [$TESTTMP/r2/s2/s2.1]:
+  nothing to commit
+  
+  [$TESTTMP/r2/s2/s2.2]:
+  
+  [$TESTTMP/r2/s2/s2.2/s2.2.1]:
   $ hg -R r2 tpush
   [$TESTTMP/r2]:
   pushing to $TESTTMP/r1
@@ -937,7 +977,7 @@
   $TESTTMP/r135/s1
   $TESTTMP/r135/s3
   $TESTTMP/r135/s5
-  $ hg tcomm -R r135 pwd
+  $ hg tcommand -R r135 pwd
   [$TESTTMP/r135]:
   $TESTTMP/r135
   
@@ -950,7 +990,7 @@
   [$TESTTMP/r135/s5]:
   $TESTTMP/r135/s5
   $ hg tstat -R r135 -q
-  $ hg tcomm -R r135 -q -- sh -c 'echo foo > xyz'
+  $ hg tcommand -R r135 -q -- sh -c 'echo foo > xyz'
   $ hg tstat -R r135
   [$TESTTMP/r135]:
   ? xyz
@@ -963,7 +1003,7 @@
   
   [$TESTTMP/r135/s5]:
   ? xyz
-  $ hg tcomm -R r135 -q -- hg add xyz
+  $ hg tcommand -R r135 -q -- hg add xyz
   $ hg tstat -R r135
   [$TESTTMP/r135]:
   A xyz
@@ -1004,7 +1044,7 @@
   +++ b/xyz
   @@ -0,0 +1,1 @@
   +foo
-  $ hg tcomm -R r135 -q -- hg commit -m 'add xyz'
+  $ hg tcommit -R r135 -d '0 0' -q -m 'add xyz'
   $ hg tstat -R r135 -q
   $ hg ttag  -R r135 -d '0 0' xyz
   [$TESTTMP/r135]:
--- a/trees.py	Mon Dec 05 08:14:27 2011 -0800
+++ b/trees.py	Sun Dec 11 11:04:19 2011 -0800
@@ -214,7 +214,12 @@
     tupdate)."""
 
     ui.status('[%s]:\n' % repo.root)
-    trc = cmd(ui, repo, *args, **opts)
+    # XXX - should be done just once.
+    cmdopts = dict(opts)
+    for o in subtreesopts:
+        if o[1] in cmdopts:
+            del cmdopts[o[1]]
+    trc = cmd(ui, repo, *args, **cmdopts)
     rc = trc != None and trc or 0
     for subtree in _subtreelist(ui, repo, opts):
         ui.status('\n')
@@ -384,6 +389,23 @@
     l = __builtin__.list((cmd,) + args)
     return _command(ui, repo, l, opts.get('stop'), opts)
 
+def commit(ui, repo, *pats, **opts):
+    """commit all files"""
+    _checklocal(repo)
+    if pats:
+        util.Abort('must commit all files')
+
+    hgcommit = _origcmd('commit')
+    def condcommit(ui, repo, *pats, **opts):
+        '''commit conditionally - only if there is something to commit'''
+        for l in repo.status()[:3]: # modified, added, removed
+            if l:
+                return hgcommit(ui, repo, *pats, **opts)
+        ui.status('nothing to commit\n')
+        return 0
+
+    return _docmd1(condcommit, ui, repo, *pats, **opts)
+
 def config(ui, repo, *subtrees, **opts):
     """list or change the subtrees configuration
 
@@ -499,6 +521,19 @@
     _checklocal(repo)
     return _docmd1(_origcmd('log'), ui, repo, *args, **opts)
 
+def merge(ui, repo, node=None, **opts):
+    '''merge working directory with another revision'''
+    _checklocal(repo)
+
+    hgmerge = _origcmd('merge')
+    def condmerge(ui, repo, node=None, **opts):
+        if len(repo.heads()) > 1:
+            return hgmerge(ui, repo, node, **opts)
+        ui.status('nothing to merge\n')
+        return 0
+
+    return _docmd1(condmerge, ui, repo, node, **opts)
+
 def outgoing(ui, repo, remote=None, **opts):
     '''show changesets not found in the destination'''
     _checklocal(repo)
@@ -662,9 +697,12 @@
 def _newcte(origcmd, newfunc, extraopts = [], synopsis = None):
     '''generate a cmdtable entry based on that for origcmd'''
     cte = cmdutil.findcmd(origcmd, commands.table)[1]
-    if (len(cte) > 2):
-        return (newfunc, cte[1] + extraopts, synopsis or cte[2])
-    return (newfunc, cte[1] + extraopts, synopsis)
+    # Filter out --exclude and --include, since those do not work across
+    # repositories (mercurial converts them to abs paths).
+    opts = [o for o in cte[1] if o[1] not in ('exclude', 'include')]
+    if len(cte) > 2:
+        return (newfunc, opts + extraopts, synopsis or cte[2])
+    return (newfunc, opts + extraopts, synopsis)
 
 def extsetup(ui = None):
     # The cmdtable is initialized here to pick up options added by other
@@ -687,14 +725,16 @@
     cmdtable = {
         '^tclone': _newcte('clone', clone, cloneopts,
                            _('[OPTION]... SOURCE [DEST [SUBTREE]...]')),
-        'tcommand': (command, commandopts, _('command [arg] ...')),
+        'tcommand|tcmd': (command, commandopts, _('command [arg] ...')),
+        'tcommit|tci': _newcte('commit', commit, subtreesopts),
         'tconfig': (config, configopts, _('[OPTION]... [SUBTREE]...')),
         'tdiff': _newcte('diff', diff, subtreesopts),
         'theads': _newcte('heads', heads, subtreesopts),
         'tincoming': _newcte('incoming', incoming, subtreesopts),
         'toutgoing': _newcte('outgoing', outgoing, subtreesopts),
         'tlist': (list, listopts, _('[OPTION]...')),
-        '^tlog': _newcte('log', log, subtreesopts),
+        '^tlog|thistory': _newcte('log', log, subtreesopts),
+        'tmerge': _newcte('merge', merge, subtreesopts),
         'tparents': _newcte('parents', parents, subtreesopts),
         'tpaths': _newcte('paths', paths, subtreesopts),
         '^tpull': _newcte('pull', pull, subtreesopts),