--- a/mercurial/commands.py Thu Apr 19 17:59:23 2012 +0300
+++ b/mercurial/commands.py Thu Apr 19 17:59:23 2012 +0300
@@ -863,23 +863,29 @@
Returns 0 on success.
"""
-
- if opts.get('clean'):
- label = repo[None].p1().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'),
- # i18n: "it" refers to an existing branch
- hint=_("use 'hg update' to switch to it"))
- 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'))
- else:
+ if not opts.get('clean') and not label:
ui.write("%s\n" % repo.dirstate.branch())
+ return
+
+ wlock = repo.wlock()
+ try:
+ if opts.get('clean'):
+ label = repo[None].p1().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'),
+ # i18n: "it" refers to an existing branch
+ hint=_("use 'hg update' to switch to it"))
+ 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'))
+ finally:
+ wlock.release()
@command('branches',
[('a', 'active', False, _('show only branches that have unmerged heads')),