{"thread":{"id":"2914","subject":"git-checkout and SUBDIRECTORY_OK='Yes'","startedAt":"2005-12-23T04:20:13Z","lastAt":"2005-12-23T17:56:16Z","messageCount":3,"participants":["Jon Nelson","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"13974","messageId":"Pine.LNX.4.63.0512222217040.6812@gheavc.wnzcbav.cig","threadId":"2914","inReplyTo":null,"subject":"git-checkout and SUBDIRECTORY_OK='Yes'","fromName":"Jon Nelson","fromEmail":"jnelson-git@jamponi.net","sentAt":"2005-12-23T04:20:13Z","receivedAt":"2005-12-23T04:20:13Z","isPatch":false,"sender":{"key":"jnelson-git@jamponi.net","avatar":null},"body":"\nIs it safe to set SUBDIRECTORY_OK='Yes' in git-checkout.sh?\nWhat about the other *.sh that don't already set it?\n\n--\nJon Nelson <jnelson-git@jamponi.net>\n"},{"id":"13975","messageId":"7virtge7fb.fsf@assigned-by-dhcp.cox.net","threadId":"2914","inReplyTo":"Pine.LNX.4.63.0512222217040.6812@gheavc.wnzcbav.cig","subject":"Re: git-checkout and SUBDIRECTORY_OK='Yes'","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-12-23T04:58:16Z","receivedAt":"2005-12-23T04:58:16Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jon Nelson <jnelson-git@jamponi.net> writes:\n\n> Is it safe to set SUBDIRECTORY_OK='Yes' in git-checkout.sh?\n\nPersonally, I do not like this kind of question. If it were\nknown to be safe we would have set it so already.\n\nAh, I must be tired.  Sorry.  Let's try again.\n\ngit-checkout does two very different things, and what they\nshould do when run from subdirectory are probably quite\ndifferent.\n\nIt does not make any sense to run the one that switches the\ncurrent head from anywhere other than the toplevel:\n\n\tgit-checkout [-f] <branch>\n        git-checkout [-b <branch>] <committish>\n\nWe could of course chdir to top and do the whole-tree checkout\nin git-checkout, but the point is the operation does not make\nsense on a partial tree.\n\nThe other form is to update the index file and working tree file\nselectively:\n\n\tgit-checkout <treeish> <file>... ;# out of tree to index and file\n        git-checkout -- <file>...\t ;# out of index to file\n\nThis form _does_ make sense to run from subdirectory; and I\nmyself often wish we supported this.\n\nBefore SUBDIRECTORY_OK was introduced, git-*.sh commands were\ncarefully inspected and the ones that do not make much sense to\nbe run in subdirectories were marked with sh-setup.  So if you\ndo not see SUBDIRECTORY_OK, it is very likely that you need some\nreal work (like the analysis above to think what should happen\nwhen run from a subdirectory, and actually coding it).\n\nThis patch *might* work, or it may not.  Please let us know.\n\n\ndiff --git a/git-checkout.sh b/git-checkout.sh\nindex 36308d2..1219ea0 100755\n--- a/git-checkout.sh\n+++ b/git-checkout.sh\n@@ -1,6 +1,7 @@\n #!/bin/sh\n \n USAGE='[-f] [-b <new_branch>] [<branch>] [<paths>...]'\n+SUBDIRECTORY_OK=Sometimes\n . git-sh-setup\n \n old=$(git-rev-parse HEAD)\n@@ -95,6 +96,14 @@ else\n \tfi\n fi\n \n+# We are switching branches and checking out trees, so\n+# we *NEED* to be at the toplevel.\n+cdup=$(git-rev-parse --show-cdup)\n+if test ! -z \"$cdup\"\n+then\n+\tcd \"$cdup\"\n+fi\n+\n [ -z \"$new\" ] && new=$old\n \n # If we don't have an old branch that we're switching to,\ndiff --git a/rev-parse.c b/rev-parse.c\nindex bb4949a..0c951af 100644\n--- a/rev-parse.c\n+++ b/rev-parse.c\n@@ -216,6 +216,18 @@ int main(int argc, char **argv)\n \t\t\t\t\tputs(prefix);\n \t\t\t\tcontinue;\n \t\t\t}\n+\t\t\tif (!strcmp(arg, \"--show-cdup\")) {\n+\t\t\t\tconst char *pfx = prefix;\n+\t\t\t\twhile (pfx) {\n+\t\t\t\t\tpfx = strchr(pfx, '/');\n+\t\t\t\t\tif (pfx) {\n+\t\t\t\t\t\tpfx++;\n+\t\t\t\t\t\tprintf(\"../\");\n+\t\t\t\t\t}\n+\t\t\t\t}\n+\t\t\t\tputchar('\\n');\n+\t\t\t\tcontinue;\n+\t\t\t}\n \t\t\tif (!strcmp(arg, \"--git-dir\")) {\n \t\t\t\tconst char *gitdir = getenv(GIT_DIR_ENVIRONMENT);\n \t\t\t\tstatic char cwd[PATH_MAX];\n"},{"id":"13985","messageId":"7vwthv7l4v.fsf@assigned-by-dhcp.cox.net","threadId":"2914","inReplyTo":"7virtge7fb.fsf@assigned-by-dhcp.cox.net","subject":"Re: git-checkout and SUBDIRECTORY_OK='Yes'","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-12-23T17:56:16Z","receivedAt":"2005-12-23T17:56:16Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Junio C Hamano <junkio@cox.net> writes:\n\n> Jon Nelson <jnelson-git@jamponi.net> writes:\n>\n>> Is it safe to set SUBDIRECTORY_OK='Yes' in git-checkout.sh?\n\n> This patch *might* work, or it may not...\n\nI've done some tests and it seems to work (it is in the\nproposed updates branch).\n\nIn git.git working tree, here is what happens:\n\n\t$ git checkout pu\t\t\t;# start from pu\n        $ cd Documentation\n        $ echo >>git-daemon.txt\t\t\t;# smudge\n        $ git checkout -- git-daemon.txt\t;# restore\n\t$ git diff -r --name-status\t\t;# no change\n        $ git checkout master git-daemon.txt\t;# pick from tree\n\t$ git diff master -r --name-status\t;# (1)\n\t$ git diff -r --name-status\t\t;# (2)\n\t$ git diff pu -r --name-status          ;# (3)\n        M\tDocumentation/git-daemon.txt\n\n    (1) does not show any because it did take the file out of master\n        branch, and git-daemon.txt is the only file different under\n        Documentation/ between master and pu.\n\n    (2) does not show any because \"checkout master git-daemon.txt\"\n        updated the path both in index and working tree.\n\n    (3) shows the path indeed is different between master and pu.\n\nThe change relies on ls-tree showing full paths regardless of\nwhere it gets started (because the output is fed to --index-info\nform of git-update-index).  If we are going to take the \"ls-tree\nprefix truncation\" patch from Linus, either we also need to\nupdate \"git-update-index --index-info\" to match this.\n"}]}