changeset 3502:8dc14d630b29

add branch and branches commands
author Matt Mackall <mpm@selenic.com>
date Tue, 24 Oct 2006 16:49:36 -0500
parents 89820e9b94f2
children b28d3e0f9a8c
files mercurial/commands.py tests/test-debugcomplete.out tests/test-globalopts.out tests/test-help.out tests/test-newbranch tests/test-newbranch.out
diffstat 6 files changed, 56 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/commands.py	Tue Oct 24 17:49:48 2006 -0300
+++ b/mercurial/commands.py	Tue Oct 24 16:49:36 2006 -0500
@@ -774,6 +774,35 @@
             ui.status(_('(use "backout --merge" '
                         'if you want to auto-merge)\n'))
 
+def branch(ui, repo, label=None):
+    """set or show the current branch name
+
+    With <name>, set the current branch name. Otherwise, show the
+    current branch name.
+    """
+
+    if label is not None:
+        repo.opener("branch", "w").write(label)
+    else:
+        b = repo.workingctx().branch()
+        if b:
+            ui.write("%s\n" % b)
+
+def branches(ui, repo):
+    """list repository named branches
+
+    List the repository's named branches.
+    """
+    b = repo.branchtags()
+    l = [(-repo.changelog.rev(n), n, t) for t,n in b.items()]
+    l.sort()
+    for r, n, t in l:
+        hexfunc = ui.debugflag and hex or short
+        if ui.quiet:
+            ui.write("%s\n" % t)
+        else:
+            ui.write("%-30s %s:%s\n" % (t, -r, hexfunc(n)))
+
 def bundle(ui, repo, fname, dest=None, **opts):
     """create a changegroup file
 
@@ -2850,6 +2879,8 @@
           ('u', 'user', '', _('record user as committer')),
          ] + walkopts,
          _('hg backout [OPTION]... REV')),
+    "branch": (branch, [], _('hg branch [NAME]')),
+    "branches": (branches, [], _('hg branches')),
     "bundle":
         (bundle,
          [('f', 'force', None,
--- a/tests/test-debugcomplete.out	Tue Oct 24 17:49:48 2006 -0300
+++ b/tests/test-debugcomplete.out	Tue Oct 24 16:49:36 2006 -0500
@@ -4,6 +4,8 @@
 annotate
 archive
 backout
+branch
+branches
 bundle
 cat
 clone
--- a/tests/test-globalopts.out	Tue Oct 24 17:49:48 2006 -0300
+++ b/tests/test-globalopts.out	Tue Oct 24 16:49:36 2006 -0500
@@ -120,6 +120,8 @@
  annotate     show changeset information per file line
  archive      create unversioned archive of a repository revision
  backout      reverse effect of earlier changeset
+ branch       set or show the current branch name
+ branches     list repository named branches
  bundle       create a changegroup file
  cat          output the latest or given revisions of files
  clone        make a copy of an existing repository
@@ -168,6 +170,8 @@
  annotate     show changeset information per file line
  archive      create unversioned archive of a repository revision
  backout      reverse effect of earlier changeset
+ branch       set or show the current branch name
+ branches     list repository named branches
  bundle       create a changegroup file
  cat          output the latest or given revisions of files
  clone        make a copy of an existing repository
--- a/tests/test-help.out	Tue Oct 24 17:49:48 2006 -0300
+++ b/tests/test-help.out	Tue Oct 24 16:49:36 2006 -0500
@@ -43,6 +43,8 @@
  annotate     show changeset information per file line
  archive      create unversioned archive of a repository revision
  backout      reverse effect of earlier changeset
+ branch       set or show the current branch name
+ branches     list repository named branches
  bundle       create a changegroup file
  cat          output the latest or given revisions of files
  clone        make a copy of an existing repository
@@ -87,6 +89,8 @@
  annotate     show changeset information per file line
  archive      create unversioned archive of a repository revision
  backout      reverse effect of earlier changeset
+ branch       set or show the current branch name
+ branches     list repository named branches
  bundle       create a changegroup file
  cat          output the latest or given revisions of files
  clone        make a copy of an existing repository
--- a/tests/test-newbranch	Tue Oct 24 17:49:48 2006 -0300
+++ b/tests/test-newbranch	Tue Oct 24 16:49:36 2006 -0500
@@ -2,27 +2,32 @@
 
 hg init t
 cd t
+hg branches
 
 echo foo > a
 hg add a
 hg ci -m "initial" -d "0 0"
-echo foo > .hg/branch
+hg branch foo
+hg branch
 hg ci -m "add branch name" -d "0 0"
-echo bar > .hg/branch
+hg branch bar
 hg ci -m "change branch name" -d "0 0"
-rm .hg/branch
+hg branch ""
 hg ci -m "clear branch name" -d "0 0"
 
 hg co foo
-cat .hg/branch
+hg branch
 echo bleah > a
 hg ci -m "modify a branch" -d "0 0"
 
 hg merge
-cat .hg/branch
+hg branch
 HG_MERGE=true hg ci -m "merge" -d "0 0"
 hg log
 
+hg branches
+hg branches -q
+
 echo % test for invalid branch cache
 hg rollback
 hg tip
--- a/tests/test-newbranch.out	Tue Oct 24 17:49:48 2006 -0300
+++ b/tests/test-newbranch.out	Tue Oct 24 16:49:36 2006 -0500
@@ -1,3 +1,4 @@
+foo
 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
 foo
 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
@@ -41,6 +42,10 @@
 date:        Thu Jan 01 00:00:00 1970 +0000
 summary:     initial
 
+foo                            5:dc140083783b
+bar                            2:ed2bbf4e0102
+foo
+bar
 % test for invalid branch cache
 rolling back last transaction
 changeset:   4:98d14f698afe