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"
20 git-check-ref-format "heads/$newbranch" ||
21 die "we do not like '$newbranch' as a branch name."
27 rev=$(git-rev-parse --verify "$arg^0" 2>/dev/null) ||
28 die "I don't know any '$arg'."
29 if [ -z "$rev" ]; then
30 echo "unknown flag $arg"
34 echo "Multiple revisions?"
38 if [ -f "$GIT_DIR/refs/heads/$arg" ]; then
44 [ -z "$new" ] && new=$old
47 # If we don't have an old branch that we're switching to,
48 # and we don't have a new branch name for the target we
49 # are switching to, then we'd better just be checking out
52 [ -z "$branch$newbranch" ] &&
53 [ "$new" != "$old" ] &&
54 die "git checkout: you need to specify a new branch name"
58 git-read-tree --reset $new &&
59 git-checkout-index -q -f -u -a
61 git-update-index --refresh >/dev/null
62 git-read-tree -m -u $old $new
66 # Switch the HEAD pointer to the new branch if it we
67 # checked out a branch head, and remove any potential
68 # old MERGE_HEAD's (subsequent commits will clearly not
69 # be based on them, since we re-set the index)
71 if [ "$?" -eq 0 ]; then
72 if [ "$newbranch" ]; then
73 echo $new > "$GIT_DIR/refs/heads/$newbranch"
77 GIT_DIR="$GIT_DIR" git-symbolic-ref HEAD "refs/heads/$branch"
78 rm -f "$GIT_DIR/MERGE_HEAD"