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