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."
30 if rev=$
(git-rev-parse
--verify "$arg^0" 2>/dev
/null
)
32 if [ -z "$rev" ]; then
33 echo "unknown flag $arg"
37 if [ -f "$GIT_DIR/refs/heads/$arg" ]; then
40 elif rev=$
(git-rev-parse
--verify "$arg^{tree}" 2>/dev
/null
)
42 # checking out selected paths from a tree-ish.
56 # The behaviour of the command with and without explicit path
57 # parameters is quite different.
59 # Without paths, we are checking out everything in the work tree,
60 # possibly switching branches. This is the traditional behaviour.
62 # With paths, we are _never_ switching branch, but checking out
63 # the named paths from either index (when no rev is given),
64 # or the named tree-ish (when rev is given).
68 if test '' != "$newbranch$force"
70 die
"updating paths and switching branches or forcing are incompatible."
74 # from a specific tree-ish; note that this is for
75 # rescuing paths and is never meant to remove what
76 # is not in the named tree-ish.
77 git-ls-tree
-r "$new" "$@" |
78 sed -ne 's/^\([0-7]*\) blob \(.*\)$/\1 \2/p' |
79 git-update-index
--index-info ||
exit $?
81 git-checkout-index
-f -u -- "$@"
84 # Make sure we did not fall back on $arg^{tree} codepath
85 # since we are not checking out from an arbitrary tree-ish,
86 # but switching branches.
89 git-rev-parse
--verify "$new^{commit}" >/dev
/null
2>&1 ||
90 die
"Cannot switch branch to a non-commit."
94 [ -z "$new" ] && new
=$old
96 # If we don't have an old branch that we're switching to,
97 # and we don't have a new branch name for the target we
98 # are switching to, then we'd better just be checking out
101 [ -z "$branch$newbranch" ] &&
102 [ "$new" != "$old" ] &&
103 die
"git checkout: you need to specify a new branch name"
107 git-read-tree
--reset $new &&
108 git-checkout-index
-q -f -u -a
110 git-update-index
--refresh >/dev
/null
111 git-read-tree
-m -u $old $new
115 # Switch the HEAD pointer to the new branch if it we
116 # checked out a branch head, and remove any potential
117 # old MERGE_HEAD's (subsequent commits will clearly not
118 # be based on them, since we re-set the index)
120 if [ "$?" -eq 0 ]; then
121 if [ "$newbranch" ]; then
122 echo $new > "$GIT_DIR/refs/heads/$newbranch"
126 GIT_DIR
="$GIT_DIR" git-symbolic-ref HEAD
"refs/heads/$branch"
127 rm -f "$GIT_DIR/MERGE_HEAD"