1#!/bin/sh
2. git-sh-setup-script || die "Not a git archive"
34
old=$(git-rev-parse HEAD)
5new=
6force=
7branch=
8while [ "$#" != "0" ]; do
9arg="$1"
10shift
11case "$arg" in
12"-f")
13force=1
14;;
15*)
16rev=$(git-rev-parse --verify --revs-only "$arg")
17if [ -z "$rev" ]; then
18echo "unknown flag $arg"
19exit 1
20fi
21if [ "$new" ]; then
22echo "Multiple revisions?"
23exit 1
24fi
25new="$rev"
26if [ -f "$GIT_DIR/refs/heads/$arg" ]; then
27branch="$arg"
28fi
29;;
30esac
31i=$(($i+1))
32done
33[ -z "$new" ] && new=$old
3435
if [ "$force" ]
36then
37git-read-tree --reset $new &&
38git-checkout-cache -q -f -u -a
39else
40git-read-tree -m -u $old $new
41fi
4243
#
44# Switch the HEAD pointer to the new branch if it we
45# checked out a branch head, and remove any potential
46# old MERGE_HEAD's (subsequent commits will clearly not
47# be based on them, since we re-set the index)
48#
49if [ "$?" -eq 0 ]; then
50[ "$branch" ] && ln -sf "refs/heads/$branch" "$GIT_DIR/HEAD"
51rm -f "$GIT_DIR/MERGE_HEAD"
52fi