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