How to properly close a branch?

Didly Bom didlybom at gmail.com
Wed Nov 10 15:06:26 UTC 2010


On Thu, Nov 4, 2010 at 9:29 AM, Gilles Moris <gilles.moris at free.fr> wrote:

> The "hg commit --close-branch" closes a head from a branch so ...
>
> On Wednesday 03 November 2010 08:47:43 am Didly Bom wrote:
> > Hi,
> >
> > I'd like to ask you guys what is the proper way to close a named branch.
> >
> > We often create named "feature" branches which, once finished, we merge
> > into the default branch. Once work on a feature branch is done we want to
> > close the corresponding named branch. However we are not sure of what is
> > the properly way to do so.
> >
> > My questions are:
> >
> > 1. Closing a branch creates a new commit. I believe that this is the last
> > commit _in the branch_. Should we then merge from that last, close commit
> > or from the previous commit, leaving an extra (closed) head on the
> > repository?
> >
>
> It should not really matter provided you merge your feature branch from the
> default branch. The closed commit is basically an empty commit with a
> marker.
> So the merge will not be affected, only the history graph will look
> different.
>
> > 2. Must the "close" commit be performed in the branch that it closes?
> Must
> > it be done at the tip of the corresponding branch?
> >
> > 3. Closing a branch closes the whole branch or just the "head" in which
> the
> > "close" commit is performed? Do you need to perform one "close branch"
> > operation per head in the branch you are closing?
> >
>
> You are closing head by head, not "named-branch" wide. Once all heads have
> been closed on a branch, that branch will no more show up in "hg branches".
>
> Regards.
> Gilles.
>

Thanks a lot for your answer Gilles. Your explanation was very good and in
principle it answers my questions.

It is actually quite confusing that the "--close-branch" flag of the commit
command does not close a branch but a head! Quite frankly I think that the
flag should actually be called "--close-head"!

With your explanation I did some tests to make sure that I understood how
this works. However I still seem to not understand it perfectly because I
got an error when I tried to push after having closed one of the two heads
on my test repository.

Let me try to tell you all the steps I performed. Hopefully I have not
missed any of the steps. Note that I used TortoiseHg 1.1.5 (with Mercurial
1.7) for this test:

- I created a brand new repo with a single file.
- I did an initial commit to create the first changeset of the repo
(revision 0).
- I then created a clone of this repo.
- In the clone I modified the file and committed the change (which created
rev #1).
- I updated to revision #0.
- I modified the file and commited the change, creating a new head at rev
#3.
- I tried to push to the source repo. As expected this failed with the usual
error "abort: push creates new remote heads on branch 'default'!", since
there were 2 heads.
- I then closed the head in revision #3. To do so I used the TortoiseHg
commit tool, selected the branch button and clicked on "Close current
branch".
- At this point there was a single "non closed" head in the repository. To
check this, on the Repository History view of the clone repository I
filtered by "heads" and I saw a single revison (#2).
- I updated to the remaining head.
- I tried to push. Again I got the error "abort: push creates new remote
heads on branch 'default'!"

I was not expecting this last error. Since there is only a single
"non-closed" head I would expect mercurial to send all the changesets to the
source repo.

Is this normal? Am I doing something wrong?
BTW, this is the output of "hg log" on the clone repository:

>hg glog
o  changeset:   4:d179bc264f60
|  tag:         tip
|  user:        Angel
|  date:        Tue Nov 09 14:30:11 2010 +0100
|  summary:     Close
|
o  changeset:   3:e002e4249dfa
|  parent:      1:57b7eb86e96d
|  user:        Angel
|  date:        Tue Nov 09 14:29:41 2010 +0100
|  summary:     4b
|
| @  changeset:   2:2ce74e5015d7
|/   user:        Angel
|    date:        Tue Nov 09 14:28:58 2010 +0100
|    summary:     4
|
o  changeset:   1:57b7eb86e96d
|  user:        Angel
|  date:        Tue Nov 09 14:27:37 2010 +0100
|  summary:     3
|
o  changeset:   0:edc291cb2a9d
   user:        Angel
   date:        Tue Nov 09 14:27:01 2010 +0100
   summary:     1

I really would like to know how to avoid these "abort: push creates new
remote heads on branch 'default'!" because in our project we sometimes end
up with some "dangling" heads that we'd like to "close".

Cheers,

Angel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurial-scm.org/pipermail/mercurial/attachments/20101110/0b77f031/attachment.html>


More information about the Mercurial mailing list