Skip to content

Instantly share code, notes, and snippets.

@djsutherland
Created January 7, 2010 04:03
Show Gist options
  • Save djsutherland/270968 to your computer and use it in GitHub Desktop.
Save djsutherland/270968 to your computer and use it in GitHub Desktop.
A script to set up an hg-to-git clone
#!/bin/sh
# hg-to-git
# sets up a clone of a remote mercurial repository to a git repo
# relies on the wonderful tools from http://repo.or.cz/w/fast-export.git
PROJ_NAME=$1
HG_REMOTE=$2
GIT_REMOTE=$3
echo "---- making the project in $PROJ_NAME"
mkdir $PROJ_NAME
cd $PROJ_NAME
echo '---- cloning the hg repo'
hg clone $HG_REMOTE hg
echo '---- creating the git repo'
mkdir git
cd git
git init --bare
echo '---- migrating hg->git'
hg-fast-export.sh --quiet -r ../hg
if [ -n $GIT_REMOTE ]; then
echo '---- pushing git'
git remote add origin $3
git push origin master
fi
echo "---- writing the update script"
cd ..
echo '#!/bin/sh' > update
echo >> update
if [ -n $GIT_REMOTE ]; then
echo 'GIT_PUSH=1' >> update
else
echo 'GIT_PUSH=' >> update
fi
cat >> update <<'UPDATE'
ROOT=`cd $(dirname $0); pwd`
echo '---- updating hg'
cd $ROOT/hg
hg pull -u
cd -
echo '---- migrating hg->git'
cd $ROOT/git
hg-fast-export.sh --quiet
if [ $GIT_PUSH ]; then
echo '---- pushing git'
git push
fi
cd -
UPDATE
chmod +x update
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment