For each public server we have three stages: development, testing, and production. Each of these stages is a web server. I am using named branches in Mercurial to complement this process. The trick is pushing the correct versions of things to to the correct servers i.e. the test branch would be pushed to the test webserver when the script to publish test was ran.

I have the hooks and all the little details worked out. The part I am not sure on is the Mercurial file structure. I want to implement the publish process using RSync and for that I need a local folder to sync from, This folder can be the one I created the repository in on the server, but what I need to confirm is if the server version of the repository can be current to whatever branch I want.

I.e., I create a repository in test

cd test
hg init
touch sample
hg add ./*
hg commit -m "whatever" -u someowner

Now lets say I do a bunch of work from a workstation and commit changes to the repository which create two named branches test and prod. What I am concerned with is the actual test directory. Can I make that directory contain the latest version of a certain named branch (on the server where I did the initialization above) and not hurt the repository itself?

Take this in the context that I am new to Mercurial.

  • 4
    Why do you want to publish via rsync instead of hg push, which will allow you to take advantage of hooks? – Zed Jul 14 '10 at 15:59
  • Also, push should be safe in case the transfer is interrupted (or if someone accesses the repository concurrently), whereas rsync will most certainly corrupt the repository in these cases. – b0fh Jul 15 '10 at 10:54
  • We have a central repository server which I am using a hook on incoming to update the repository folder on the repository server itself, and then RSyncing from the repository folder on the repository folder to the correct server. Pushing is an interesting idea though. I would probably use Public key like I am now, and then push the branch I want to push to the appropriate server correct? Then have apache on the webservers ignore the .hg folders? – Joshua Enfield Jul 15 '10 at 14:16
  • Just FYI: the ./* part is unnecessary and not important for that question. A plain hg add will add all un-ignored files in the repository so there's no need to specify them manually. – Martin Geisler Dec 23 '11 at 16:14

If I understand the scenario and the question right, then the answer is "yes".

Let me explain what I think you're asking: you have a Mercurial repository hosted somewhere and you have three named branches in this repository. I'll assume they're named default, test, and prod. Developers push changes into the repository.

You want to publish the code onto three different webservers, let's call them web-default, web-test, and web-prod. You want to use rsync for this.

This is all a very reasonable setup. The main question is if you can run

$ hg update test
$ rsync -av --exclude .hg . web-test:/var/www

on the server repository and if it will affect future pushes. The answer is "yes", you can update the working copy to whatever revision you want — changesets that are pushed to the server are not affected by this in any way.

So you could make three hooks on the server, something like this:

changegroup.default = hg update default && rsync ... web-default:/var/www
changegroup.test    = hg update test && rsync ... web-test:/var/www
changegroup.prod    = hg update prod && rsync ... web-prod:/var/www

That would publish the tip of each branch onto the corresponding webserver whenever someone pushes to the repository. I hope that helps you!

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.