mercurial/commands.py
changeset 4197 b2873c587b1a
parent 4195 b5d1eaade333
child 4199 e4c586763258
equal deleted inserted replaced
4196:7e95381a9f1e 4197:b2873c587b1a
   245             ui.status(_('the backout changeset is a new head - '
   245             ui.status(_('the backout changeset is a new head - '
   246                         'do not forget to merge\n'))
   246                         'do not forget to merge\n'))
   247             ui.status(_('(use "backout --merge" '
   247             ui.status(_('(use "backout --merge" '
   248                         'if you want to auto-merge)\n'))
   248                         'if you want to auto-merge)\n'))
   249 
   249 
   250 def branch(ui, repo, label=None):
   250 def branch(ui, repo, label=None, **opts):
   251     """set or show the current branch name
   251     """set or show the current branch name
   252 
   252 
   253     With <name>, set the current branch name. Otherwise, show the
   253     With <name>, set the current branch name. Otherwise, show the
   254     current branch name.
   254     current branch name.
       
   255 
       
   256     Unless --force is specified, branch will not let you set a
       
   257     branch name that shadows an existing branch.
   255     """
   258     """
   256 
   259 
   257     if label is not None:
   260     if label is not None:
       
   261         if not opts.get('force') and label in repo.branchtags():
       
   262             if label not in [p.branch() for p in repo.workingctx().parents()]:
       
   263                 raise util.Abort(_('a branch of the same name already exists'
       
   264                                    ' (use --force to override)'))
   258         repo.opener("branch", "w").write(util.fromlocal(label) + '\n')
   265         repo.opener("branch", "w").write(util.fromlocal(label) + '\n')
   259     else:
   266     else:
   260         b = util.tolocal(repo.workingctx().branch())
   267         b = util.tolocal(repo.workingctx().branch())
   261         if b:
   268         if b:
   262             ui.write("%s\n" % b)
   269             ui.write("%s\n" % b)
  2620           ('d', 'date', '', _('record datecode as commit date')),
  2627           ('d', 'date', '', _('record datecode as commit date')),
  2621           ('', 'parent', '', _('parent to choose when backing out merge')),
  2628           ('', 'parent', '', _('parent to choose when backing out merge')),
  2622           ('u', 'user', '', _('record user as committer')),
  2629           ('u', 'user', '', _('record user as committer')),
  2623          ] + walkopts + commitopts,
  2630          ] + walkopts + commitopts,
  2624          _('hg backout [OPTION]... REV')),
  2631          _('hg backout [OPTION]... REV')),
  2625     "branch": (branch, [], _('hg branch [NAME]')),
  2632     "branch": (branch,
       
  2633                [('f', 'force', None,
       
  2634                  _('create branch even if it shadows an existing branch'))],
       
  2635                 _('hg branch [NAME]')),
  2626     "branches": (branches, [], _('hg branches')),
  2636     "branches": (branches, [], _('hg branches')),
  2627     "bundle":
  2637     "bundle":
  2628         (bundle,
  2638         (bundle,
  2629          [('f', 'force', None,
  2639          [('f', 'force', None,
  2630            _('run even when remote repository is unrelated')),
  2640            _('run even when remote repository is unrelated')),