diff --git a/src/cargo/ops/fix.rs b/src/cargo/ops/fix.rs index 97ea565062e..75231b1139a 100644 --- a/src/cargo/ops/fix.rs +++ b/src/cargo/ops/fix.rs @@ -78,7 +78,9 @@ fn check_version_control(opts: &FixOptions) -> CargoResult<()> { let mut dirty_files = Vec::new(); if let Ok(repo) = git2::Repository::discover(config.cwd()) { - for status in repo.statuses(None)?.iter() { + let mut opts = git2::StatusOptions::new(); + opts.include_ignored(false); + for status in repo.statuses(Some(&mut opts))?.iter() { if status.status() != git2::Status::CURRENT { if let Some(path) = status.path() { dirty_files.push(path.to_string()); diff --git a/tests/testsuite/fix.rs b/tests/testsuite/fix.rs index 88c86586867..bce8bf8fffd 100644 --- a/tests/testsuite/fix.rs +++ b/tests/testsuite/fix.rs @@ -1,7 +1,10 @@ +use std::fs::File; + +use git2; + use support::git; use support::{execs, project}; use support::{is_nightly, ChannelChanger}; -use git2; use support::hamcrest::assert_that; #[test] @@ -966,7 +969,14 @@ fn warns_about_dirty_working_directory() { ) .build(); - git2::Repository::init(&p.root()).unwrap(); + let repo = git2::Repository::init(&p.root()).unwrap(); + let mut cfg = t!(repo.config()); + t!(cfg.set_str("user.email", "foo@bar.com")); + t!(cfg.set_str("user.name", "Foo Bar")); + drop(cfg); + git::add(&repo); + git::commit(&repo); + File::create(p.root().join("src/lib.rs")).unwrap(); assert_that( p.cargo("fix"), @@ -978,7 +988,6 @@ fix` can potentially perform destructive changes; if you'd like to \ suppress this error pass `--allow-dirty`, or commit the changes to \ these files: - * Cargo.toml * src/lib.rs @@ -1023,3 +1032,39 @@ fn does_not_warn_about_clean_working_directory() { execs().with_status(0), ); } + +#[test] +fn does_not_warn_about_dirty_ignored_files() { + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.1.0" + "#, + ) + .file( + "src/lib.rs", + r#" + pub fn foo() { + } + "#, + ) + .file(".gitignore", "foo\n") + .build(); + + let repo = git2::Repository::init(&p.root()).unwrap(); + let mut cfg = t!(repo.config()); + t!(cfg.set_str("user.email", "foo@bar.com")); + t!(cfg.set_str("user.name", "Foo Bar")); + drop(cfg); + git::add(&repo); + git::commit(&repo); + File::create(p.root().join("foo")).unwrap(); + + assert_that( + p.cargo("fix"), + execs().with_status(0), + ); +}