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:
[extensions]
hgext.bookmarks =
hggit =
And then in the repo's .hg/hgrc I'd add something like this:
[paths]
github = git+ssh://git@github.com:goosemo/hooks.git
bitbucket = ssh://hg@bitbucket.org/morgan_goose/hooks
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:
#!/bin/bash
# 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" ]]
then
hg push github --quiet
fi
#post-push to github
if [[ $HG_ARGS =~ "push github" ]]
then
hg push bitbucket --quiet
fi
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
[hooks]
post-push = $HOME/workspace/hooks/github.sh
Success
Now regardless of where I push the other will get the update:
~/workspace/hooks$ hg push bitbucket
pushing to ssh://hg@bitbucket.org/morgan_goose/hooks
searching for changes
no changes found
~/workspace/hooks$ hg push github
pushing to git+ssh://git@github.com:goosemo/hooks.git
importing Hg objects into Git
creating and sending data
github::refs/heads/master => GIT:b4fb4c58
- blog comments powered by Disqus