diff --git a/src/cargo/ops/fix.rs b/src/cargo/ops/fix.rs index 40297ec3f111..2b8c55b41c7b 100644 --- a/src/cargo/ops/fix.rs +++ b/src/cargo/ops/fix.rs @@ -154,14 +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); - if repo.is_empty()? && !opts.allow_dirty { - bail!( - "no commits found in the git repository, and \ - `cargo fix` can potentially perform destructive changes; if you'd \ - like to suppress this error pass `--allow-dirty`, \ - or commit your changes" - ) - } + repo_opts.include_untracked(true); for status in repo.statuses(Some(&mut repo_opts))?.iter() { if let Some(path) = status.path() { match status.status() { diff --git a/tests/testsuite/fix.rs b/tests/testsuite/fix.rs index 897433cb000c..984972a4a703 100644 --- a/tests/testsuite/fix.rs +++ b/tests/testsuite/fix.rs @@ -772,7 +772,7 @@ commit the changes to these files: } #[cargo_test] -fn errors_on_empty_repo() { +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(); @@ -782,10 +782,15 @@ fn errors_on_empty_repo() { .with_status(101) .with_stderr( "\ -error: no commits found in the git repository, \ -and `cargo fix` can potentially perform destructive changes; \ -if you'd like to suppress this error pass `--allow-dirty`, \ -or commit your changes +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();