<div dir="ltr">I deleted duplicate tests and  left them at the end of the file. I didn't <div>want to ruin the current test.</div><div><br></div><div style>Iulian <br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">
2013/5/15 Iulian Stana <span dir="ltr"><<a href="mailto:julian.stana@gmail.com" target="_blank">julian.stana@gmail.com</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
# HG changeset patch<br>
# User Iulian Stana <<a href="mailto:julian.stana@gmail.com">julian.stana@gmail.com</a>><br>
# Date 1367512607 -10800<br>
#      Thu May 02 19:36:47 2013 +0300<br>
# Branch stable<br>
# Node ID f9db59f38518cf077cbc119ac3acfbddc94dbceb<br>
# Parent  90f4587801ed6c525d1264d8f5b9285fb5cb71cc<br>
commit: amending with --close-branch (issue3445)<br>
<br>
You can't close a branch that hasn't got a head.<br>
newbranch + commit --close-branch must fail<br>
newbranch + commit + commit --amend --close-branch must fail<br>
<br>
You must not be allowed to close a branch that is not defined.<br>
<br>
diff --git a/mercurial/commands.py b/mercurial/commands.py<br>
--- a/mercurial/commands.py<br>
+++ b/mercurial/commands.py<br>
@@ -1297,12 +1297,19 @@<br>
         # Let --subrepos on the command line override config setting.<br>
         ui.setconfig('ui', 'commitsubrepos', True)<br>
<br>
+    branch = repo[None].branch()<br>
+    bheads = repo.branchheads(branch)<br>
+<br>
     extra = {}<br>
     if opts.get('close_branch'):<br>
         extra['close'] = 1<br>
<br>
-    branch = repo[None].branch()<br>
-    bheads = repo.branchheads(branch)<br>
+        if not bheads:<br>
+            raise util.Abort(_('can only close branch heads'))<br>
+        elif opts.get('amend'):<br>
+            if repo.parents()[0].p1().branch() != branch and \<br>
+                    repo.parents()[0].p2().branch() != branch:<br>
+                raise util.Abort(_('can only close branch heads'))<br>
<br>
     if opts.get('amend'):<br>
         if ui.configbool('ui', 'commitsubrepos'):<br>
diff --git a/tests/test-commit-amend.t b/tests/test-commit-amend.t<br>
--- a/tests/test-commit-amend.t<br>
+++ b/tests/test-commit-amend.t<br>
@@ -304,6 +304,8 @@<br>
   $ hg branches<br>
   default                        2:ce12b0b57d46<br>
<br>
+<br>
+<br>
 Refuse to amend during a merge:<br>
<br>
   $ hg up -q default<br>
@@ -743,3 +745,32 @@<br>
   -aa<br>
   -aa<br>
<br>
+<br>
+<br>
+Issue 3445: amending with --close-branch a commit that created a new head should fail<br>
+This shouldn't be possible:<br>
+<br>
+  $ hg up -q default<br>
+  $ hg branch closewithamend<br>
+  marked working directory as branch closewithamend<br>
+  (branches are permanent and global, did you want a bookmark?)<br>
+  $ hg ci -Am..<br>
+  adding cc.orig<br>
+  adding obs.py<br>
+  adding obs.pyc<br>
+  $ hg ci --amend --close-branch -m 'closing'<br>
+  abort: can only close branch heads<br>
+  [255]<br>
+<br>
+This silliness fails:<br>
+<br>
+  $ hg branch silliness<br>
+  marked working directory as branch silliness<br>
+  (branches are permanent and global, did you want a bookmark?)<br>
+  $ echo b >> b<br>
+  $ hg ci --close-branch -m'open and close'<br>
+  abort: can only close branch heads<br>
+  [255]<br>
+<br>
+<br>
+<br>
</blockquote></div><br></div>