commit: amending with --close-branch (issue3445) stable
authorIulian Stana <julian.stana@gmail.com>
Thu, 02 May 2013 19:36:47 +0300
branchstable
changeset 19305 b500a663a2c7
parent 19296 da16d21cf4ed
child 19306 59cdd3a7e281
child 19316 6f3428c528b4
commit: amending with --close-branch (issue3445) You can't close a branch that hasn't got a head. newbranch + commit --close-branch must fail newbranch + commit + commit --amend --close-branch must fail You must not be allowed to close a branch that is not defined.
mercurial/commands.py
tests/test-branches.t
tests/test-commit-amend.t
--- a/mercurial/commands.py	Thu Jun 06 14:05:03 2013 -0400
+++ b/mercurial/commands.py	Thu May 02 19:36:47 2013 +0300
@@ -1319,12 +1319,19 @@
         raise util.Abort(_('cannot commit an interrupted graft operation'),
                          hint=_('use "hg graft -c" to continue graft'))
 
+    branch = repo[None].branch()
+    bheads = repo.branchheads(branch)
+
     extra = {}
     if opts.get('close_branch'):
         extra['close'] = 1
 
-    branch = repo[None].branch()
-    bheads = repo.branchheads(branch)
+        if not bheads:
+            raise util.Abort(_('can only close branch heads'))
+        elif opts.get('amend'):
+            if repo.parents()[0].p1().branch() != branch and \
+                    repo.parents()[0].p2().branch() != branch:
+                raise util.Abort(_('can only close branch heads'))
 
     if opts.get('amend'):
         if ui.configbool('ui', 'commitsubrepos'):
--- a/tests/test-branches.t	Thu Jun 06 14:05:03 2013 -0400
+++ b/tests/test-branches.t	Thu May 02 19:36:47 2013 +0300
@@ -267,14 +267,16 @@
   $ hg up -C b
   1 files updated, 0 files merged, 0 files removed, 0 files unresolved
   $ hg commit -d '9 0' --close-branch -m 'close this part branch too'
+  $ hg commit -d '9 0' --close-branch -m 're-closing this branch'
+  abort: can only close branch heads
+  [255]
 
-  $ hg commit -d '9 0' --close-branch -m 're-closing this branch'
   $ hg log -r tip --debug
-  changeset:   13:c2601d54b1427e99506bee25a566ef3a5963af0b
+  changeset:   12:e3d49c0575d8fc2cb1cd6859c747c14f5f6d499f
   branch:      b
   tag:         tip
   phase:       draft
-  parent:      12:e3d49c0575d8fc2cb1cd6859c747c14f5f6d499f
+  parent:      8:eebb944467c9fb9651ed232aeaf31b3c0a7fc6c1
   parent:      -1:0000000000000000000000000000000000000000
   manifest:    8:6f9ed32d2b310e391a4f107d5f0f071df785bfee
   user:        test
@@ -282,13 +284,9 @@
   extra:       branch=b
   extra:       close=1
   description:
-  re-closing this branch
+  close this part branch too
   
   
-  $ hg rollback
-  repository tip rolled back to revision 12 (undo commit)
-  working directory now based on revision 12
-
 --- b branch should be inactive
 
   $ hg branches
--- a/tests/test-commit-amend.t	Thu Jun 06 14:05:03 2013 -0400
+++ b/tests/test-commit-amend.t	Thu May 02 19:36:47 2013 +0300
@@ -743,3 +743,27 @@
   -aa
   -aa
   
+Issue 3445: amending with --close-branch a commit that created a new head should fail
+This shouldn't be possible:
+
+  $ hg up -q default
+  $ hg branch closewithamend
+  marked working directory as branch closewithamend
+  (branches are permanent and global, did you want a bookmark?)
+  $ hg ci -Am..
+  adding cc.orig
+  adding obs.py
+  adding obs.pyc
+  $ hg ci --amend --close-branch -m 'closing'
+  abort: can only close branch heads
+  [255]
+
+This silliness fails:
+
+  $ hg branch silliness
+  marked working directory as branch silliness
+  (branches are permanent and global, did you want a bookmark?)
+  $ echo b >> b
+  $ hg ci --close-branch -m'open and close'
+  abort: can only close branch heads
+  [255]