--- 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
)