Patchwork [v4] commit: amending with --close-branch (issue3445)

login
register
mail settings
Submitter Iulian Stana
Date May 14, 2013, 9:18 p.m.
Message ID <f9db59f38518cf077cbc.1368566284@doppler>
Download mbox | patch
Permalink /patch/1641/
State Accepted
Commit b500a663a2c7543e9e8484e58753fefd71b2aa17
Headers show

Comments

Iulian Stana - May 14, 2013, 9:18 p.m.
# HG changeset patch
# User Iulian Stana <julian.stana@gmail.com>
# Date 1367512607 -10800
#      Thu May 02 19:36:47 2013 +0300
# Branch stable
# Node ID f9db59f38518cf077cbc119ac3acfbddc94dbceb
# Parent  90f4587801ed6c525d1264d8f5b9285fb5cb71cc
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.
Iulian Stana - May 14, 2013, 9:21 p.m.
I deleted duplicate tests and  left them at the end of the file. I didn't
want to ruin the current test.

Iulian


2013/5/15 Iulian Stana <julian.stana@gmail.com>

> # HG changeset patch
> # User Iulian Stana <julian.stana@gmail.com>
> # Date 1367512607 -10800
> #      Thu May 02 19:36:47 2013 +0300
> # Branch stable
> # Node ID f9db59f38518cf077cbc119ac3acfbddc94dbceb
> # Parent  90f4587801ed6c525d1264d8f5b9285fb5cb71cc
> 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.
>
> diff --git a/mercurial/commands.py b/mercurial/commands.py
> --- a/mercurial/commands.py
> +++ b/mercurial/commands.py
> @@ -1297,12 +1297,19 @@
>          # 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 and \
> +                    repo.parents()[0].p2().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-amend.t b/tests/test-commit-amend.t
> --- a/tests/test-commit-amend.t
> +++ b/tests/test-commit-amend.t
> @@ -304,6 +304,8 @@
>    $ hg branches
>    default                        2:ce12b0b57d46
>
> +
> +
>  Refuse to amend during a merge:
>
>    $ hg up -q default
> @@ -743,3 +745,32 @@
>    -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]
> +
> +
> +
>
Matt Mackall - June 7, 2013, 9:06 p.m.
On Wed, 2013-05-15 at 00:18 +0300, Iulian Stana wrote:
> # HG changeset patch
> # User Iulian Stana <julian.stana@gmail.com>
> # Date 1367512607 -10800
> #      Thu May 02 19:36:47 2013 +0300
> # Branch stable
> # Node ID f9db59f38518cf077cbc119ac3acfbddc94dbceb
> # Parent  90f4587801ed6c525d1264d8f5b9285fb5cb71cc
> commit: amending with --close-branch (issue3445)

Looks like this fell through the cracks. Queued for stable, thanks.

Patch

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -1297,12 +1297,19 @@ 
         # 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 and \
+                    repo.parents()[0].p2().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-amend.t b/tests/test-commit-amend.t
--- a/tests/test-commit-amend.t
+++ b/tests/test-commit-amend.t
@@ -304,6 +304,8 @@ 
   $ hg branches
   default                        2:ce12b0b57d46
 
+
+
 Refuse to amend during a merge:
 
   $ hg up -q default
@@ -743,3 +745,32 @@ 
   -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]
+
+
+