[PATCH v2] commit: amending with --close-branch (issue3445)

Iulian Stana julian.stana at gmail.com
Thu May 2 16:12:41 CDT 2013


# HG changeset patch
# User Iulian Stana <julian.stana at gmail.com>
# Date 1367512607 -10800
#      Thu May 02 19:36:47 2013 +0300
# Branch stable
# Node ID 4e58fbec4055006d786075074d4c6f78799df451
# Parent  90f4587801ed6c525d1264d8f5b9285fb5cb71cc
commit: amending with --close-branch (issue3445)

You can't close a branch that hasn't got a head.
newbrach + commit --close must fail
newbranch + commit + commit --amend --close must fail

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -1297,12 +1297,18 @@
         # Let --subrepos on the command line override config setting.
         ui.setconfig('ui', 'commitsubrepos', True)
 
+    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:
+                raise util.Abort(_('can only close branch heads'))
 
     if opts.get('amend'):
         if ui.configbool('ui', 'commitsubrepos'):
diff --git a/tests/test-commit.t b/tests/test-commit.t
--- a/tests/test-commit.t
+++ b/tests/test-commit.t
@@ -307,3 +307,58 @@
        1         6       7  .....       1 d267bddd54f7 26d3ca0dfd18 000000000000 (re)
 
   $ cd ..
+
+
+Issue 3445: amending with --close-branch a commit that created a new head should fail
+This shouldn't be possible:
+
+  $ hg init issue3445
+  $ cd issue3445
+  $ echo a >> a
+  $ hg ci -Am.
+  adding a
+  $ echo a >> a
+  $ hg branch foo
+  marked working directory as branch foo
+  (branches are permanent and global, did you want a bookmark?)
+  $ hg ci -Am..
+  $ hg ci --amend --close-branch -m 'closing'
+  abort: can only close branch heads
+  [255]
+
+
+This silliness fails:
+
+  $ hg branch newbranch
+  marked working directory as branch newbranch
+  (branches are permanent and global, did you want a bookmark?)
+  $ echo b >> b
+  $ hg ci --close -m'open and close'
+  abort: can only close branch heads
+  [255]
+
+Correct close with commit:
+
+  $ hg branch correctclose
+  marked working directory as branch correctclose
+  (branches are permanent and global, did you want a bookmark?)
+  $ echo b >> b
+  $ hg ci -Am.
+  adding b
+  $ hg ci --close -m'open and close'
+
+Correct close with commit and amend:
+
+  $ hg branch amendclose
+  marked working directory as branch amendclose
+  (branches are permanent and global, did you want a bookmark?)
+  $ echo c >> c
+  $ hg ci -Am.
+  adding c
+  $ echo a >> a
+  $ hg ci -Am.
+  $ hg ci --amend --close -m'open and close'
+  saved backup bundle to $TESTTMP/issue3445/.hg/strip-backup/109ed8058c1e-amend-backup.hg
+  $ cd ..
+
+


More information about the Mercurial-devel mailing list