8000 ssh: Omit port option from ssh command unless specified in remote url · libgit2/libgit2@35dccc3 · GitHub
[go: up one dir, main page]

Skip to content

Commit 35dccc3

Browse files
committed
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.
1 parent 2ecc858 commit 35dccc3

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/libgit2/transports/ssh_exec.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ static int get_ssh_cmdline(
131131
git_str ssh_cmd = GIT_STR_INIT;
132132
const char *default_ssh_cmd = "ssh";
133133
int error;
134+
git_str port_str = GIT_STR_INIT;
134135

135136
/*
136137
* Safety check: like git, we forbid paths that look like an
@@ -158,16 +159,20 @@ static int get_ssh_cmdline(
158159
else if ((error = git_config__get_string_buf(&ssh_cmd, cfg, "core.sshcommand")) < 0 && error != GIT_ENOTFOUND)
159160
goto done;
160161

161-
error = git_str_printf(out, "%s -p %s \"%s%s%s\" \"%s\" \"%s\"",
162+
if (url->port_specified && (error = git_str_printf(&port_str, "-p %s", url->port)) < 0)
163+
return error;
164+
165+
error = git_str_printf(out, "%s %s \"%s%s%s\" \"%s\" \"%s\"",
162166
ssh_cmd.size > 0 ? ssh_cmd.ptr : default_ssh_cmd,
163-
url->port,
167+
port_str.ptr,
164168
url->username ? url->username : "",
165169
url->username ? "@" : "",
166170
url->host,
167171
command,
168172
url->path);
169173

170174
done:
175+
git_str_dispose(&port_str);
171176
git_str_dispose(&ssh_cmd);
172177
git_config_free(cfg);
173178
return error;

0 commit comments

Comments
 (0)
0