#!/bin/bash
#
# Setup subtrees.
#
# Parameters
DIRNAME="`dirname $0`"
# Usage
function usage {
echo "Usage: $1 add-submodules
"
exit $2
}
# Check for git-subtree
if ! which git-subtree &> /dev/null; then
echo "fatal: please install git-subtree"
exit 1
fi
# Get module list
repos="`grep = $DIRNAME/../.mrconfig | cut -d = -f 2 | cut -d ' ' -f 4`"
# Add subtrees
for repo in $repos; do
module="`basename $repo .git | sed -e s/^puppet-//`"
if [ ! -d "modules/$module" ]; then
echo "Processing puppet module $module..."
git remote add $module $repo
git subtree add --prefix modules/$module $module master --squash
elif [ ! -d "modules/$module/.git" ]; then
# The puppet module exists and is a subtree, so update it
if ! git remote | grep -qe "^$module$"; then
git remote add $module $repo
fi
# Update subtrees
git fetch $module master
git subtree pull --prefix modules/$module $module master --squash
fi
done