{"thread":{"id":"47109","subject":"[PATCH] setup: avoid double slashes when looking for HEAD","startedAt":"2017-11-03T12:58:33Z","lastAt":"2017-11-03T18:38:46Z","messageCount":2,"participants":["Johannes Schindelin","Jeff King"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"331775","messageId":"9322728aaa3010c0b71574eb5876548487d66885.1509713589.git.johannes.schindelin@gmx.de","threadId":"47109","inReplyTo":null,"subject":"[PATCH] setup: avoid double slashes when looking for HEAD","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2017-11-03T12:58:02Z","receivedAt":"2017-11-03T12:58:33Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"From: Jeff King <peff@peff.net>\n\nAndrew Baumann reported that when called outside of any Git worktree,\n`git rev-parse --is-inside-work-tree` eventually tries to access\n`//HEAD`, i.e.  any `HEAD` file in the root directory, but with a double\nslash.\n\nThis double slash is not only unintentional, but is allowed by the POSIX\nstandard to have a special meaning. And most notably on Windows, it\ndoes, where it refers to a UNC path of the form `//server/share/`.\n\nAs a consequence, afore-mentioned `rev-parse` call not only looks for\nthe wrong thing, but it also causes serious delays, as Windows will try\nto access a server called `HEAD`.  Let's simply avoid the unintended\ndouble slash.\n\nSigned-off-by: Jeff King <peff@peff.net>\nAcked-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\nPublished-As: https://github.com/dscho/git/releases/tag/double-slash-HEAD-v1\nFetch-It-Via: git fetch https://github.com/dscho/git double-slash-HEAD-v1\n\n\tAnd here it is, as a proper, easy-to-pull branch, and also in the\n\tform Junio prefers.\n\n setup.c | 4 +++-\n 1 file changed, 3 insertions(+), 1 deletion(-)\n\ndiff --git a/setup.c b/setup.c\nindex 03f51e056cd..94768512b79 100644\n--- a/setup.c\n+++ b/setup.c\n@@ -312,7 +312,9 @@ int is_git_directory(const char *suspect)\n \tsize_t len;\n \n \t/* Check worktree-related signatures */\n-\tstrbuf_addf(&path, \"%s/HEAD\", suspect);\n+\tstrbuf_addstr(&path, suspect);\n+\tstrbuf_complete(&path, '/');\n+\tstrbuf_addstr(&path, \"HEAD\");\n \tif (validate_headref(path.buf))\n \t\tgoto done;\n \n\nbase-commit: cb5918aa0d50f50e83787f65c2ddc3dcb10159fe\n-- \n2.15.0.windows.1\n"},{"id":"331797","messageId":"20171103183836.zpsspuj2xbufuu7u@sigill.intra.peff.net","threadId":"47109","inReplyTo":"9322728aaa3010c0b71574eb5876548487d66885.1509713589.git.johannes.schindelin@gmx.de","subject":"Re: [PATCH] setup: avoid double slashes when looking for HEAD","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2017-11-03T18:38:36Z","receivedAt":"2017-11-03T18:38:46Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Fri, Nov 03, 2017 at 01:58:02PM +0100, Johannes Schindelin wrote:\n\n> From: Jeff King <peff@peff.net>\n> \n> Andrew Baumann reported that when called outside of any Git worktree,\n> `git rev-parse --is-inside-work-tree` eventually tries to access\n> `//HEAD`, i.e.  any `HEAD` file in the root directory, but with a double\n> slash.\n> \n> This double slash is not only unintentional, but is allowed by the POSIX\n> standard to have a special meaning. And most notably on Windows, it\n> does, where it refers to a UNC path of the form `//server/share/`.\n> \n> As a consequence, afore-mentioned `rev-parse` call not only looks for\n> the wrong thing, but it also causes serious delays, as Windows will try\n> to access a server called `HEAD`.  Let's simply avoid the unintended\n> double slash.\n> \n> Signed-off-by: Jeff King <peff@peff.net>\n> Acked-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n\nThanks, this explanation looks good to me (and the patch is flawless, of\ncourse ;) ).\n\n-Peff\n"}]}