Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git bridge to Mercurial

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.

like image 370
agiliq Avatar asked Dec 23 '22 01:12

agiliq


1 Answers

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.

like image 133
tghw Avatar answered Jan 02 '23 14:01

tghw