[PATCH v3 05/20] mingw: prepare the TMPDIR environment variable for shell scripts
- From
Johannes Schindelin <johannes.schindelin@gmx.de>
- Date
- Jan 27, 2016, 16:19 UTC
- Message-ID
- <99caadcf6af5619988792b47b50d70b691d355c3.1453911367.git.johannes.schindelin@gmx.de>
- In-Reply-To
- <cover.1453911367.git.johannes.schindelin@gmx.de>
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 <johannes.schindelin@gmx.de> --- compat/mingw.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-)
diff --git a/compat/mingw.c b/compat/mingw.c index 8d52c73..ba5cb1c 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -2049,13 +2049,28 @@ int xwcstoutf(char *utf, const wchar_t *wcs, size_t utflen) static void setup_windows_environment() { + char *tmp = getenv("TMPDIR"); + /* on Windows it is TMP and TEMP */ - if (!getenv("TMPDIR")) { - const char *tmp = getenv("TMP"); - if (!tmp) + if (!tmp) { + if (!(tmp = getenv("TMP"))) tmp = getenv("TEMP"); - if (tmp) + if (tmp) { setenv("TMPDIR", tmp, 1); + tmp = getenv("TMPDIR"); + } + } + + if (tmp) { + /* + * Convert all dir separators to forward slashes, + * to help shell commands called from the Git + * executable (by not mistaking the dir separators + * for escape characters). + */ + for (; *tmp; tmp++) + if (*tmp == '\\') + *tmp = '/'; } /* simulate TERM to enable auto-color (see color.c) */
-- 2.7.0.windows.1.7.g55a05c8