summaryrefslogtreecommitdiff
path: root/tool/git-refresh
blob: 7f5361a8532fdecb44f35a6d99a7ed803452f8e3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/bin/sh
set -e

quiet=
branch=
OPT_SPEC="\
${0##*/} [options] URL dir [options]
--
C=directory         Change directory
q,quiet             Quiet
b,branch=branch     Checkout branch
"
rev="$(echo "$OPT_SPEC" | git rev-parse --parseopt -- "$@")"
status=$?
eval "$rev"
[ $status = 0 ] || exit $status

until [ $# = 0 ]; do
    case "$1" in
	--) shift; break;;
	-C) shift; cd "$1";;
	-q) quiet=1;;
	-b) shift; branch="$1";;
	-*) echo "unknown option: $1" 1>&2; exit 1;;
	*) break;;
    esac
    shift
done

url="$1"
dir="$2"
shift 2
if [ -d "$dir" ]; then
    echo updating "${dir#*/}" ...
    [ $quiet ] || set -x
    cd "$dir"
    git fetch "$@"
    exec git checkout ${branch:+"$branch"} "$@"
else
    echo retrieving "${dir#*/}" ...
    [ $quiet ] || set -x
    exec git clone "$url" "$dir" "$@"
fi