git-checkout-scripton commit [PATCH] Factor out useful test case infrastructure from t/t6001... into t/t6000-lib.sh (ce11895)
   1#!/bin/sh
   2: ${GIT_DIR=.git}
   3old=$(git-rev-parse HEAD)
   4new=
   5force=
   6branch=
   7while [ "$#" != "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))
  31done
  32[ -z "$new" ] && new=$old
  33
  34if [ "$force" ]
  35then
  36    git-read-tree --reset $new &&
  37        git-checkout-cache -q -f -u -a
  38else
  39    git-read-tree -m -u $old $new
  40fi
  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#
  48if [ "$?" -eq 0 ]; then
  49        [ "$branch" ] && ln -sf "refs/heads/$branch" "$GIT_DIR/HEAD"
  50        rm -f "$GIT_DIR/MERGE_HEAD"
  51fi