Created
January 2, 2014 16:21
-
-
Save waj/8221708 to your computer and use it in GitHub Desktop.
Migrate mercurial repository to git
This file contains hidden or 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/new/repo" | |
exit 1 | |
} | |
[ $# -eq 1 ] || abort "Invalid parameters count" | |
[ -d .hg ] || abort "should run this script in an existing mercurial directory" | |
[ -d $1 ] && abort "$1 should not exist" | |
TARGET="$1" | |
GIT="git --git-dir=$TARGET" | |
BRANCHES=`hg branches | cut -f 1 -d " "` | |
mkdir -p "$TARGET" | |
$GIT init --bare | |
for branch in $BRANCHES; do | |
hg bookmark -f "git-$branch" -r $branch | |
done | |
hg push $TARGET | |
for branch in $BRANCHES; do | |
case $branch in | |
default) new_branch="master" ;; | |
*) new_branch=$branch | |
esac | |
$GIT branch -m "git-$branch" "$new_branch" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment