summaryrefslogtreecommitdiff
path: root/compat/mingw.c
diff options
context:
space:
mode:
authorLibravatar Johannes Schindelin <johannes.schindelin@gmx.de>2022-01-19 18:56:01 +0000
committerLibravatar Junio C Hamano <gitster@pobox.com>2022-01-19 11:27:31 -0800
commite2724c1ed1ca2605de6cf885bcfc4d512e93a537 (patch)
tree7d3815815c4c8d2ce4e88930b9bcc071c40e9e0a /compat/mingw.c
parentMerge branch 'js/branch-track-inherit' (diff)
downloadtgif-e2724c1ed1ca2605de6cf885bcfc4d512e93a537.tar.xz
getcwd(mingw): handle the case when there is no cwd
A recent upstream topic introduced checks for certain Git commands that prevent them from deleting the current working directory, introducing also a regression test that ensures that commands such as `git version` _can_ run without a current working directory. While technically not possible on Windows via the regular Win32 API, we do run the regression tests in an MSYS2 Bash which uses a POSIX emulation layer (the MSYS2/Cygwin runtime) where a really evil hack _does_ allow to delete a directory even if it is the current working directory. Therefore, Git needs to be prepared for a missing working directory, even on Windows. This issue was not noticed in upstream Git because there was no caller that tried to discover a Git directory with a deleted current working directory in the test suite. But in the microsoft/git fork, we do want to run `pre-command`/`post-command` hooks for every command, even for `git version`, which means that we make precisely such a call. The bug is not in that `pre-command`/`post-command` feature, though, but in `mingw_getcwd()` and needs to be addressed there. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'compat/mingw.c')
-rw-r--r--compat/mingw.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/compat/mingw.c b/compat/mingw.c
index 640dcb11de..03af369b2b 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -1127,6 +1127,10 @@ char *mingw_getcwd(char *pointer, int len)
}
if (!ret || ret >= ARRAY_SIZE(wpointer))
return NULL;
+ if (GetFileAttributesW(wpointer) == INVALID_FILE_ATTRIBUTES) {
+ errno = ENOENT;
+ return NULL;
+ }
if (xwcstoutf(pointer, wpointer, len) < 0)
return NULL;
convert_slashes(pointer);