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