Skip to content

Instantly share code, notes, and snippets.

@mbbx6spp
Created October 4, 2010 15:12
Show Gist options
  • Save mbbx6spp/609846 to your computer and use it in GitHub Desktop.
Save mbbx6spp/609846 to your computer and use it in GitHub Desktop.
Sets up a Git-hg repository, cloning from Hg remote repo, converting to Git format, pushing to Git remote repo.
#!/usr/bin/env bash
# Assumes: git-hg is in your PATH.
# Customize defaults for your needs
BASE_DIR=${HOME}/code
PROJECT_DIR=zotonic
HG_REPO_URL=https://zotonic.googlecode.com/hg/
[email protected]:mbbx6spp/zotonic.git
# If any arguments given to script assume it goes in following order:
# $0 ${BASE_DIR} ${PROJECT_DIR} ${HG_REPO_URL}
if [ ! -z "$1" ]; then
BASE_DIR=$1
fi
if [ ! -z "$2" ]; then
PROJECT_DIR=$2
fi
if [ ! -z "$3" ]; then
HG_REPO_URL=$3
fi
if [ ! -z "$4" ]; then
GIT_REPO_URL=$4
fi
echo "The ${PROJECT_NAME} Mercurial project was:"
# No need to edit below here unless logic needs to be different.
git-hg clone ${HG_REPO_URL} ${PROJECT_DIR}
pushd ${PROJECT_DIR}
echo " * checked out locally from ${HG_REPO_URL} to ${BASE_DIR}/${PROJECT_DIR}"
echo " * imported to Git format"
# Use .hgignore as canonical source of ignore file patterns.
# Note: only make this per Git repo, not global!
if [ -f .hgignore ]; then
git config core.excludesfile .hgignore
fi
echo " * set to use .hgignore for excludesfile"
git remote add origin ${GIT_REPO_URL}
# TODO: maybe we should parameterize the branch and remote names?
git push origin master
echo " * pushed to remote Git repo ${GIT_REPO_URL}"
popd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment