diff --git a/src/cargo/util/vcs.rs b/src/cargo/util/vcs.rs index 84474867640..01a8c1fa749 100644 --- a/src/cargo/util/vcs.rs +++ b/src/cargo/util/vcs.rs @@ -13,9 +13,12 @@ use crate::util::{process, CargoResult}; pub fn existing_vcs_repo(path: &Path, cwd: &Path) -> bool { fn in_git_repo(path: &Path, cwd: &Path) -> bool { if let Ok(repo) = GitRepo::discover(path, cwd) { - repo.is_path_ignored(path) - .map(|ignored| !ignored) - .unwrap_or(true) + // Don't check if the working directory itself is ignored. + if repo.workdir().map_or(false, |workdir| workdir == path) { + true + } else { + !repo.is_path_ignored(path).unwrap_or(false) + } } else { false } diff --git a/tests/testsuite/fix.rs b/tests/testsuite/fix.rs index 97d49108742..667e240ecf1 100644 --- a/tests/testsuite/fix.rs +++ b/tests/testsuite/fix.rs @@ -1289,3 +1289,26 @@ fn fix_with_common() { assert_eq!(p.read_file("tests/common/mod.rs"), "pub fn r#try() {}"); } + +#[test] +fn fix_in_existing_repo_weird_ignore() { + // Check that ignore doesn't ignore the repo itself. + let p = git::new("foo", |project| { + project + .file("src/lib.rs", "") + .file(".gitignore", "foo\ninner\n") + .file("inner/file", "") + }) + .unwrap(); + + p.cargo("fix").run(); + // This is questionable about whether it is the right behavior. It should + // probably be checking if any source file for the current project is + // ignored. + p.cargo("fix") + .cwd(p.root().join("inner")) + .with_stderr_contains("[ERROR] no VCS found[..]") + .with_status(101) + .run(); + p.cargo("fix").cwd(p.root().join("src")).run(); +}