tags:

views:

63

answers:

2

I discovered today that I can switch back to a branch even after I closed it. Why?

hg init abc
cd abc
echo 'readme1' > README1.txt
hg ci -Am "1st commit"
hg branch other-branch
echo 'readme2' > README2.txt
hg ci -Am "2nd commit" 
hg update default
hg merge other-branch
hg ci -m "Merged other-branch into default"
hg update other-branch
hg ci -m "Closing other branch" --close-branch
hg update default

now I think I'm not supposed to do this

hg update other-branch

but it works ok

It confuses me and makes me feel somewhat uneasy.

UPDATE: sorry forgot to indicate that I'm using HG v.1.6

+2  A: 

Closing a branch mostly just makes it not show up in certain lists:

http://mercurial.selenic.com/wiki/PruningDeadBranches#Closing_branches

Amber
+2  A: 

Like Amber said, when you close a branch, it just records that it is closed. As a consequence when you do "hg branches" you will just see "default", and not "other-branch".

However, as soon as you switch to this branch and commit something new, it automatically reopen it (and thus appears again in the list of "hg branches"). You can also re-close it when you are done.

I find this feature actually desirable: Imagine you have created a "stable" branch in order to stabilize some code for a delivery, only allowing bug fixes on this branch. Now after the delivery, you can close the stable branch and develop new features again on default, switching to the next iteration and preparing the next delivery (assuming you are using scrum for instance). Now when three days after, your delivery customer finds a problem and demand to receive a fixed delivery, not wanting to wait for the next one, then you can easily switch to the stable branch, reproduce the problem, fix it (reopening the branch), redeploy, and finally close the branch again. This seems like a plausible scenario and a good Mercurial behavior to me.

Just my 0.02€ :-)

Cheers,
Christophe.

= The illiterate of the 21st century will not be those who cannot read or write; they will be those who cannot learn, unlearn, and relearn. --Alvin Toffler =

Christophe Muller