Skip to content

fix(install): check if git url contains a rev #15489

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

dawedawe
Copy link
Contributor

@dawedawe dawedawe commented May 4, 2025

Check if the git url contains a '#' which is likely a sign for the user's desire to specify a rev. Give hint to use --rev

Fixes #15336

@rustbot
Copy link
Collaborator

rustbot commented May 4, 2025

r? @epage

rustbot has assigned @epage.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added A-cli Area: Command-line interface, option parsing, etc. Command-install S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 4, 2025
Comment on lines 175 to 183
if url.contains('#') {
return Err(anyhow::format_err!(
"invalid git url to install from\n\n\
help: use `--rev <SHA>` to specify a commit"
)
.into());
}

let url = url.into_url()?;
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this check be done on the parsed URL, rather than on the string?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, yeah. That makes a lot of sense.

Comment on lines 175 to 183
if url.contains('#') {
return Err(anyhow::format_err!(
"invalid git url to install from\n\n\
help: use `--rev <SHA>` to specify a commit"
)
.into());
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Is this definitively a bad URL or should this be a hint on the existing error?

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 think it's definitely a bad URL, yes.
From the github page:
2025-05-05-223239_hyprshot

I can't think of a valid git url with a # besides the rev.

Copy link
Contributor

Choose a reason for hiding this comment

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

Cargo supports more than Github. The question would be more about the git protocol and what is expected around it as we could be turning a success case into an error case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

From what I'm seeing here, other git servers should be the same.

return error if the git url contains a # and hint user to use --rev
@dawedawe dawedawe force-pushed the check_rev_in_git_url branch from 552440b to dcc8cef Compare May 5, 2025 20:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-cli Area: Command-line interface, option parsing, etc. Command-install S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cargo install --git accepts malformed URL with #, discards it for cloning, then re-adds it into crates.toml
3 participants