Skip to content

Instantly share code, notes, and snippets.

@mbarkhau
Created May 24, 2020 20:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mbarkhau/c49877ce4a506d6d8676107fd6305bca to your computer and use it in GitHub Desktop.
Save mbarkhau/c49877ce4a506d6d8676107fd6305bca to your computer and use it in GitHub Desktop.
A helper script to migrate mercurial repositories to gitlab/github
#!/bin/bash
set -e;
REPOUSER=mbarkhau
mkdir -p $HOME/workspace
cd $HOME/workspace
if ! [[ -d fast-export ]]; then
git clone https://github.com/frej/fast-export.git
fi
if ! [[ -d $1-hg ]]; then
hg clone ssh://hg@bitbucket.org/$REPOUSER/$1 $1-hg
fi
mkdir -p $1
cd $1
if ! [[ -d .git ]]; then
git init
$HOME/workspace/fast-export/hg-fast-export.sh -r ../$1-hg/
fi
git checkout HEAD
cat << EOF > .git/config
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[remote "origin"]
url = git@gitlab.com:$REPOUSER/$1.git
fetch = +refs/heads/*:refs/remotes/origin/*
[remote "gitlab"]
url = git@gitlab.com:$REPOUSER/$1.git
fetch = +refs/heads/*:refs/remotes/origin/*
[remote "github"]
url = git@github.com:$REPOUSER/$1.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
EOF
git push
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment