Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Include port in GitRemote origin #4393

Merged
merged 2 commits into from
Aug 7, 2024

Conversation

bryceatmoderne
Copy link
Contributor

@bryceatmoderne bryceatmoderne commented Aug 7, 2024

What's changed?

Update GitRemote to include port in origin.

What's your motivation?

Host port is required to avoid ambiguity between origins.

Anything in particular you'd like reviewers to focus on?

No

Anyone you would like to review specifically?

@pstreef

Have you considered any alternatives or workarounds?

No

Any additional context

No

Checklist

  • I've added unit tests to cover both positive and negative cases
  • I've read and applied the recipe conventions and best practices
  • I've used the IntelliJ IDEA auto-formatter on affected files

@bryceatmoderne bryceatmoderne requested a review from pstreef August 7, 2024 15:56
@bryceatmoderne bryceatmoderne self-assigned this Aug 7, 2024
@bryceatmoderne bryceatmoderne added the bug Something isn't working label Aug 7, 2024
@@ -170,6 +178,7 @@ private String repositoryPath(@Nullable String origin) {
throw new IllegalArgumentException("Unable to find origin '" + origin + "' in '" + hostAndPath + "'");
}
return hostAndPath.substring(origin.length())
.replaceFirst("^:\\d+", "")
Copy link
Contributor

Choose a reason for hiding this comment

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

why would this be needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It strips out the port number when creating the repository path. The port number is present because we first built hostAndPath then take a substring of it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, you're right. This should not be required through I have to update GitRemote.Parser#parse to cache host + port as the origin

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I updated registerRemote to cache origins with their port number if present. I also added gitlab.com:22 to the list of known origins. I'm not sure if gitlab is special and if we should include origins with :22 and :443 for github and bitbucket as well. I figure this would only be relevant for on-prem installs?

Copy link
Contributor

Choose a reason for hiding this comment

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

Personally, I find these all as the same SCM origin given the current logic:

https://github.com
https://github.com:443
ssh://[email protected]
ssh://[email protected]:22

With both of the port style URLs above, they are just declaring explicitly the default port. Declaring the port is optional, however, when there is a well established default value for the proticol. So to me they all refer to the same origin as GitRemote isn't drawing any distinction between protocols/ports at the moment.

Now if you wanted protocol to be a part of the GitRemote spec, then I'd say the above maps into two -- HTTPS and SSH remotes -- but the presence of absence of the default port doesn't create a new origin.

Copy link
Contributor

Choose a reason for hiding this comment

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

hmm I think you are right and we should ignore explicit default port values.

Adding the protocol into the mix would make it "more correct/complete" but the problem it solves is such a niche (2 servers on different protocols on their default ports) that it's probably not worth it.

@bryceatmoderne bryceatmoderne merged commit d028592 into main Aug 7, 2024
2 checks passed
@bryceatmoderne bryceatmoderne deleted the fix/include-port-git-remote-origin branch August 7, 2024 18:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants