mirror of
https://github.com/rust-lang/cargo.git
synced 2025-10-01 11:30:39 +00:00
Allow cargo fix
if gitignore matches root working dir.
This commit is contained in:
parent
ff1c9de432
commit
00c562df56
@ -13,9 +13,12 @@ use crate::util::{process, CargoResult};
|
|||||||
pub fn existing_vcs_repo(path: &Path, cwd: &Path) -> bool {
|
pub fn existing_vcs_repo(path: &Path, cwd: &Path) -> bool {
|
||||||
fn in_git_repo(path: &Path, cwd: &Path) -> bool {
|
fn in_git_repo(path: &Path, cwd: &Path) -> bool {
|
||||||
if let Ok(repo) = GitRepo::discover(path, cwd) {
|
if let Ok(repo) = GitRepo::discover(path, cwd) {
|
||||||
repo.is_path_ignored(path)
|
// Don't check if the working directory itself is ignored.
|
||||||
.map(|ignored| !ignored)
|
if repo.workdir().map_or(false, |workdir| workdir == path) {
|
||||||
.unwrap_or(true)
|
true
|
||||||
|
} else {
|
||||||
|
!repo.is_path_ignored(path).unwrap_or(false)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
@ -1289,3 +1289,26 @@ fn fix_with_common() {
|
|||||||
|
|
||||||
assert_eq!(p.read_file("tests/common/mod.rs"), "pub fn r#try() {}");
|
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();
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user