-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Prevent cargo init in home directory
#16566
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
Conversation
|
r? @epage |
|
Thanks for working on this! As a heads up, we''ve found it really helpful for contributors and reviewers to split the tests out into their own commit before the change with them passing, showing the existing behavior you wish to change. Then you fix commit will update the test to reflect the new behavior with the diff between them showing how your changes affected behavior. For more on this, including example PRs, see https://doc.crates.io/contrib/process/working-on-cargo.html#submitting-a-pull-request. |
b17eb3d to
a3621f6
Compare
a3621f6 to
fd59dc2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
As this was approved during a Cargo Team meeting and this is a UX command, I'll directly merge rather than do an FCP.
| if let Some(home) = home_dir() { | ||
| if path == &home { | ||
| anyhow::bail!( | ||
| "cannot create package in the home directory\n\n\ | ||
| help: use `cargo init <path>` to create a package in a different directory" | ||
| ) | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: you can flatten these if statements
if let Some(home) = home_dir() && path == &home { ... }| #[cargo_test] | ||
| fn case() { | ||
| snapbox::cmd::Command::cargo_ui() | ||
| .arg_line("init --vcs none") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is --vcs none removed in the second commit?
(Or added in the first commit?)
Resolves #16562
Running
cargo initin the home directory can lead to confusing states, particularly for new users experimenting with Cargo. ACargo.tomlin the home directory causes issues with file discovery, as Cargo will treat the entire home directory as a package root when running commands from any subdirectory.This diff adds a check to error out when
cargo initis run in the home directory, with a message suggesting to usecargo init <path>instead.