Created
September 15, 2019 09:05
-
-
Save lietu/201fc7fe0e575da8e74e42a78d904be4 to your computer and use it in GitHub Desktop.
Sync a Mercurial (hg) repository to a Git repository
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
#!/usr/bin/env sh | |
set -exu | |
# Which Git repo to sync with - change this for sure | |
GIT_REPO="git@..." | |
# Paths | |
HG_REPO="$(pwd -P)" # You might need to change this | |
GIT_TMP="/tmp/git-sync-$(date +%s)" | |
# Ensure SSH key is accepted, you might have to change the grep | |
REMOTE_HOST=$(echo "${GIT_REPO}" | grep -Eo "git@([^:]+)" | cut -d@ -f2) | |
if [ "$(ssh-keygen -F ${GIT_REPO})" == "" ]; then | |
ssh-keyscan -H "${GIT_REPO}" >> ~/.ssh/known_hosts | |
fi | |
# Set up temp git folder | |
mkdir "${GIT_TMP}" | |
cd "${GIT_TMP}" | |
git init . | |
# Sync from HG | |
git config core.notesRef refs/notes/hg | |
git remote add origin "hg::${HG_REPO}" | |
git fetch --all | |
# Sync to Git | |
git remote add other "${GIT_REPO}" | |
git push --all -f other | |
# Clean up | |
cd "${HG_REPO}" | |
rm -rf "${GIT_TMP}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment