views:

76

answers:

2

I work mostly with Git and have a lot of code on github. I would also like to have it on Bitbucket, for people using mercurial but more importantly as I want to also have the code on my domian, and BItbucket supports Cnames for hosted code.

So is there a way for me to mostly work with Git, but also be able to push to HG.

Github created a project in other direction, (For HG repos to git), but is there one for the direction I am looking for.

+3  A: 

If you're just doing a mirror of the Git repo(s), then you can set up a cron job to run the following script:

#!/bin/bash

USER=bitbucketuser
ERROR_FILE=clone_update_err
CLONES=/path/to/clones

cd $CLONES

if [ $# -ne 1 ]; then
    for DIR in *; do
        if [ -d $DIR ]; then
            ./update.sh $DIR 2> $ERROR_FILE
            if [ -s $ERROR_FILE ]; then
                echo $DIR >&2
                cat -n $ERROR_FILE >&2
            fi
        fi
    done
else
    DIR=$1
    echo $DIR
    cd $DIR

    if [ -a source ]; then
        cd source
        if [ -d .hg ]; then
            hg pull
        elif [ -d .git ]; then
            git pull
        elif [ -d .bzr ]; then
            bzr pull
        elif [ -d .svn ]; then
            svn up
        else
            echo "$DIR is not a known repository type."
            return 1
        fi

        cd ..
        hg convert source hg

        URL=ssh://[email protected]/$USER/$DIR/
        cd hg
        hg pull $URL
        hg push $URL # You can add -f here if you don't mind multiple heads
        cd ..
    else
        # hg dir or hg-git
        cd hg
        hg pull
        hg push $URL
        cd ..
    fi

    cd ..

    sleep 5
fi

This assumes you have an SSH key installed. As you can see, it will mirror other VCSs as well. It assumes a directory structure like this:

clones/
  project1/
    source/  # Original Git/Bazaar/SVN/Mercurial repo
    hg/      # Mercurial repo

Obviously, this is only one-way, but if you do all of your work in Git, then it won't matter.

tghw
+5  A: 

I was going to add this to my other answer, but it got a little long, so we'll do it as a separate answer.

If you want to go both ways, you can use hg-git to get an hg version of the repo on your machine. You can still do all of your work in Git, it just means you'll be using GitHub as your intermediary.

$ cd src
# do some work
# push to GitHub
$ cd ../hg
$ hg pull
$ hg push bitbucket

However, it does have the benefit that if you want to pull changes from a Mercurial user, you can pull them into the hg repo, and push them out to GitHub.

$ cd hg
$ hg pull someotherrepo
  # Probably merge
$ hg push # Changes go to GitHub
$ cd ../src
$ git pull
  # Continue working in Git
tghw