[PATCH] git-ssh-pull: commit-id consistency
[git.git] / git-checkout-script
1 #!/bin/sh
2 : ${GIT_DIR=.git}
3 old=$(git-rev-parse HEAD)
4 new=
5 force=
6 branch=
7 while [ "$#" != "0" ]; do
8     arg="$1"
9     shift
10     case "$arg" in
11         "-f")
12                 force=1
13                 ;;
14         *)
15                 rev=$(git-rev-parse --verify --revs-only "$arg")
16                 if [ -z "$rev" ]; then
17                         echo "unknown flag $arg"
18                         exit 1
19                 fi
20                 if [ "$new" ]; then
21                         echo "Multiple revisions?"
22                         exit 1
23                 fi
24                 new="$rev"
25                 if [ -f "$GIT_DIR/refs/heads/$arg" ]; then
26                         branch="$arg"
27                 fi
28                 ;;
29     esac
30     i=$(($i+1))
31 done
32 [ -z "$new" ] && new=$old
33
34 if [ "$force" ]
35 then
36     git-read-tree --reset $new &&
37         git-checkout-cache -q -f -u -a
38 else
39     git-read-tree -m -u $old $new
40 fi
41
42
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 #
48 if [ "$?" -eq 0 ]; then
49         [ "$branch" ] && ln -sf "refs/heads/$branch" "$GIT_DIR/HEAD"
50         rm -f "$GIT_DIR/MERGE_HEAD"
51 fi