git: Handle scp-style git addresses in detector, not getter #180
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The "scp-style" remote URL scheme in git is ambiguous with the standard URL syntax in our previous design where we'd add/accept the
ssh://
prefix in both cases;ssh://git@example.com:222/foo
could be understood as either of the following:example.com
on port 222 and clone from pathfoo
example.com
on port 22 and clone from path222/foo
Originally we used the first interpretation. but in #129 we switched to the second in order to support a strange hybrid form where the
ssh://
prefix could introduce scp-like form, but in the process we broke handling of the standard URL form when a non-standard port is required, as is sometimes the case for internal git servers running on machines where port 22 is already used for administrative access.git itself resolves this ambiguity by not permitting the
ssh://
scheme to be used in conjunction with the scp-like form. Here we'll now mimic that by supporting the scp-like form only in the detector, and only allowing it when thessh://
prefix isn't present. That allows for the following two scp-like forms to be accepted:git@example.com:foo/bar
when the username is "git", as seems common in various git server solutionsgit::anything@example.com:foo/bar
for any usernameWe no longer support using the scp-like form with the ssh:// prefix, so
git::ssh://anything.example.com:foo/bar
is invalid. To use that form, thessh://
part must be omitted, which is consistent with git's own behavior. This is a breaking change togo-getter
for scp-like addresses with the scheme and no port number, though.The detector already rewrites the scp-like form into the standard URL form when no
ssh:
scheme is given, so the getter does not need to do anything special to deal with it.In the git getter, we now also check to see if the port number seems to be non-decimal and return a more actionable error if so, since that is likely to be caused by someone incorrectly using the
ssh://
scheme with a scp-style address. Explicitly prohibiting that ambiguous form seems better than breaking the ability to use non-standard port numbers.This is for hashicorp/terraform#21257. As we vendor this fix into Terraform we'll also need to update its module sources documentation, which is largely a description of go-getter's behavior. Any other application that supports installing from git using
go-getter
will probably need to make similar documentation changes, as well as recording this as a breaking change.