Here is a solution to maintain divergent branches in git. Because it is easy to merge by mistake. I give a script that encapsulate git in order to forbid some merge and warn you some merge should be dangerous.
</div>
## how to protect against your own dumb
I work on a project in which some of my git branches should remain divergent. And divergences should grow.
I also use some branch to contain what is common between projects.
Say I have some branches:
master: common to all branches
dev: branch devoted to unstable development
client: branch with features for all client but not general enough for master
An arrow from A to B means, you can merge A in B. If there is no arrow from A to B that means it is *forbidden* to merge A in B. Here is the corresponding rubycode:
<div><codeclass="ruby">
$architecture={
:master => [ :dev, :client ],
:dev => [ :master ],
:client => [ :clientA, :clientB ] }
</code></div>
Having a `:master => [ :dev, :client ]` means you can merge `master` branch into `dev` and `client`.
If by mistake I make a `git checkout master && git merge clientA`, I made a mistake. This is why I made a script which encapsulate the git behaviour to dodge this kind of mistake.
But this script do far more than that. It also merge from top to down. The action `allmerges` will do:
<div><codeclass="zsh">
git co dev && git merge master
git co client && git merge master
git co clientA && git merge client
git co clientB && git merge client
</code></div>
That means, I can update all branches. The algorithm will not make loop even if there is a cycle in the branch hierarchy.
Here it is:
<divclass="small"><codeclass="ruby"file="eng">
#!/usr/bin/env ruby
# encoding: utf-8
# architecture
#
# master <-> dev
# master -> client
# clien -> clientA | clientB
#
# merge using two of these branches should be
# restricted to these rules
# merge to one of these branch and an unknown one should
# raise a warning, and may the option to add this new branch