{"thread":{"id":"51722","subject":"[PATCH 0/3] Handle worktrees at the top of a network drive","startedAt":"2019-08-24T22:10:48Z","lastAt":"2019-08-26T17:08:49Z","messageCount":5,"participants":["Johannes Schindelin via GitGitGadget","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":3},"messages":[{"id":"381075","messageId":"pull.141.git.gitgitgadget@gmail.com","threadId":"51722","inReplyTo":null,"subject":"[PATCH 0/3] Handle worktrees at the top of a network drive","fromName":"Johannes Schindelin via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-08-24T22:10:44Z","receivedAt":"2019-08-24T22:10:48Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Windows' network drive concept is a quite useful and versatile one. Once\nauthenticated, one can even change the working directory to a network drive\n(cd \\\\server\\share, works in PowerShell and Git Bash).\n\nSome users want to have their Git repositories there, and with these\npatches, that works, even.\n\nThis is yet another patch series in the seemingly endless stream of Git for\nWindows patches.\n\nJohannes Schindelin (3):\n  setup_git_directory(): handle UNC paths correctly\n  Fix .git/ discovery at the root of UNC shares\n  setup_git_directory(): handle UNC root paths correctly\n\n setup.c | 10 ++++++++--\n 1 file changed, 8 insertions(+), 2 deletions(-)\n\n\nbase-commit: 8104ec994ea3849a968b4667d072fedd1e688642\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-141%2Fdscho%2Fgitdir-at-unc-root-v1\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-141/dscho/gitdir-at-unc-root-v1\nPull-Request: https://github.com/gitgitgadget/git/pull/141\n-- \ngitgitgadget\n"},{"id":"381076","messageId":"bb29fcd20d3e3f59ed5d65f04148d73770f542b2.1566684643.git.gitgitgadget@gmail.com","threadId":"51722","inReplyTo":"pull.141.git.gitgitgadget@gmail.com","subject":"[PATCH 1/3] setup_git_directory(): handle UNC paths correctly","fromName":"Johannes Schindelin via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-08-24T22:10:44Z","receivedAt":"2019-08-24T22:10:49Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"From: Johannes Schindelin <johannes.schindelin@gmx.de>\n\nThe first offset in a UNC path is not the host name, but the folder name after that.\n\nThis fixes https://github.com/git-for-windows/git/issues/1181\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n setup.c | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/setup.c b/setup.c\nindex ca9e8a949e..a803b3ade3 100644\n--- a/setup.c\n+++ b/setup.c\n@@ -906,7 +906,7 @@ static enum discovery_result setup_git_directory_gently_1(struct strbuf *dir,\n \tconst char *env_ceiling_dirs = getenv(CEILING_DIRECTORIES_ENVIRONMENT);\n \tstruct string_list ceiling_dirs = STRING_LIST_INIT_DUP;\n \tconst char *gitdirenv;\n-\tint ceil_offset = -1, min_offset = has_dos_drive_prefix(dir->buf) ? 3 : 1;\n+\tint ceil_offset = -1, min_offset = offset_1st_component(dir->buf);\n \tdev_t current_device = 0;\n \tint one_filesystem = 1;\n \n-- \ngitgitgadget\n\n"},{"id":"381077","messageId":"e27a58d363c11c941a1e7b921dae8487a9d062df.1566684643.git.gitgitgadget@gmail.com","threadId":"51722","inReplyTo":"pull.141.git.gitgitgadget@gmail.com","subject":"[PATCH 2/3] Fix .git/ discovery at the root of UNC shares","fromName":"Johannes Schindelin via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-08-24T22:10:45Z","receivedAt":"2019-08-24T22:10:51Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"From: Johannes Schindelin <johannes.schindelin@gmx.de>\n\nA very common assumption in Git's source code base is that\noffset_1st_component() returns either 0 for relative paths, or 1 for\nabsolute paths that start with a slash. In other words, the return value\nis either 0 or points just after the dir separator.\n\nThis assumption is not fulfilled when calling offset_1st_component()\ne.g. on UNC paths on Windows, e.g. \"//my-server/my-share\". In this case,\noffset_1st_component() returns the length of the entire string (which is\ncorrect, because stripping the last \"component\" would not result in a\nvalid directory), yet the return value still does not point just after a\ndir separator.\n\nThis assumption is most prominently seen in the\nsetup_git_directory_gently_1() function, where we want to append a\n\".git\" component and simply assume that there is already a dir\nseparator. In the UNC example given above, this assumption is incorrect.\n\nAs a consequence, Git will fail to handle a worktree at the top of a UNC\nshare correctly.\n\nLet's fix this by adding a dir separator specifically for that case: we\nfound that there is no first component in the path and it does not end\nin a dir separator? Then add it.\n\nThis fixes https://github.com/git-for-windows/git/issues/1320\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n setup.c | 6 ++++++\n 1 file changed, 6 insertions(+)\n\ndiff --git a/setup.c b/setup.c\nindex a803b3ade3..3d24de15dd 100644\n--- a/setup.c\n+++ b/setup.c\n@@ -934,6 +934,12 @@ static enum discovery_result setup_git_directory_gently_1(struct strbuf *dir,\n \tif (ceil_offset < 0)\n \t\tceil_offset = min_offset - 2;\n \n+\tif (min_offset && min_offset == dir->len &&\n+\t    !is_dir_sep(dir->buf[min_offset - 1])) {\n+\t\tstrbuf_addch(dir, '/');\n+\t\tmin_offset++;\n+\t}\n+\n \t/*\n \t * Test in the following order (relative to the dir):\n \t * - .git (file containing \"gitdir: <path>\")\n-- \ngitgitgadget\n\n"},{"id":"381078","messageId":"80b5535dc096a6ce0efac5aa4adf7a933fc22062.1566684643.git.gitgitgadget@gmail.com","threadId":"51722","inReplyTo":"pull.141.git.gitgitgadget@gmail.com","subject":"[PATCH 3/3] setup_git_directory(): handle UNC root paths correctly","fromName":"Johannes Schindelin via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-08-24T22:10:46Z","receivedAt":"2019-08-24T22:10:51Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"From: Johannes Schindelin <johannes.schindelin@gmx.de>\n\nWhen working in the root directory of a file share (this is only\npossible in Git Bash and Powershell, but not in CMD), the current\ndirectory is reported without a trailing slash.\n\nThis is different from Unix and standard Windows directories: both / and\nC:\\ are reported with a trailing slash as current directories.\n\nIf a Git worktree is located there, Git is not quite prepared for that:\nwhile it does manage to find the .git directory/file, it returns as\nlength of the top-level directory's path *one more* than the length of\nthe current directory, and setup_git_directory_gently() would then\nreturn an undefined string as prefix.\n\nIn practice, this undefined string usually points to NUL bytes, and does\nnot cause much harm. Under rare circumstances that are really involved\nto reproduce (and not reliably so), the reported prefix could be a\nsuffix string of Git's exec path, though.\n\nA careful analysis determined that this bug is unlikely to be\nexploitable, therefore we mark this as a regular bug fix.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n setup.c | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/setup.c b/setup.c\nindex 3d24de15dd..c8c6bf3f49 100644\n--- a/setup.c\n+++ b/setup.c\n@@ -784,7 +784,7 @@ static const char *setup_discovered_git_dir(const char *gitdir,\n \t\tset_git_dir(gitdir);\n \tinside_git_dir = 0;\n \tinside_work_tree = 1;\n-\tif (offset == cwd->len)\n+\tif (offset >= cwd->len)\n \t\treturn NULL;\n \n \t/* Make \"offset\" point past the '/' (already the case for root dirs) */\n-- \ngitgitgadget\n"},{"id":"381215","messageId":"xmqq36hnj1lv.fsf@gitster-ct.c.googlers.com","threadId":"51722","inReplyTo":"pull.141.git.gitgitgadget@gmail.com","subject":"Re: [PATCH 0/3] Handle worktrees at the top of a network drive","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2019-08-26T17:08:44Z","receivedAt":"2019-08-26T17:08:49Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Johannes Schindelin via GitGitGadget\" <gitgitgadget@gmail.com>\nwrites:\n\n> Windows' network drive concept is a quite useful and versatile one. Once\n> authenticated, one can even change the working directory to a network drive\n> (cd \\\\server\\share, works in PowerShell and Git Bash).\n>\n> Some users want to have their Git repositories there, and with these\n> patches, that works, even.\n\nOK.  I see too many 'even' (iow, if it walks and quacks like any\nother directory, it should be able to house a Git repository, so to\nme it does not even deserve 'it even works'), but that's probably\njust me.\n\nQueued.  Thanks.\n\n> This is yet another patch series in the seemingly endless stream of Git for\n> Windows patches.\n>\n> Johannes Schindelin (3):\n>   setup_git_directory(): handle UNC paths correctly\n>   Fix .git/ discovery at the root of UNC shares\n>   setup_git_directory(): handle UNC root paths correctly\n>\n>  setup.c | 10 ++++++++--\n>  1 file changed, 8 insertions(+), 2 deletions(-)\n>\n>\n> base-commit: 8104ec994ea3849a968b4667d072fedd1e688642\n> Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-141%2Fdscho%2Fgitdir-at-unc-root-v1\n> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-141/dscho/gitdir-at-unc-root-v1\n> Pull-Request: https://github.com/gitgitgadget/git/pull/141\n"}]}