{"thread":{"id":"57270","subject":"[PATCH] getcwd(mingw): handle the case when there is no cwd","startedAt":"2022-01-19T18:56:06Z","lastAt":"2022-01-19T22:40:05Z","messageCount":3,"participants":["Johannes Schindelin via GitGitGadget","Junio C Hamano","Johannes Schindelin"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"446515","messageId":"pull.1120.git.1642618562012.gitgitgadget@gmail.com","threadId":"57270","inReplyTo":null,"subject":"[PATCH] getcwd(mingw): handle the case when there is no cwd","fromName":"Johannes Schindelin via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2022-01-19T18:56:01Z","receivedAt":"2022-01-19T18:56:06Z","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 recent upstream topic introduced checks for certain Git commands that\nprevent them from deleting the current working directory, introducing\nalso a regression test that ensures that commands such as `git version`\n_can_ run without a current working directory.\n\nWhile technically not possible on Windows via the regular Win32 API, we\ndo run the regression tests in an MSYS2 Bash which uses a POSIX\nemulation layer (the MSYS2/Cygwin runtime) where a really evil hack\n_does_ allow to delete a directory even if it is the current working\ndirectory.\n\nTherefore, Git needs to be prepared for a missing working directory,\neven on Windows.\n\nThis issue was not noticed in upstream Git because there was no caller\nthat tried to discover a Git directory with a deleted current working\ndirectory in the test suite. But in the microsoft/git fork, we do want\nto run `pre-command`/`post-command` hooks for every command, even for\n`git version`, which means that we make precisely such a call. The bug\nis not in that `pre-command`/`post-command` feature, though, but in\n`mingw_getcwd()` and needs to be addressed there.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n    getcwd(mingw): handle the case when there is no current working\n    directory\n    \n    The bug fixed by this topic was noticed due to test failures while\n    rebasing Microsoft's fork of Git onto v2.35.0-rc1. It may not be\n    desirable to take it into Git v2.35.0 this late in the -rc phase, even\n    though I do plan on integrating it into Git for Windows v2.35.0\n    [https://github.com/git-for-windows/git/pull/3641].\n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-1120%2Fdscho%2Fmingw-getcwd-without-cwd-v1\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1120/dscho/mingw-getcwd-without-cwd-v1\nPull-Request: https://github.com/gitgitgadget/git/pull/1120\n\n compat/mingw.c | 4 ++++\n 1 file changed, 4 insertions(+)\n\ndiff --git a/compat/mingw.c b/compat/mingw.c\nindex 640dcb11de0..03af369b2b9 100644\n--- a/compat/mingw.c\n+++ b/compat/mingw.c\n@@ -1127,6 +1127,10 @@ char *mingw_getcwd(char *pointer, int len)\n \t}\n \tif (!ret || ret >= ARRAY_SIZE(wpointer))\n \t\treturn NULL;\n+\tif (GetFileAttributesW(wpointer) == INVALID_FILE_ATTRIBUTES) {\n+\t\terrno = ENOENT;\n+\t\treturn NULL;\n+\t}\n \tif (xwcstoutf(pointer, wpointer, len) < 0)\n \t\treturn NULL;\n \tconvert_slashes(pointer);\n\nbase-commit: af4e5f569bc89f356eb34a9373d7f82aca6faa8a\n-- \ngitgitgadget\n"},{"id":"446517","messageId":"xmqqr193mspy.fsf@gitster.g","threadId":"57270","inReplyTo":"pull.1120.git.1642618562012.gitgitgadget@gmail.com","subject":"Re: [PATCH] getcwd(mingw): handle the case when there is no cwd","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2022-01-19T19:27:21Z","receivedAt":"2022-01-19T19:27:30Z","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> While technically not possible on Windows via the regular Win32 API, we\n> do run the regression tests in an MSYS2 Bash which uses a POSIX\n> emulation layer (the MSYS2/Cygwin runtime) where a really evil hack\n> _does_ allow to delete a directory even if it is the current working\n> directory.\n\nWow.  I am not sure if I should frown or smile ;-)\n\n>     The bug fixed by this topic was noticed due to test failures while\n>     rebasing Microsoft's fork of Git onto v2.35.0-rc1. It may not be\n>     desirable to take it into Git v2.35.0 this late in the -rc phase, even\n>     though I do plan on integrating it into Git for Windows v2.35.0\n\nI think we can and should take it in my tree (even direct to\n'master'), as it is very clear it affects nobody other than Windows,\nand even if this has any unintended negative effect, having that\ncommon with \"Git for Windows\" would only help.\n\nThanks.\n"},{"id":"446527","messageId":"nycvar.QRO.7.76.6.2201192339250.2121@tvgsbejvaqbjf.bet","threadId":"57270","inReplyTo":"xmqqr193mspy.fsf@gitster.g","subject":"Re: [PATCH] getcwd(mingw): handle the case when there is no cwd","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2022-01-19T22:39:56Z","receivedAt":"2022-01-19T22:40:05Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Junio,\n\nOn Wed, 19 Jan 2022, Junio C Hamano wrote:\n\n> \"Johannes Schindelin via GitGitGadget\" <gitgitgadget@gmail.com>\n> writes:\n>\n> >     The bug fixed by this topic was noticed due to test failures while\n> >     rebasing Microsoft's fork of Git onto v2.35.0-rc1. It may not be\n> >     desirable to take it into Git v2.35.0 this late in the -rc phase, even\n> >     though I do plan on integrating it into Git for Windows v2.35.0\n>\n> I think we can and should take it in my tree (even direct to\n> 'master'), as it is very clear it affects nobody other than Windows,\n> and even if this has any unintended negative effect, having that\n> common with \"Git for Windows\" would only help.\n\nThank you!\nDscho\n"}]}