Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/cargo/ops/fix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
51 changes: 48 additions & 3 deletions tests/testsuite/fix.rs
Original file line number Diff line number Diff line change
@@ -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]
Expand Down Expand Up @@ -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", "[email protected]"));
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"),
Expand All @@ -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


Expand Down Expand Up @@ -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", "[email protected]"));
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),
);
}