Created
October 9, 2013 15:49
-
-
Save matiasgarciaisaia/6903416 to your computer and use it in GitHub Desktop.
A script for migrating a Mercurial repository to a new git one
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
function abort() { | |
echo "ERROR: $1" | |
echo "" | |
echo "USAGE: $0 /path/to/hg/repo /path/to/new/repo" | |
exit 1 | |
} | |
[ $# -eq 2 ] || abort "Invalid parameters count" | |
[ -d $1 ] || abort "$1 should be an existing hg repository" | |
[ -d $1/.hg ] || abort "$1 should be an existing hg repository ($1/.hg must be a directory)" | |
[ -d $2 ] && abort "$2 should not exist" | |
SOURCE=$(cd "$1" && pwd) | |
mkdir -p "$2" && cd "$2" | |
TARGET=$(pwd) | |
git clone git://repo.or.cz/fast-export.git "$TARGET" | |
rm -rf .git .gitignore | |
git init | |
./hg-fast-export.sh -r "$SOURCE" | |
for branch in $(cd "$SOURCE" && hg branches --closed | grep \(closed\) | cut -f1 -d' ') | |
do | |
git checkout "$branch" && git tag "$branch" && git checkout master && git branch -D "$branch" | |
done | |
git reset . && git checkout . && git clean -f |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment