Include untracked files

Signed-off-by: hi-rustin <rustin.liu@gmail.com>
This commit is contained in:
hi-rustin 2022-11-26 19:37:19 +08:00
parent 25f7d4b09a
commit 3189dc3b06
2 changed files with 11 additions and 13 deletions

View file

@ -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() {

View file

@ -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();