2 . git-sh-setup || die
"Not a git archive"
4 old
=$
(git-rev-parse HEAD
)
9 while [ "$#" != "0" ]; do
16 [ -z "$newbranch" ] &&
17 die
"git checkout: -b needs a branch name"
18 [ -e "$GIT_DIR/refs/heads/$newbranch" ] &&
19 die
"git checkout: branch $newbranch already exists"
25 rev=$
(git-rev-parse
--verify "$arg^0") ||
exit
26 if [ -z "$rev" ]; then
27 echo "unknown flag $arg"
31 echo "Multiple revisions?"
35 if [ -f "$GIT_DIR/refs/heads/$arg" ]; then
41 [ -z "$new" ] && new
=$old
44 # If we don't have an old branch that we're switching to,
45 # and we don't have a new branch name for the target we
46 # are switching to, then we'd better just be checking out
49 [ -z "$branch$newbranch" ] &&
50 [ "$new" != "$old" ] &&
51 die
"git checkout: you need to specify a new branch name"
55 git-read-tree
--reset $new &&
56 git-checkout-index
-q -f -u -a
58 git-update-index
--refresh >/dev
/null
59 git-read-tree
-m -u $old $new
63 # Switch the HEAD pointer to the new branch if it we
64 # checked out a branch head, and remove any potential
65 # old MERGE_HEAD's (subsequent commits will clearly not
66 # be based on them, since we re-set the index)
68 if [ "$?" -eq 0 ]; then
69 if [ "$newbranch" ]; then
70 echo $new > "$GIT_DIR/refs/heads/$newbranch"
73 [ "$branch" ] && ln -sf "refs/heads/$branch" "$GIT_DIR/HEAD"
74 rm -f "$GIT_DIR/MERGE_HEAD"