ssh: Omit port option from ssh command unless specified in remote url

Omit `-p 22` option from ssh command by default.
Adding `-p 22` option when a port is not in a remote url causes that
`Port` option in a ssh config is ignored.
This commit is contained in:
Jaeyong Choi
2024-07-04 10:49:34 +09:00
parent 2ecc8586f7
commit d2389b2caa

View File

@@ -158,9 +158,10 @@ static int get_ssh_cmdline(
else if ((error = git_config__get_string_buf(&ssh_cmd, cfg, "core.sshcommand")) < 0 && error != GIT_ENOTFOUND)
goto done;
error = git_str_printf(out, "%s -p %s \"%s%s%s\" \"%s\" \"%s\"",
error = git_str_printf(out, "%s %s %s \"%s%s%s\" \"%s\" \"%s\"",
ssh_cmd.size > 0 ? ssh_cmd.ptr : default_ssh_cmd,
url->port,
url->port_specified ? "-p" : "",
url->port_specified ? url->port : "",
url->username ? url->username : "",
url->username ? "@" : "",
url->host,