rust-lang / cargo

The Rust package manager
https://doc.rust-lang.org/cargo
Apache License 2.0
12.78k stars 2.42k forks source link

Cannot parse "scp-style" git URLs #3014

Closed nipunn1313 closed 7 years ago

nipunn1313 commented 8 years ago
[dependencies.myrepo]
git = "user@myhost.net:repo/myrepo.git"

According to "git help clone" this is a valid url type

       An alternative scp-like syntax may also be used with the ssh protocol:

       o   [user@]host.xz:path/to/repo.git/

However, cargo chokes on this because the url does not parse. I traced this to a call to Url::parse which does not accept this format.

Filed here with rust-url, but it seems that rust-url shouldn't be expected to parse this git format. https://github.com/servo/rust-url/issues/220

Does libgit2 have a url parsing library?

alexcrichton commented 8 years ago

Thanks for the report! I believe this is a duplicate of https://github.com/rust-lang/cargo/issues/1851, so I'm going to close in favor of that for now.

I also think that the url crate may strive to be more standards-driven in the sense that it may not ever parse these kinds of URLs. That being said, I'd be totally fine adding that sort of parsing to Cargo, as it seems quite appropriate to add!

For now though you can work around this with a URL of the form:

ssh://user@myhost.net/path/to/repo.git
nipunn1313 commented 8 years ago

@alexcrichton that workaround is actually not identical. See jboning's explanation here https://secure.phabricator.com/T11004

If you use the scp-style syntax, it sets your cwd to the user's home directory, while ssh style syntax sets your cwd to the root.

Thus, you can work around with an absolute path using ssh syntax, but it's not 1<->1 the same.

I actually believe #1851 is conflating two separate issues

1) Manifest parse error on an scp-style git url nipunn-mbp:engine nipunn$ cargo build

error: failed to parse manifest at `project/Cargo.toml`

Caused by:
  invalid url `user@myhost.net:repo/myrepo.git`: relative URL without a base

2) Inability to fetch ssh credentials without ssh-agent running. The executable git clone seems to look into ~/.ssh/id_rsa in order to do the cloning even if ssh-agent is not running or not authenticated. Seems like cargo (libgit2?) will not work unless ssh-agent is running.

I ran into both issues when investigating this issue on my side. I was running out of a blank lxc container which didn't have ssh-agent running and First ran into (1) -> switched to ssh url Ran into issue (2) -> ran evalssh-agent; ssh-add Ran into into the homedir path issue. -> switched to an absolute path

I'd like to reopen this one to pay attention to issue (1) and leave #1851 because it has a lot of conversation about issue (2).

alexcrichton commented 8 years ago

Aha very good points! I'm also cool leaving this open as a separate issue.

alexcrichton commented 8 years ago

And yeah to clarify I believe that the git command line tool literally shells out to the ssh command line tool which is why it doesn't require ssh-agent to be running. Cargo, however, links to libgit2 for git operations and libssh2 for ssh operations. Neither implements parsing of ~/.ssh/config (https://github.com/rust-lang/cargo/issues/2078) but libssh2 supports ssh-agent, so that's the only source we draw keys from right now.

alexcrichton commented 7 years ago

I believe this is a duplicate of https://github.com/rust-lang/cargo/issues/1851, so closing in favor of that.