Skip to content

Commit 1fc7bf7

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

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
@@ -2046,13 +2046,28 @@ int xwcstoutf(char *utf, const wchar_t *wcs, size_t utflen)
20462046

20472047
static void setup_windows_environment()
20482048
{
2049+
char *tmp = getenv("TMPDIR");
2050+
20492051
/* on Windows it is TMP and TEMP */
2050-
if (!getenv("TMPDIR")) {
2051-
const char *tmp = getenv("TMP");
2052-
if (!tmp)
2052+
if (!tmp) {
2053+
if (!(tmp = getenv("TMP")))
20532054
tmp = getenv("TEMP");
2054-
if (tmp)
2055+
if (tmp) {
20552056
setenv("TMPDIR", tmp, 1);
2057+
tmp = getenv("TMPDIR");
2058+
}
2059+
}
2060+
2061+
if (tmp) {
2062+
/*
2063+
* Convert all dir separators to forward slashes,
2064+
* to help shell commands called from the Git
2065+
* executable (by not mistaking the dir separators
2066+
* for escape characters).
2067+
*/
2068+
for (; *tmp; tmp++)
2069+
if (*tmp == '\\')
2070+
*tmp = '/';
20562071
}
20572072

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

0 commit comments

Comments
 (0)