Github and Bitbucket hooks

September 29, 2010 at 05:40 PM | categories: Version Control | View Comments

I use hg but like github

I also dislike unevenness. Having recently read about the hg-git plugin and read about a setup that uses the paths definitions for hg to make simple names to push to, and decided to combine them all together. I ended up with a ~/.hgrc that I had this:

hgext.bookmarks =
hggit =

And then in the repo's .hg/hgrc I'd add something like this:

github = git+ssh://
bitbucket = ssh://

That worked well

But I had to remember to push to both, and that was annoying. Then I dug into hooks and found that I could easily make a shell script to push to both for me. What I ended up with was a bash script that would determine which path I had pushes to, and then push to the other:


# This script takes in the args that a hg push is given and checks for the paths
# that I've defined in my hg repos for either a push to bitbucket or github,
# and then does the other, so that regardless of which of these sites I push to
# the other also get pushed to.

#post-push to bitbucket
if [[ $HG_ARGS =~ "push bitbucket" ]]
    hg push github --quiet

#post-push to github
if [[ $HG_ARGS =~ "push github" ]]
    hg push bitbucket --quiet

Note that the quiet flags or similar must be employed, otherwise you'll get caught in an infinite loop. After that I added this line into my ~/.hgrc

post-push = $HOME/workspace/hooks/


Now regardless of where I push the other will get the update:

~/workspace/hooks$ hg push bitbucket
pushing to ssh://
searching for changes
no changes found

~/workspace/hooks$ hg push github
pushing to git+ssh://
importing Hg objects into Git
creating and sending data
github::refs/heads/master => GIT:b4fb4c58

- blog comments powered by Disqus