{"thread":{"id":"57416","subject":"Quoting of paths when pushing to Windows over SSH","startedAt":"2022-02-15T18:15:42Z","lastAt":"2022-02-15T18:15:42Z","messageCount":1,"participants":["Ben Boeckel"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"448470","messageId":"YgvtwEPMCH3974e7@erythro.dev.benboeckel.internal","threadId":"57416","inReplyTo":null,"subject":"Quoting of paths when pushing to Windows over SSH","fromName":"Ben Boeckel","fromEmail":"mathstuf@gmail.com","sentAt":"2022-02-15T18:15:28Z","receivedAt":"2022-02-15T18:15:42Z","isPatch":false,"sender":{"key":"mathstuf@gmail.com","avatar":"https://avatars.githubusercontent.com/u/97253?v=4"},"body":"Hi,\n\nIt seems that some quoting when creating the SSH command line for the\nSSH transport needs some extra logic to handle remote hosts which are\nnot using POSIX shells (namely `cmd`). With the Windows \"Enable SSH\nServer\" built-in feature, it ends up failing with this being attempted\n(as reported by `GIT_TRACE=2`):\n\n    run_command: unset GIT_PREFIX; GIT_PROTOCOL=version=2 ssh -o SendEnv=GIT_PROTOCOL hostname 'C:/Progra~1/Git/mingw64/libexec/git-core/git-receive-pack.exe '\\''remote/path'\\'''\n\nOf note here:\n\n  - I could not figure out a way to have a path with a space for\n    `git-receive-pack` (it just kept saying `C:\\Program` is not a\n    program regardless of what kinds of quoting I tried), but DOS\n    shortnames suffice here at least.\n  - the remote path is single-quoted which is not stripped on the other\n    side, so the error that `'remote/path'` does not exist ends up\n    happening.\n\nI do *not* want to change the default shell on the other side because it\nis actually useful to be `cmd` in this instance (for `vcvarsall.bat`\nnamely) when logging in manually. Some potential solutions:\n\n  - a way to set the shell to use on the remote for ssh command;\n  - a way to say \"use double quotes, not single quotes\" (or some other\n    way to tell `sq_*` that we're not talking to POSIX on the other\n    side).\n\nI was able to move forward for now with this patch that I'm using in a\nspecific build to talk to this remote (on top of 2.34.1) because I know\nI don't have any special characters in my instance:\n\ndiff --git a/connect.c b/connect.c\nindex eaf7d6d261..a286feb812 100644\n--- a/connect.c\n+++ b/connect.c\n@@ -1393,7 +1393,7 @@ struct child_process *git_connect(int fd[2], const char *url,\n \n                strbuf_addstr(&cmd, prog);\n                strbuf_addch(&cmd, ' ');\n-               sq_quote_buf(&cmd, path);\n+               strbuf_addstr(&cmd, path);\n \n                /* remove repo-local variables from the environment */\n                for (var = local_repo_env; *var; var++)\n\nWhat might be the best way of making this work more widely?\n\n--Ben\n"}]}