{"thread":{"id":"51483","subject":"[PATCH 0/1] mingw: support spawning programs with paths containing spacesnames","startedAt":"2019-07-16T14:03:16Z","lastAt":"2019-07-16T14:03:16Z","messageCount":2,"participants":["Johannes Schindelin via GitGitGadget"],"isPatch":true,"patchVersion":1,"patchTotal":1},"messages":[{"id":"378959","messageId":"pull.220.git.gitgitgadget@gmail.com","threadId":"51483","inReplyTo":null,"subject":"[PATCH 0/1] mingw: support spawning programs with paths containing spacesnames","fromName":"Johannes Schindelin via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-07-16T14:03:11Z","receivedAt":"2019-07-16T14:03:16Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"This is a patch to support older Windows versions (e.g. Windows 7) better.\n\nI know, I know, Windows 7's End-Of-Life is now less than half a year away,\nbut... I am unsure just how long Git for Windows will support Windows 7\nbeyond its officially-supported life; We still support Windows Vista, after\nall, which has been \"sun-set\" over two years ago.\n\nJohannes Schindelin (1):\n  mingw: support spawning programs containing spaces in their names\n\n compat/mingw.c         | 8 +++++---\n t/t0061-run-command.sh | 6 ++++++\n 2 files changed, 11 insertions(+), 3 deletions(-)\n\n\nbase-commit: aa25c82427ae70aebf3b8f970f2afd54e9a2a8c6\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-220%2Fdscho%2Fspawn-with-spaces-v1\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-220/dscho/spawn-with-spaces-v1\nPull-Request: https://github.com/gitgitgadget/git/pull/220\n-- \ngitgitgadget\n"},{"id":"378960","messageId":"bc9e45488c27452155e57336354d3e935fbc3c5d.1563285791.git.gitgitgadget@gmail.com","threadId":"51483","inReplyTo":"pull.220.git.gitgitgadget@gmail.com","subject":"[PATCH 1/1] mingw: support spawning programs containing spaces in their names","fromName":"Johannes Schindelin via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-07-16T14:03:12Z","receivedAt":"2019-07-16T14:03:16Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"From: Johannes Schindelin <johannes.schindelin@gmx.de>\n\nOn some older Windows versions (e.g. Windows 7), the CreateProcessW()\nfunction does not really support spaces in its first argument,\nlpApplicationName. But it supports passing NULL as lpApplicationName,\nwhich makes it figure out the application from the (possibly quoted)\nfirst argument of lpCommandLine.\n\nLet's use that trick (if we are certain that the first argument matches\nthe executable's path) to support launching programs whose path contains\nspaces.\n\nWe will abuse the test-fake-ssh.exe helper to verify that this works and\ndoes not regress.\n\nThis fixes https://github.com/git-for-windows/git/issues/692\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n compat/mingw.c         | 8 +++++---\n t/t0061-run-command.sh | 6 ++++++\n 2 files changed, 11 insertions(+), 3 deletions(-)\n\ndiff --git a/compat/mingw.c b/compat/mingw.c\nindex 9b6d2400e1..6d7fc07a48 100644\n--- a/compat/mingw.c\n+++ b/compat/mingw.c\n@@ -1437,7 +1437,9 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen\n \tsi.hStdOutput = winansi_get_osfhandle(fhout);\n \tsi.hStdError = winansi_get_osfhandle(fherr);\n \n-\tif (xutftowcs_path(wcmd, cmd) < 0)\n+\tif (*argv && !strcmp(cmd, *argv))\n+\t\twcmd[0] = L'\\0';\n+\telse if (xutftowcs_path(wcmd, cmd) < 0)\n \t\treturn -1;\n \tif (dir && xutftowcs_path(wdir, dir) < 0)\n \t\treturn -1;\n@@ -1466,8 +1468,8 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen\n \twenvblk = make_environment_block(deltaenv);\n \n \tmemset(&pi, 0, sizeof(pi));\n-\tret = CreateProcessW(wcmd, wargs, NULL, NULL, TRUE, flags,\n-\t\twenvblk, dir ? wdir : NULL, &si, &pi);\n+\tret = CreateProcessW(*wcmd ? wcmd : NULL, wargs, NULL, NULL, TRUE,\n+\t\tflags, wenvblk, dir ? wdir : NULL, &si, &pi);\n \n \tfree(wenvblk);\n \tfree(wargs);\ndiff --git a/t/t0061-run-command.sh b/t/t0061-run-command.sh\nindex ebc49561ac..015fac8b5d 100755\n--- a/t/t0061-run-command.sh\n+++ b/t/t0061-run-command.sh\n@@ -210,4 +210,10 @@ test_expect_success MINGW 'verify curlies are quoted properly' '\n \ttest_cmp expect actual\n '\n \n+test_expect_success MINGW 'can spawn with argv[0] containing spaces' '\n+\tcp \"$GIT_BUILD_DIR/t/helper/test-fake-ssh$X\" ./ &&\n+\ttest_must_fail \"$PWD/test-fake-ssh$X\" 2>err &&\n+\tgrep TRASH_DIRECTORY err\n+'\n+\n test_done\n-- \ngitgitgadget\n"}]}