#!/bin/bash set -o errexit SCRIPT="`readlink -e $0`" SCRIPTPATH=$(dirname ${SCRIPT}) source ${SCRIPTPATH}/hv-hg-functions.sh PROG_NAME=$(basename $0) # Version control checkout command for all subrepositories. # 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) -- Version control subrepository checkout" echo "Usage: $(basename $0) [OPTIONS...]" echo "Options:" echo " -h display this help and exit" echo " -m display only subrepositories with local modifications" } if [ "x${1}" = "x--help" ]; then print_usage exit 1 fi if [ ${#} -eq 0 ]; then echo "${PROG_NAME}: Missing branch name." echo "Try \`${PROG_NAME} --help' for more information." exit 1 elif [ ${#} -gt 1 ]; then echo "${PROG_NAME}: Too many arguments." echo "Try \`${PROG_NAME} --help' for more information." exit 1 fi branch=${1} if [ ! -f .hgsub ]; then echo "No Mercurial subrepositories found" exit 1 fi checkout_branch() { if [ ${#} -eq 0 ]; then echo "${PROG_NAME}: Missing branch name." exit 1 fi local branch=${1} if vb | egrep -q "^\s+${branch}$" ; then # Branch found vco ${branch} 1> /dev/null 2>&1 if [ -n "${debug}" ]; then echo "Changing branch" echo # Blank line fi elif vb | egrep -q "^\**\s+${branch}$" ; then if [ -n "${debug}" ]; then echo "Already on branch" echo # Blank line fi else if [ -n "${debug}" ]; then echo "Branch not found" echo # Blank line fi fi } # Switch branch on main assembly if [ -n "${debug}" ]; then dest="Top assembly" display_subrepo_name fi checkout_branch ${branch} # Read lines from .hgsub while read sub; do # Remove CR (DOS) sub="${sub//$'\r'/}" if [ "${sub}" != "" ]; then # 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/") if [ -n "${debug}" ]; then display_subrepo_name fi if [ -d "${dest}" ]; then pushd "${dest}" 1> /dev/null checkout_branch ${branch} popd 1> /dev/null else display_subrepo_name echo "Error: missing local subrepository" echo # Blank line fi fi done < .hgsub