Skip to content

Commit e2724c1

Browse files
dschogitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent af4e5f5 commit e2724c1

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

compat/mingw.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,6 +1127,10 @@ char *mingw_getcwd(char *pointer, int len)
11271127
}
11281128
if (!ret || ret >= ARRAY_SIZE(wpointer))
11291129
return NULL;
1130+
if (GetFileAttributesW(wpointer) == INVALID_FILE_ATTRIBUTES) {
1131+
errno = ENOENT;
1132+
return NULL;
1133+
}
11301134
if (xwcstoutf(pointer, wpointer, len) < 0)
11311135
return NULL;
11321136
convert_slashes(pointer);

0 commit comments

Comments
 (0)