Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mercurial: allow merge from a release branch to the default one, but not vice versa

Tags:

mercurial

I'm using default branch for ongoing development, and now going to create a new named branch to mark a release. All further development will be on the default branch, all production bugfixes will be done on the new one (with subsequent merge to default), like this:

#>hg branches
   aristotle   42:dbd...
   default     41:da5...
#>hg branch
   default
#>echo "Feature #1 for the next release" >> feature1.txt
#>hg add
#>hg commit -m "Implement feature #1 for the next release" 

...... eek, need to make an urgent fix on Production .....

#>hg update aristotle
#>echo "Fixed urgent bug #123 on Production" >> fix123.txt
#>hg add
#>hg commit -m "Fixed bug #123 on Production" 
   created new head
#>hg update default
#>hg merge aristotle
   1 files updated, 0 files merged, 0 files removed, 0 files unresolved
   (branch merge, dont forget to commit)
#>hg commit -m "Merge in the fix for bug #123"
#>hg push

The above seems the way to go, however it seems easy to mess things up and merge the other way around (from default to aristotle which means all the new features will appear in the production branch).

Maybe my fears are groundless because one will notice the mess before pushing the commit to the central repo, but I'd like to see if it's possible to make the approach more foolproof.

So I started looking into hooks:

[hooks]
pretxnchangegroup.branch = hg heads --template "{branches} " | find "aristotle" && exit 1 || exit 0

..but then realized it's not what I need, because this will not allow me to push aristotle changes at all.

So I'm not sure what to do. Ideally, I want developers to see the "wrong way merge" message when they attempt to commit a merge from default to aristotle locally (obviously, there should be a double-check on the central repo), while merging from production branch to the default one should be possible.

Thanks!

like image 866
andreister Avatar asked May 16 '11 14:05

andreister


People also ask

What is mercurial default branch?

Named branches If no branch name was set, Mercurial assigns the branch name "default". So the name of the default branch in a repository is "default" (which, for example, is not displayed when doing a hg log). Mercurial branch names may be used for whatever reasons users want.

How do you merge Heads in Mercurial?

To start a merge between the two heads, we use the hg merge command. We resolve the contents of hello. c This updates the working directory so that it contains changes from both heads, which is reflected in both the output of hg parents and the contents of hello.


1 Answers

This should do it. It uses a revset query to find any merges into aristotle from default.

hg log -r 'children(p2(::aristotle and ::default and merge()) and branch(default)) and branch(aristotle)'
  • ::aristotle and ::default and merge() finds all merges that are ancestors of both aristotle and default branches
  • p2(...) and branch(default) grabs the second parent (incoming changeset) that are on the default branch.
  • children(...) and branch(aristotle) then grabs the actual merge changeset that is on the aristotle branch.

I recently needed to figure this out myself but also needed to ensure that default wasn't indirectly merged into my release branch, i.e. default -> feature -> release.

like image 168
Aaron Jensen Avatar answered Oct 17 '22 12:10

Aaron Jensen