{"thread":{"id":"2225","subject":"git status and commit from subdirectory?","startedAt":"2005-10-25T21:51:54Z","lastAt":"2005-10-26T00:16:56Z","messageCount":2,"participants":["Daniel Barkalow","Linus Torvalds"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"10615","messageId":"Pine.LNX.4.64.0510251735500.25300@iabervon.org","threadId":"2225","inReplyTo":null,"subject":"git status and commit from subdirectory?","fromName":"Daniel Barkalow","fromEmail":"barkalow@iabervon.org","sentAt":"2005-10-25T21:51:54Z","receivedAt":"2005-10-25T21:51:54Z","isPatch":false,"sender":{"key":"barkalow@iabervon.org","avatar":"https://avatars.githubusercontent.com/u/55364219?v=4"},"body":"It seems like everything that \"git status\" does can now be done from a \nsubdirectory (giving, of course, the status of the contents of the \nsubdirectory). I think the same might be true of \"git commit\", but I \nhaven't checked on everything. Is there anything that has to be done to \nenable this properly other than removing the \"|| die\" part of the first \nline?\n\n\t-Daniel\n*This .sig left intentionally blank*\n"},{"id":"10633","messageId":"Pine.LNX.4.64.0510251644090.10477@g5.osdl.org","threadId":"2225","inReplyTo":"Pine.LNX.4.64.0510251735500.25300@iabervon.org","subject":"Re: git status and commit from subdirectory?","fromName":"Linus Torvalds","fromEmail":"torvalds@osdl.org","sentAt":"2005-10-26T00:16:56Z","receivedAt":"2005-10-26T00:16:56Z","isPatch":false,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\n\nOn Tue, 25 Oct 2005, Daniel Barkalow wrote:\n>\n> It seems like everything that \"git status\" does can now be done from a \n> subdirectory (giving, of course, the status of the contents of the \n> subdirectory). I think the same might be true of \"git commit\", but I \n> haven't checked on everything. Is there anything that has to be done to \n> enable this properly other than removing the \"|| die\" part of the first \n> line?\n\nThis patch _may_ work. I've not tested it a lot. Surprise surprise.\n\nNOTE! This has some seriously far-reaching implications. One of them is \nthat a few programs will automagically start working inside some random \ndirectories.\n\nAnd probably others won't. Instead of saying \"Not a git archive\", they \nmight run and do strange things.\n\nThe patch is definitely a big step in the right direction: it makes the \nshell scripts that include \"git-sh-setup\" act a lot more like the programs \nthat automatically find the git directory. But everybody that includes \ngit-sh-setup should be verified.\n\nThis fixes gitk to also work the same way, btw.\n\nTesting needed. Lots of it.\n\n\t\tLinus\n\n---\ndiff --git a/git-sh-setup.sh b/git-sh-setup.sh\nindex dbb9884..044b0b4 100755\n--- a/git-sh-setup.sh\n+++ b/git-sh-setup.sh\n@@ -3,7 +3,7 @@\n # Set up GIT_DIR and GIT_OBJECT_DIRECTORY\n # and return true if everything looks ok\n #\n-: ${GIT_DIR=.git}\n+: ${GIT_DIR=$(git-rev-parse --git-dir)} || exit\n : ${GIT_OBJECT_DIRECTORY=\"$GIT_DIR/objects\"}\n \n # Having this variable in your environment would break scripts because\ndiff --git a/gitk b/gitk\nindex a9d37d9..a934255 100755\n--- a/gitk\n+++ b/gitk\n@@ -12,7 +12,7 @@ proc gitdir {} {\n     if {[info exists env(GIT_DIR)]} {\n \treturn $env(GIT_DIR)\n     } else {\n-\treturn \".git\"\n+\treturn [exec git-rev-parse --git-dir]\n     }\n }\n \ndiff --git a/setup.c b/setup.c\nindex c487d7e..96085dd 100644\n--- a/setup.c\n+++ b/setup.c\n@@ -53,11 +53,10 @@ const char **get_pathspec(const char *pr\n \tconst char **p;\n \tint prefixlen;\n \n-\tif (!prefix && !entry)\n-\t\treturn NULL;\n-\n \tif (!entry) {\n \t\tstatic const char *spec[2];\n+\t\tif (!prefix || !*prefix)\n+\t\t\treturn NULL;\n \t\tspec[0] = prefix;\n \t\tspec[1] = NULL;\n \t\treturn spec;\n@@ -120,9 +119,19 @@ const char *setup_git_directory(void)\n \n \tif (offset == len)\n \t\treturn NULL;\n-\n \t/* Make \"offset\" point to past the '/', and add a '/' at the end */\n \toffset++;\n+\n+\t/*\n+\t * If we're inside the \".git\" directory, we have an empty prefix\n+\t */\n+\tif (!strncmp(cwd + offset, \".git\", 4)) {\n+\t\tswitch (cwd[offset+4]) {\n+\t\tcase '\\0': case '/':\n+\t\t\treturn \"\";\n+\t\t}\n+\t}\n+\n \tcwd[len++] = '/';\n \tcwd[len] = 0;\n \treturn cwd + offset;\n"}]}