# HG changeset patch # User Pierre-Yves David # Date 1655172248 -7200 # Node ID 3d3d7fc6035a26e6280a0d7efbd0d31f93b56bf6 # Parent 2f326ea19fbc27a93c9e41fe3d42bbad8d510f53 commit: allow to close branch when committing change over a closed head Otherwise, an explicit other commit become necessary, which seems both silly and verbose. This is useful when merging closed heads on the same branches, for example when merging multiple repositories together. diff -r 2f326ea19fbc -r 3d3d7fc6035a mercurial/commands.py --- a/mercurial/commands.py Thu May 12 13:53:50 2022 +0400 +++ b/mercurial/commands.py Tue Jun 14 04:04:08 2022 +0200 @@ -2087,10 +2087,17 @@ extra[b'close'] = b'1' if repo[b'.'].closesbranch(): - raise error.InputError( - _(b'current revision is already a branch closing head') - ) - elif not bheads: + # Not ideal, but let us do an extra status early to prevent early + # bail out. + matcher = scmutil.match(repo[None], pats, opts) + s = repo.status(match=matcher) + if s.modified or s.added or s.removed: + bheads = repo.branchheads(branch, closed=True) + else: + msg = _(b'current revision is already a branch closing head') + raise error.InputError(msg) + + if not bheads: raise error.InputError( _(b'branch "%s" has no heads to close') % branch ) diff -r 2f326ea19fbc -r 3d3d7fc6035a tests/test-branches.t --- a/tests/test-branches.t Thu May 12 13:53:50 2022 +0400 +++ b/tests/test-branches.t Tue Jun 14 04:04:08 2022 +0200 @@ -283,6 +283,19 @@ abort: current revision is already a branch closing head [10] + $ echo foo > b + $ hg commit -d '9 0' --close-branch -m 're-closing this branch' + + $ echo bar > b + $ hg commit -d '9 0' --close-branch -m 're-closing this branch' bh1 + abort: current revision is already a branch closing head + [10] + $ hg commit -d '9 0' --close-branch -m 're-closing this branch' b + + $ hg debugstrip --rev 13: --no-backup + 1 files updated, 0 files merged, 0 files removed, 0 files unresolved + $ hg revert --all --no-backup + $ hg log -r tip --debug changeset: 12:e3d49c0575d8fc2cb1cd6859c747c14f5f6d499f branch: b