Add "git checkout" that does what the name suggests
[git/git.git] / git-checkout-script
1 #!/bin/sh
2 : ${GIT_DIR=.git}
3 old=$(git-rev-parse HEAD)
4 new=$(git-rev-parse --revs-only "$@")
5 new=${new:-$old}
6 args=($(git-rev-parse --no-revs "$@"))
7
8 i=0
9 force=0
10 while [ $i -lt ${#args} ]; do
11 case "${args[$i]}" in
12 "-f")
13 force=1;;
14 "")
15 ;;
16 *)
17 echo "unknown flag ${args[$i]}"
18 exit 1;;
19 esac
20 i=$(($i+1))
21 done
22
23 if $force
24 then
25 git-read-tree --reset $new &&
26 git-checkout-cache -q -f -u -a &&
27 echo $new > "$GIT_DIR/HEAD"
28 else
29 git-read-tree -m -u $old $new && echo $new > "$GIT_DIR/HEAD"
30 fi