From: Junio C Hamano Date: Fri, 23 Dec 2005 06:37:50 +0000 (-0800) Subject: checkout: sometimes work from a subdirectory. X-Git-Tag: v1.1.0~24^2~1 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=104f3e03c03a83617bac9d120b5e536c5f29d9ef;p=git.git checkout: sometimes work from a subdirectory. git-checkout does two very different things, and what they should do when run from subdirectory are quite different. It does not make any sense to run the one that switches the current head from anywhere other than the toplevel: git-checkout [-f] git-checkout [-b ] We could of course chdir to top and do the whole-tree checkout in git-checkout, but the point is the operation does not make sense on a partial tree. The whole tree is checked out. The other form is to update the index file and working tree file selectively: git-checkout ... ;# out of tree to index and file git-checkout -- ... ;# out of index to file This form _does_ make sense to run from subdirectory; and I myself often wish we supported this. So here is a patch to do both. Signed-off-by: Junio C Hamano --- diff --git a/git-checkout.sh b/git-checkout.sh index 36308d22..1219ea0b 100755 --- a/git-checkout.sh +++ b/git-checkout.sh @@ -1,6 +1,7 @@ #!/bin/sh USAGE='[-f] [-b ] [] [...]' +SUBDIRECTORY_OK=Sometimes . git-sh-setup old=$(git-rev-parse HEAD) @@ -95,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,