Mercurial > public > mercurial-scm > hg
diff mercurial/commands.py @ 42542:2e1d9414ff71
commit: add --force-close-branch flag to close a non-head changeset
While closing branch from a changeset which is not a branch head
current implementation abort this action in every case but, there
can be the situations where the changeset is not a local head but
could be a remote head. This patch adds the functionality to bypass
the "abort: can only close branch heads" by introducing
--force-close-branch flag.
Test case changes demonstrate the new functionality added.
Differential Revision: https://phab.mercurial-scm.org/D6490
author | Sushil khanchi <sushilkhanchi97@gmail.com> |
---|---|
date | Sat, 18 May 2019 15:44:23 +0530 |
parents | 3de4f17f4824 |
children | 70f1a84d0794 |
line wrap: on
line diff
--- a/mercurial/commands.py Fri Jun 28 21:31:34 2019 +0530 +++ b/mercurial/commands.py Sat May 18 15:44:23 2019 +0530 @@ -1584,6 +1584,8 @@ ('', 'amend', None, _('amend the parent of the working directory')), ('s', 'secret', None, _('use the secret phase for committing')), ('e', 'edit', None, _('invoke editor on commit messages')), + ('', 'force-close-branch', None, + _('forcibly close branch from a non-head changeset (ADVANCED)')), ('i', 'interactive', None, _('use interactive mode')), ] + walkopts + commitopts + commitopts2 + subrepoopts, _('[OPTION]... [FILE]...'), @@ -1671,7 +1673,7 @@ bheads = repo.branchheads(branch) extra = {} - if opts.get('close_branch'): + if opts.get('close_branch') or opts.get('force_close_branch'): extra['close'] = '1' if repo['.'].closesbranch(): @@ -1679,8 +1681,11 @@ ' head')) elif not bheads: raise error.Abort(_('branch "%s" has no heads to close') % branch) - elif branch == repo['.'].branch() and repo['.'].node() not in bheads: - raise error.Abort(_('can only close branch heads')) + elif (branch == repo['.'].branch() and repo['.'].node() not in bheads + and not opts.get('force_close_branch')): + hint = _('use --force-close-branch to close branch from a non-head' + ' changeset') + raise error.Abort(_('can only close branch heads'), hint=hint) elif opts.get('amend'): if (repo['.'].p1().branch() != branch and repo['.'].p2().branch() != branch):