#!/bin/bash set -o errexit SCRIPT="`readlink -e $0`" SCRIPTPATH=$(dirname ${SCRIPT}) source ${SCRIPTPATH}/hv-hg-functions.sh # for use with git-remote-hg: # http://felipec.wordpress.com/2012/11/13/git-remote-hg-bzr-2/ # Uncomment to have verbose debug output #debug=1 print_usage() { echo "$(basename $0) -- HG subrepository importer for git-remote-hg" echo "Usage: $(basename $0) [OPTIONS...]" } if [ "x${1}" = "x--help" ]; then print_usage exit 1 fi if [ ! -f .hgsub ]; then echo "No Mercurial subrepositories found" exit 1 fi if [ ! -f .gitignore ]; then # We do not want to track .gitignore itself echo ".gitignore" > .gitignore fi hg_subpaths_config # Read lines from .hgsub while read sub; do # Remove CR (DOS) sub="${sub//$'\r'/}" if [ "${sub}" != "" ]; then # Get subrepository URL src="${sub//*= /}" # Replace using subpaths extension content src=${src/${sp_src}/${sp_dst}} # Get subrepository local alias or label dest="${sub// =*}" # Get project ID (example: S0289) id=$(echo ${sub} | sed "s/.*\(S[0-9][0-9][0-9][0-9]\).*/\1/") # Get revision of subrepository (remove CR from .hgsubstate) rev=$(cat .hgsubstate | tr -d '\r' | grep "${id}" | sed "s/ .*//") if [ -n "${debug}" ]; then echo "repo: ${src}" echo " id: ${id}" echo " rev: ${rev}" echo " src: ${src}" echo " dest: ${dest}" fi pushd "${dest}" 1> /dev/null echo "============================" echo "subrepo: ${dest}" git pull popd 1> /dev/null fi done < .hgsub