X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=git-checkout.sh;h=3bbd1117739b02572aece86030bb9f02f3110d34;hb=b21c31c9a5edfd90d6f85481517f979352da4eed;hp=4cf30e2c0529e90886e6edfd485cec67a278e224;hpb=5e80092f7e6db09a40a62e837ca3f74f0bc5ad73;p=git.git diff --git a/git-checkout.sh b/git-checkout.sh index 4cf30e2c..3bbd1117 100755 --- a/git-checkout.sh +++ b/git-checkout.sh @@ -1,9 +1,8 @@ #!/bin/sh -. git-sh-setup -usage () { - die "usage: git checkout [-f] [-b ] [] [...]" -} +USAGE='[-f] [-b ] [] [...]' +SUBDIRECTORY_OK=Sometimes +. git-sh-setup old=$(git-rev-parse HEAD) new= @@ -81,7 +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" "$@" | + git-ls-tree --full-name -r "$new" "$@" | git-update-index --index-info || exit $? fi git-checkout-index -f -u -- "$@" @@ -97,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, @@ -118,7 +125,7 @@ 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)