Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
ethomson merged 1 commit intolibgit2:mainfromjayong93:no-default-ssh-port
Sep 22, 2024

Conversation

jayong93
Copy link
Contributor

@jayong93jayong93 commentedJul 6, 2024
edited
Loading

Currently, when usingGIT_SSH_EXEC feature,libgit2 doen't respect aPort config in ssh config because it always insert-p 22 option to a ssh command if there is no port value in a git remote url (e.g.git@my-custom-domain.org:user/path). I've experienced this for my company's GHE.

One caveat of this implementation is that if you specify port22 in a remote url despite a different port in ssh config, it will be ignored.
For example, in~/.ssh/config:

Host my-custom-domain.org  Port 1234

and if you try to fetch or push with a remote urlssh://git@my-custom-domain.org:22/user/path, the port1234 will be used.
It would be unlikely someone tries to do this though, I guess.

EDITED:
Now-p <port> option is added only when the port is specified in a remote url.

@ethomson
Copy link
Member

One caveat of this implementation is that if you specify port 22 in a remote url despite a different port in ssh config, it will be ignored.

Yeah, you're right. Looking at git, they specify-p <num> if and only if the port number is specified in the URL. IOW,ssh://host/path will honorPort in the config, whilessh://host:22/port will add-p 22 to the command-line to override that.

I added#6851 so that we could discern that as well. Does that make sense in this regard and can you check whether the port was specifically provided using that?

jayong93 reacted with thumbs up emoji

@jayong93
Copy link
ContributorAuthor

Yeah, you're right. Looking at git, they specify-p <num> if and only if the port number is specified in the URL. IOW,ssh://host/path will honorPort in the config, whilessh://host:22/port will add-p 22 to the command-line to override that.

I added#6851 so that we could discern that as well. Does that make sense in this regard and can you check whether the port was specifically provided using that?

That is what I wanted. I'll rebase this PR on#6851 and using that to check whether we should add-p option or not. Thank you!

@jayong93jayong93force-pushed theno-default-ssh-port branch 3 times, most recently from35dccc3 toce1d2c0CompareJuly 15, 2024 05:47
Copy link
Member

@ethomsonethomson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Sorry; I didn't notice that you'd pushed an update. One thing I notice is that I think that we can avoid an allocation of theport_str

@@ -131,6 +131,7 @@ static int get_ssh_cmdline(
git_str ssh_cmd = GIT_STR_INIT;
const char *default_ssh_cmd = "ssh";
int error;
git_str port_str = GIT_STR_INIT;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
git_str port_str = GIT_STR_INIT;

url->username ? url->username : "",
url->username ? "@" : "",
url->host,
command,
url->path);

done:
git_str_dispose(&port_str);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
git_str_dispose(&port_str);

Comment on lines 162 to 164
if (url->port_specified && (error = git_str_printf(&port_str, "-p %s", url->port)) < 0)
goto done;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
if (url->port_specified&& (error=git_str_printf(&port_str,"-p %s",url->port))<0)
gotodone;

ssh_cmd.size > 0 ? ssh_cmd.ptr : default_ssh_cmd,
url->port,
port_str.ptr,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
port_str.ptr,
url->port_specified ?"-p " :"",
url->port_specified ?url->port :"",

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.
@jayong93
Copy link
ContributorAuthor

@ethomson

Sorry; I didn't notice that you'd pushed an update. One thing I notice is that I think that we can avoid an allocation of the port_str

Right. I've removed the useless allocation.

@ethomsonethomson merged commitcb0bf67 intolibgit2:mainSep 22, 2024
19 checks passed
@ethomson
Copy link
Member

Thanks for the fix! Great improvement.

jayong93 reacted with thumbs up emojijayong93 reacted with heart emoji

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@ethomsonethomsonethomson approved these changes

Assignees
No one assigned
Labels
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@jayong93@ethomson

[8]ページ先頭

©2009-2025 Movatter.jp