[PATCH 1 of 3 branch --new] branch: add --new option for creating new branches without offending user

Mads Kiilerich mads at kiilerich.com
Wed Apr 15 21:14:50 UTC 2015


# HG changeset patch
# User Mads Kiilerich <madski at unity3d.com>
# Date 1429131575 14400
#      Wed Apr 15 16:59:35 2015 -0400
# Node ID 564a87ee98c6d0e4f9cf3fe46b1153e07e606668
# Parent  c560d8c687916cb70a6d54c2c9ddcb5c9e457be2
branch: add --new option for creating new branches without offending user

--new makes it explicit that the user is creating a new branch and there is
thus no need for the 'did you want a bookmark?' warning.

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -1058,7 +1058,8 @@ def bookmark(ui, repo, *names, **opts):
 @command('branch',
     [('f', 'force', None,
      _('set branch name even if it shadows an existing branch')),
-    ('C', 'clean', None, _('reset branch name to parent branch name'))],
+    ('C', 'clean', None, _('reset branch name to parent branch name')),
+    ('n', 'new', '', _('mark working directory as creating new branch'))],
     _('[-fC] [NAME]'))
 def branch(ui, repo, label=None, **opts):
     """set or show the current branch name
@@ -1069,11 +1070,12 @@ def branch(ui, repo, label=None, **opts)
        light-weight bookmark instead. See :hg:`help glossary` for more
        information about named branches and bookmarks.
 
-    With no argument, show the current branch name. With one argument,
-    set the working directory branch name (the branch will not exist
-    in the repository until the next commit). Standard practice
-    recommends that primary development take place on the 'default'
-    branch.
+    With no argument, show the current branch name.
+
+    With --new, set the working directory branch name to create a new branch
+    (the branch will not exist in the repository until the next commit).
+    Standard practice recommends that primary development take place on the
+    'default' branch.
 
     Unless -f/--force is specified, branch will not let you set a
     branch name that already exists.
@@ -1087,6 +1089,12 @@ def branch(ui, repo, label=None, **opts)
 
     Returns 0 on success.
     """
+    new = opts.get('new')
+    if new:
+        if label:
+            raise util.Abort(_("--new only takes one branch name"))
+        label = new
+
     if label:
         label = label.strip()
 
@@ -1109,9 +1117,10 @@ def branch(ui, repo, label=None, **opts)
                                      hint=_("use 'hg update' to switch to it"))
             scmutil.checknewlabel(repo, label, 'branch')
             repo.dirstate.setbranch(label)
-            ui.status(_('marked working directory as branch %s\n') % label)
-            ui.status(_('(branches are permanent and global, '
-                        'did you want a bookmark?)\n'))
+            if not new:
+                ui.status(_('marked working directory as branch %s\n') % label)
+                ui.status(_('(branches are permanent and global, '
+                            'did you want a bookmark?)\n'))
     finally:
         wlock.release()
 
diff --git a/tests/test-branches.t b/tests/test-branches.t
--- a/tests/test-branches.t
+++ b/tests/test-branches.t
@@ -11,9 +11,11 @@
   (branches are permanent and global, did you want a bookmark?)
   $ hg commit -d '1 0' -m "Adding a branch"
 
-  $ hg branch q
-  marked working directory as branch q
-  (branches are permanent and global, did you want a bookmark?)
+  $ hg branch --new q q
+  abort: --new only takes one branch name
+  [255]
+
+  $ hg branch --new q
   $ echo 'aa' >a
   $ hg branch -C
   reset working directory to branch a
diff --git a/tests/test-completion.t b/tests/test-completion.t
--- a/tests/test-completion.t
+++ b/tests/test-completion.t
@@ -221,7 +221,7 @@ Show all commands + options
   backout: merge, commit, parent, rev, edit, tool, include, exclude, message, logfile, date, user
   bisect: reset, good, bad, skip, extend, command, noupdate
   bookmarks: force, rev, delete, rename, inactive, template
-  branch: force, clean
+  branch: force, clean, new
   branches: active, closed, template
   bundle: force, rev, branch, base, all, type, ssh, remotecmd, insecure
   cat: output, rev, decode, include, exclude


More information about the Mercurial-devel mailing list