-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Suggest cargo install url using --git #10485
Comments
Heuristically identify git URL by matching the pattern "git" in the domain. Add a special case error with a fixit hint to help users rerun the correct cargo install command
As suggested here i would like to get some input on a heuristic that I can use to tell if a command line argument is a git-repo in disguise. This is the comment in question. b87ae28#diff-962037da03b1549f2185f7de90ea6bf84aabfe566f3033a4d983955cb21b6bf5R527-R534 Is matching "git" in the domain enough? What about "bitbucket"? Any other providers? Can this be dynamically populated from cargo config with another repository name? @pickfire can you please provide some input as the original reporter |
I'm trying to think of what a user might type in, valid or not,
Ideas
|
I think string matching probably won't work here given that alias can be done, I see two ways:
Not a good idea as git can work without that.
That limits the scope greatly given that What I think is when a path is invalid, maybe we can first probe git to try and clone it (given that you can use alias in git like But most importantly we only suggest this when the input is invalid, so it's fine even though the suggestion may be incorrect, so we don't really have to git clone to probe it, can just suggest it when the crate name didn't work out. |
Note that my ideas for checking
We probably should not make any network connections to determine what hint we should give.
As I mentioned, there are other cases we should differentiate with like for paths. That is why I was suggesting the URL approach so we can differentiate between an identifier, a path, and a url and suggest |
What about using this crate then our hint can use the GitUrl struct to generate the appropriate suggestion? |
GitUrl manages to successfully parse all 5 URLs that you gave, but installing from git@ urls fails. cargo install --git [email protected]:rust-lang/cargo.git
error: invalid url `[email protected]:rust-lang/cargo.git`: relative URL without a base Replacing Url with GitUrl in cargo feels like a bigger task than this ticket and current bandwidth allows. The question is - would you be amenable to using GitUrl only to verify that the cmdline argument is indeed a valid git URL and generate a suggestion that uses https for cargo install? |
What do you think about this prototype? It uses GitUrl and then normalises git@ arguments into http-based git URLs that cargo currently supports. |
Not sure if we want to normalize it but I think it's better to show the suggestion with the url that user was given rather than the normalized url, then the user might be surprised where did that url come from, if it's from their input then it should not be surprising. |
if we leave the URL supplied by the user, the hint will suggest another failing command cargo install [email protected]:jcmoyer/rust-tictactoe.git
Updating crates.io index
error: could not find `[email protected]:jcmoyer/rust-tictactoe.git` in registry `crates-io` with version `*` # imagine this suggested add `install --git [email protected]:jcmoyer/rust-tictactoe.git
cargo install --git [email protected]:jcmoyer/rust-tictactoe.git
error: invalid url `[email protected]:jcmoyer/rust-tictactoe.git`: relative URL without a base you are right about the principle of least surprise and I want to follow it, but I don't want to make a suggestion that also errors. what if I restrict the hint suggestion to only return something for http(s) git URLs? |
That works too since most git url behave like that, then we can just ignore those without for now. |
cargo install: suggest --git when package name is url ### What does this PR try to resolve? Improve the error message when specifying a URL for a package name in `cargo install`. Fixes #10485 ### How should we test and review this PR? Just cargo test and trying a common case like `cargo install https://github.com/rust-lang/cargo` ### Additional information I found this PR after finishing this one: #10522 But it seems have a larger scope to refactor some of the related code. Perhaps this one would be easier to merge and that one could focus on the refactor, otherwise sorry for the noise and feel free to close.
Problem
Currently, someone may try
cargo install https://github.com/light4/cargo-info
, then I see.Proposed Solution
It would be nice to see a suggestion to ask the user to run the same command with
--git
.Notes
No response
The text was updated successfully, but these errors were encountered: