mirror of
https://github.com/rust-lang/cargo.git
synced 2025-09-28 11:20:36 +00:00
Auto merge of #11400 - hi-rustin:rustin-patch-fix-error, r=epage
Add error message when `cargo fix` on an empty repo ### What does this PR try to resolve? close https://github.com/rust-lang/cargo/issues/11380 Add error message when `cargo fix` on an empty repo. ### How should we test and review this PR? - [x] unit test ```sh set -eux cargo +nightly new repro cd repro echo "fn main() { let _ = 0.clone(); }" > src/main.rs cargo fix ```
This commit is contained in:
commit
a2ea66bea6
@ -154,6 +154,7 @@ fn check_version_control(config: &Config, opts: &FixOptions) -> CargoResult<()>
|
||||
if let Ok(repo) = git2::Repository::discover(config.cwd()) {
|
||||
let mut repo_opts = git2::StatusOptions::new();
|
||||
repo_opts.include_ignored(false);
|
||||
repo_opts.include_untracked(true);
|
||||
for status in repo.statuses(Some(&mut repo_opts))?.iter() {
|
||||
if let Some(path) = status.path() {
|
||||
match status.status() {
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
use cargo::core::Edition;
|
||||
use cargo_test_support::compare::assert_match_exact;
|
||||
use cargo_test_support::git;
|
||||
use cargo_test_support::git::{self, init};
|
||||
use cargo_test_support::paths::{self, CargoPathExt};
|
||||
use cargo_test_support::registry::{Dependency, Package};
|
||||
use cargo_test_support::tools;
|
||||
@ -771,6 +771,32 @@ commit the changes to these files:
|
||||
p.cargo("fix --allow-staged").run();
|
||||
}
|
||||
|
||||
#[cargo_test]
|
||||
fn errors_about_untracked_files() {
|
||||
let mut git_project = project().at("foo");
|
||||
git_project = git_project.file("src/lib.rs", "pub fn foo() {}");
|
||||
let p = git_project.build();
|
||||
let _ = init(&p.root());
|
||||
|
||||
p.cargo("fix")
|
||||
.with_status(101)
|
||||
.with_stderr(
|
||||
"\
|
||||
error: the working directory of this package has uncommitted changes, \
|
||||
and `cargo fix` can potentially perform destructive changes; if you'd \
|
||||
like to suppress this error pass `--allow-dirty`, `--allow-staged`, or \
|
||||
commit the changes to these files:
|
||||
|
||||
* Cargo.toml (dirty)
|
||||
* src/ (dirty)
|
||||
|
||||
|
||||
",
|
||||
)
|
||||
.run();
|
||||
p.cargo("fix --allow-dirty").run();
|
||||
}
|
||||
|
||||
#[cargo_test]
|
||||
fn does_not_warn_about_clean_working_directory() {
|
||||
let p = git::new("foo", |p| p.file("src/lib.rs", "pub fn foo() {}"));
|
||||
@ -1405,7 +1431,7 @@ fn fix_in_existing_repo_weird_ignore() {
|
||||
let p = git::new("foo", |project| {
|
||||
project
|
||||
.file("src/lib.rs", "")
|
||||
.file(".gitignore", "foo\ninner\n")
|
||||
.file(".gitignore", "foo\ninner\nCargo.lock\ntarget\n")
|
||||
.file("inner/file", "")
|
||||
});
|
||||
|
||||
@ -1715,7 +1741,7 @@ fn fix_with_run_cargo_in_proc_macros() {
|
||||
"src/lib.rs",
|
||||
r#"
|
||||
use proc_macro::*;
|
||||
|
||||
|
||||
#[proc_macro]
|
||||
pub fn foo(_input: TokenStream) -> TokenStream {
|
||||
let output = std::process::Command::new(env!("CARGO"))
|
||||
@ -1725,7 +1751,7 @@ fn fix_with_run_cargo_in_proc_macros() {
|
||||
eprintln!("{}", std::str::from_utf8(&output.stderr).unwrap());
|
||||
println!("{}", std::str::from_utf8(&output.stdout).unwrap());
|
||||
"".parse().unwrap()
|
||||
}
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
|
Loading…
x
Reference in New Issue
Block a user