changeset 42202:8d14d91584f1

branch: abort if closing branch from a non-branchhead cset This patch make sure that we abort if the user is trying to close a branch from a cset which is not a branch head. Changes in test file reflect the fixed behaviour. Differential Revision: https://phab.mercurial-scm.org/D6282
author Sushil khanchi <sushilkhanchi97@gmail.com>
date Tue, 16 Apr 2019 02:06:20 +0530
parents 258821f2d465
children 5997eabc7b85
files mercurial/commands.py tests/test-branches.t
diffstat 2 files changed, 5 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/commands.py	Tue Apr 16 01:19:58 2019 +0530
+++ b/mercurial/commands.py	Tue Apr 16 02:06:20 2019 +0530
@@ -1675,6 +1675,8 @@
 
         if not bheads:
             raise error.Abort(_('can only close branch heads'))
+        elif branch == repo['.'].branch() and repo['.'].node() not in bheads:
+            raise error.Abort(_('can only close branch heads'))
         elif opts.get('amend'):
             if (repo['.'].p1().branch() != branch and
                 repo['.'].p2().branch() != branch):
--- a/tests/test-branches.t	Tue Apr 16 01:19:58 2019 +0530
+++ b/tests/test-branches.t	Tue Apr 16 02:06:20 2019 +0530
@@ -956,19 +956,16 @@
 
 trying to close branch from a cset which is not a branch head
 it should abort:
-XXX: it should have aborted here
   $ hg ci -m "closing branch" --close-branch
-  created new head
+  abort: can only close branch heads
+  [255]
 
   $ hg up 0
   0 files updated, 0 files merged, 1 files removed, 0 files unresolved
   $ hg log -GT "{rev}: {node|short} {desc|firstline}\n\t{branch}\n\n"
-  _  3: 006876ddd20e closing branch
+  o  2: 155349b645be added c
   |  	default
   |
-  | o  2: 155349b645be added c
-  |/   	default
-  |
   o  1: 5f6d8a4bf34a added b
   |  	default
   |