Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Storing separate named branches in mercurial without having to merge them

It's my first time using a DVCS and also as a lone developer, the first time that I've actually used branches, so maybe I'm missing something here.

I have a remote repository from which I pulled the files and started working. Changes were pushed to the remote repository and of course this simple scenario works fine.

Now that my web application has some stable features, I'd like to start deploying it and so I cloned the remote repository to a new branches/stable directory outside of my working directory for the default branch and used:

hg branch stable

to create a new named branch. I created a bunch of deployment scripts that are needed only by the stable branch and I committed them as needed. Again this worked fine.

Now when I went back to my initial working directory to work on some new features, I found out that Mercurial insists on only ONE head being in the remote repository. In other words, I'd have to merge the two branches (default and stable), adding in the unneeded deployment scripts to my default branch in order to push to the main repository. This could get worse, if I had to make a change to a file in my stable branch in order to deploy.

How do I keep my named branches separate in Mercurial? Do I have to create two separate remote repositories to do so? In which case the named branches lose their value. Am I missing something here?

like image 230
Praveen Angyan Avatar asked Jul 24 '09 13:07

Praveen Angyan


4 Answers

Use hg push -f to force the creation of a new remote head.

The reason push won't do it by default is that it's trying to remind you to pull and merge in case you forgot. What you don't want to happen is:

  • You and I check out revision 100 of named branch "X".
  • You commit locally and push.
  • I commit locally and push.

Now branch X looks like this in the remote repo:

--(100)--(101)
     \
      \---------(102)

Which head should a new developer grab if they're checking out the branch? Who knows.

like image 197
Steve Losh Avatar answered Oct 10 '22 17:10

Steve Losh


After re reading the section on named branchy development in the Mercurial book, I've concluded that for me personally, the best practice is to have separate shared repositories, one for each branch. I was on the free account at bitbucket.org, so I was trying to force myself to use only one shared repository, which created the problem.

I've bit the bullet and got myself a paid account so that I can keep a separate shared repository for my stable releases.

like image 20
Praveen Angyan Avatar answered Oct 10 '22 18:10

Praveen Angyan


You wrote:

I found out that Mercurial insists on only ONE head being in the remote repository.

Why do you think this is the case?

From the help for hg push:

By default, push will refuse to run if it detects the result would increase the number of remote heads. This generally indicates the the client has forgotten to pull and merge before pushing.

If you know that you are intentionally creating a new head in the remote repository, and this is desirable, use the -f flag.

like image 30
Jim Correia Avatar answered Oct 10 '22 16:10

Jim Correia


I've come from git expecting the same thing. Just pushing the top looks like it might be one approach.

hg push -r tip

like image 26
Stephen Emslie Avatar answered Oct 10 '22 16:10

Stephen Emslie