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

internal: url, support more scp-like URLs #324

Closed
wants to merge 4 commits into from

Conversation

loderunner
Copy link

SCP-like URLs do not necessarily need to have a prefix followed by a / in the path.

For example, if a git repository is located at /test-repo.git on a remote, the following command is valid.

git clone user@remote:/test-repo.git

As long as user can use SSH to log into the remote (which might be described in SSH config), git will attempt to clone the repo at the given path.


I removed the / as separator for the port as it interfered with this URL scheme, but I might have missed the rationale for this. Feel free to explain, and I will update the PR accordingly.

@mcuadros
Copy link
Member

mcuadros commented Jun 1, 2021

can you take a look to the testS?

@loderunner
Copy link
Author

loderunner commented Jun 1, 2021

I rewrote some things in the tests.

  • Fixed the regex to support port number in scp-like URL better
  • Fixed the regex to support root paths better
  • Fixed an assertion in internal/url/url_test.go
  • Changed a test in plumbing/transport/common_test.go

I tried my best, but I'm worried about breaking compatibility, here.

Investigating a bit deeper, I found that git does not support port numbers in SCP-like URLs.

On github (connection should be refused):

$ git clone git@github.com:2222:loderunner/go-git.git
Cloning into 'go-git'...
fatal: remote error:
   is not a valid repository name
  Visit https://support.github.com/ for help

With scrt.test defined as 127.0.0.1 in /etc/hosts:

$ git clone scrt@scrt.test:2222:repos/toto.git
Cloning into 'toto'...
ssh: connect to host scrt.test port 22: Connection refused
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
$ git clone scrt@127.0.0.1:2222:repos/toto.git
Cloning into 'toto'...
ssh: connect to host 127.0.0.1 port 22: Connection refused
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

You can see that git does not recognize my port, here, and tries to connect to 22.

Ran on my MacBook Pro, with an sshd running at port 2222

$ git --version
git version 2.24.3 (Apple Git-128)

According the the scp manpage, git@github.com:9999/user/repository.git is not a valid path anyway:

The source and target may be specified as a local pathname, a remote host with
optional path in the form [user@]host:[path], or a URI in the form
scp://[user@]host[:port][/path].

What should I do: stick to git specification or maintain go-git backwards compatibility?

@mcuadros
Copy link
Member

mcuadros commented Jun 2, 2021

Support backward compatibility is the best in this case.

@b3n4kh
Copy link

b3n4kh commented Jan 20, 2022

My PR to this issue got closed as duplicate - this one is apparently dead. What is the way forward here?

@github-actions github-actions bot added the stale Issues/PRs that are marked for closure due to inactivity label Feb 22, 2024
@pjbgf
Copy link
Member

pjbgf commented Feb 29, 2024

Closing as this was fixed by #715.

@pjbgf pjbgf closed this Feb 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale Issues/PRs that are marked for closure due to inactivity
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants