Skip to content

lfsapi: handle SSH hostnames and aliases without users - #3230

Merged
bk2204 merged 1 commit into
git-lfs:masterfrom
bk2204:ssh-shorthands
Sep 6, 2018
Merged

bk2204 merged 1 commit into
git-lfs:masterfrom
bk2204:ssh-shorthands

Conversation

@bk2204

@bk2204 bk2204 commented Sep 5, 2018

Copy link
Copy Markdown
Member

It's very common for a user to specify an SSH remote that refers to an
alias in their gitconfig file. For example, if a user must use
different SSH keys when pushing to different remotes, setting different
aliases that use those different keys is the simplest and easiest way to
accomplish that goal.

Unfortunately, our parsing logic was broken for SSH remotes that used
bare SSH URLs (that is, without “ssh://”) with a hostname or alias, but
without a username component. The URL parser we used saw the hostname
portion as the scheme of a URL, and we passed through any URLs with
unknown schemes. This led to a failure to push, since we misparsed the
URL as a non-SSH URL and gave up when it also didn't look like an
HTTP(S) URL.

If we get an unknown “scheme” when parsing a URL, check if the URL uses a
remote helper (that is, it contains a double colon), and pass it
through. Otherwise, do what Git does, and assume the URL is in fact an
SSH URL, and handle it accordingly.

We already handle the url.insteadof syntax properly, even if it looks
like a scheme. Add tests that we continue to do so, and for the new
code and all the various permutations mentioned above.

This should fix #278 and also fix #2842.

@ttaylorr ttaylorr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✨ This looks great, @bk2204.

I left one nit, but you're more than free to ignore it:

Comment thread lfsapi/endpoint_finder.go Resolved
@ttaylorr

ttaylorr commented Sep 6, 2018

Copy link
Copy Markdown
Contributor

✨ This looks great, @bk2204.

Thanks also for the detailed walkthrough of what's going on and how the changes works. I've always been somewhat wary of changing this part of the code, so your detailed message helped me build confidence that my understanding was correct.

It's very common for a user to specify an SSH remote that refers to an
alias in their gitconfig file.  For example, if a user must use
different SSH keys when pushing to different remotes, setting different
aliases that use those different keys is the simplest and easiest way to
accomplish that goal.

Unfortunately, our parsing logic was broken for SSH remotes that used
bare SSH URLs (that is, without “ssh://”) with a hostname or alias, but
without a username component.  The URL parser we used saw the hostname
portion as the scheme of a URL, and we passed through any URLs with
unknown schemes.  This led to a failure to push, since we misparsed the
URL as a non-SSH URL and gave up when it also didn't look like an
HTTP(S) URL.

If we get an unknown “scheme” when parsing a URL, check if the URL uses
a remote helper (that is, it contains a double colon), and pass it
through.  Otherwise, do what Git does, and assume the URL is in fact an
SSH URL, and handle it accordingly.

We already handle the url.insteadof syntax properly, even if it looks
like a scheme.  Add tests that we continue to do so, and for the new
code and all the various permutations mentioned above, and update the
existing integration test to reflect our new parsing strategy.
@bk2204
bk2204 merged commit b25cf00 into git-lfs:master Sep 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cannot clone with non-default SSH key Using SSH shorthands as git remote should work the same as a full hostname

2 participants