Skip to content

Commit ac2aa32

Browse files
committed
mingw: prepare the TMPDIR environment variable for shell scripts
When shell scripts access a $TMPDIR variable containing backslashes, they will be mistaken for escape characters. Let's not let that happen by converting them to forward slashes. This partially fixes t7800 with MSYS2. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent c210331 commit ac2aa32

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

compat/mingw.c

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2049,13 +2049,28 @@ int xwcstoutf(char *utf, const wchar_t *wcs, size_t utflen)
20492049

20502050
static void setup_windows_environment()
20512051
{
2052+
char *tmp = getenv("TMPDIR");
2053+
20522054
/* on Windows it is TMP and TEMP */
2053-
if (!getenv("TMPDIR")) {
2054-
const char *tmp = getenv("TMP");
2055-
if (!tmp)
2055+
if (!tmp) {
2056+
if (!(tmp = getenv("TMP")))
20562057
tmp = getenv("TEMP");
2057-
if (tmp)
2058+
if (tmp) {
20582059
setenv("TMPDIR", tmp, 1);
2060+
tmp = getenv("TMPDIR");
2061+
}
2062+
}
2063+
2064+
if (tmp) {
2065+
/*
2066+
* Convert all dir separators to forward slashes,
2067+
* to help shell commands called from the Git
2068+
* executable (by not mistaking the dir separators
2069+
* for escape characters).
2070+
*/
2071+
for (; *tmp; tmp++)
2072+
if (*tmp == '\\')
2073+
*tmp = '/';
20592074
}
20602075

20612076
/* simulate TERM to enable auto-color (see color.c) */

0 commit comments

Comments
 (0)