minix/releasetools/checkout_repo.sh
Jean-Baptiste Boric ad60a889a0 Replace fetch_u-boot.sh with checkout_repo.sh
This allows checking out Git repositories besides U-Boot.

Co-Authored-By: Benjamin Dauphin <benjamin.dauphin@live.fr>
Co-Authored-By: Gilles Henaux <gill.henaux@gmail.com>
2016-06-01 11:11:25 +02:00

70 lines
1.0 KiB
Bash
Executable File

#!/bin/sh
#
# Perform a checkout / update of git repo if needed
#
OUTPUT_DIR=""
GIT_REVISION=""
REPO_URL=""
BRANCH="master"
while getopts "o:n:b:?" c
do
case "$c" in
\?)
echo "Usage: $0 [-b branch] [-o output_dir] -n revision repo_url" >&2
exit 1
;;
o)
OUTPUT_DIR=$OPTARG
;;
n)
GIT_REVISION=$OPTARG
;;
b)
BRANCH=$OPTARG
;;
esac
done
shift $(($OPTIND - 1))
REPO_URL=$1
#
# check arguments
#
if [ -z "$GIT_REVISION" -o -z "$REPO_URL" -o -z "$OUTPUT_DIR" ]
then
echo "Usage: $0 [-b branch] -o output_dir -n revision repo_url" >&2
exit 1
fi
#
# if the file doesn't exist it's easy , to a checkout
#
if [ ! -e "$OUTPUT_DIR" ]
then
git clone ${REPO_URL} -b $BRANCH $OUTPUT_DIR
fi
(
cd "$OUTPUT_DIR"
#
# perform an update
#
CURRENT_VERSION=$(git rev-parse HEAD)
echo "Checking out $REPO_URL..."
echo " * Current revision: $CURRENT_VERSION"
echo " * Wanted revision: $GIT_REVISION"
if [ "$CURRENT_VERSION" != "$GIT_REVISION" ]
then
echo " * Performing update and checkout..."
git fetch -v
git checkout $GIT_REVISION
fi
)