Alex Rivera | Logout

Mercurial: keep 2 branches in sync but with certain persistent differences?

Asked 2009-08-10T15:38:49.810
11

I'm a web developer working on my own using django, and I'm trying to get my head round how best to deploy sites using mercurial. What I'd like to have is to be able to keep one repository that I can use for both production and development work. There will always be some differences between production/development (e.g. they might use different databases, development will always have debug turned on) but by and large they will be in sync. I'd also like to be able to make changes directly on the production server (tidying up html or css, simple bugfixes etc.).

The workflow that I intend to use for doing this is as follows:

  • Create 2 branches, prod and dev (all settings initially set to production settings)
  • Change settings.py and a few other things in the dev branch. So now I've got 2 heads, and from now on the repository will always have 2 heads.
  • (On dev machine) Make changes to dev, then use 'hg transplant' to copy relevant changesets to production.
  • push to master repository
  • (On production server) Pull from master repo, update to prod head

Note: you can also make changes straight to prod so long as you transplant the changes into dev.

This workflow has the drawback that whenever you make a change, not only do you have to commit it to whichever branch you make the change on, you also have to transplant it to the other branch. Is there a more sensible way of doing what I want here, perhaps using patches? Or failing that, is there a way of automating the commit process to automatically transplant the changeset to the other branch, and would this be a good idea?

Edit
Report

1 Answer

1

Perhaps try something like this: (I was just thinking about this issue, in my case it's a sqlite database)

  • Add settings.py to .hgignore, to keep it out of the repository.
  • Take your settings.py files from the two separate branches and move them into two separate files, settings-prod.py and settings-dev.py
  • Create a deploy script which copies the appropriate settings-X file to settings.py, so you can deploy either way.

If you have a couple of additional files, do the same thing for them. If you have a lot of files but they're all in the same directory by themselves, you could just create a pair of directories: production and development, and then either copy or symlink the appropriate one into a deploy directory.

If you did something like this, you could dispense with the need for branching your repository.

answered 2009-08-10T16:30:32.373

Your Answer