summaryrefslogtreecommitdiff
path: root/git-checkout-script
blob: dc1cffde0bd214b90f0c0b754f0e5f33bd3023b2 (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
#!/bin/sh
: ${GIT_DIR=.git}
old=$(git-rev-parse HEAD)
new=$(git-rev-parse --revs-only "$@")
new=${new:-$old}
args=($(git-rev-parse --no-revs "$@"))

i=0
force=
update=
while [ $i -lt ${#args} ]; do
    case "${args[$i]}" in
	"-f")
		force=1;;
	"-u")
		update=1;;
	"")
		;;
	*)
		echo "unknown flag ${args[$i]}"
		exit 1;;
    esac
    i=$(($i+1))
done

if [ "$force" ]
then
    git-read-tree --reset $new &&
	git-checkout-cache -q -f -u -a
else
    git-read-tree -m -u $old $new
fi && [ "$update" ] && echo $new > "$GIT_DIR/HEAD"