diff mercurial/commands.py @ 7006:92d44ec32430

branch: added more support for named branches hg branch now has a -C (--clean) option, to reset the current (dirstate) branch to the branch of the last commit (first parent).
author Sune Foldager <cryo@cyanite.org>
date Mon, 08 Sep 2008 12:55:27 +0200
parents 2365c6d4c330
children 78341ea65d16
line wrap: on
line diff
--- a/mercurial/commands.py	Mon Sep 08 11:32:53 2008 +0200
+++ b/mercurial/commands.py	Mon Sep 08 12:55:27 2008 +0200
@@ -373,10 +373,17 @@
     Unless --force is specified, branch will not let you set a
     branch name that shadows an existing branch.
 
+    Use --clean to reset the working directory branch to that of the
+    parent of the working directory, negating a previous branch change.
+
     Use the command 'hg update' to switch to an existing branch.
     """
 
-    if label:
+    if opts.get('clean'):
+        label = repo[None].parents()[0].branch()
+        repo.dirstate.setbranch(label)
+        ui.status(_('reset working directory to branch %s\n') % label)
+    elif label:
         if not opts.get('force') and label in repo.branchtags():
             if label not in [p.branch() for p in repo.parents()]:
                 raise util.Abort(_('a branch of the same name already exists'
@@ -2987,8 +2994,9 @@
     "branch":
         (branch,
          [('f', 'force', None,
-           _('set branch name even if it shadows an existing branch'))],
-         _('hg branch [-f] [NAME]')),
+           _('set branch name even if it shadows an existing branch')),
+          ('C', 'clean', None, _('reset branch name to parent branch name'))],
+         _('hg branch [-fC] [NAME]')),
     "branches":
         (branches,
          [('a', 'active', False,