X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=git-checkout.sh;h=3bbd1117739b02572aece86030bb9f02f3110d34;hb=0f76f52621a6d760127cf2a508e09287766219b6;hp=73652fa5f367b8200a9fb05740c09cf12a72bc54;hpb=4ae22d96fe9248dac4f26b1fc91154ba5e879799;p=git.git diff --git a/git-checkout.sh b/git-checkout.sh index 73652fa5..3bbd1117 100755 --- a/git-checkout.sh +++ b/git-checkout.sh @@ -1,5 +1,8 @@ #!/bin/sh -. git-sh-setup || die "Not a git archive" + +USAGE='[-f] [-b ] [] [...]' +SUBDIRECTORY_OK=Sometimes +. git-sh-setup old=$(git-rev-parse HEAD) new= @@ -26,6 +29,9 @@ while [ "$#" != "0" ]; do --) break ;; + -*) + usage + ;; *) if rev=$(git-rev-parse --verify "$arg^0" 2>/dev/null) then @@ -74,8 +80,7 @@ then # from a specific tree-ish; note that this is for # rescuing paths and is never meant to remove what # is not in the named tree-ish. - git-ls-tree -r "$new" "$@" | - sed -ne 's/^\([0-7]*\) blob \(.*\)$/\1 \2/p' | + git-ls-tree --full-name -r "$new" "$@" | git-update-index --index-info || exit $? fi git-checkout-index -f -u -- "$@" @@ -91,6 +96,14 @@ else fi fi +# We are switching branches and checking out trees, so +# we *NEED* to be at the toplevel. +cdup=$(git-rev-parse --show-cdup) +if test ! -z "$cdup" +then + cd "$cdup" +fi + [ -z "$new" ] && new=$old # If we don't have an old branch that we're switching to, @@ -112,14 +125,16 @@ else fi # -# Switch the HEAD pointer to the new branch if it we +# Switch the HEAD pointer to the new branch if we # checked out a branch head, and remove any potential # old MERGE_HEAD's (subsequent commits will clearly not # be based on them, since we re-set the index) # if [ "$?" -eq 0 ]; then if [ "$newbranch" ]; then - echo $new > "$GIT_DIR/refs/heads/$newbranch" + leading=`expr "refs/heads/$newbranch" : '\(.*\)/'` && + mkdir -p "$GIT_DIR/$leading" && + echo $new >"$GIT_DIR/refs/heads/$newbranch" || exit branch="$newbranch" fi [ "$branch" ] &&