Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cargo-new should not add ignore rule on Cargo.lock inside subdirs #10379

Merged
merged 2 commits into from
Feb 15, 2022
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
2 changes: 1 addition & 1 deletion src/cargo/ops/cargo_new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ fn mk(config: &Config, opts: &MkOptions<'_>) -> CargoResult<()> {
let mut ignore = IgnoreList::new();
ignore.push("/target", "^target/", "target");
if !opts.bin {
ignore.push("Cargo.lock", "glob:Cargo.lock", "Cargo.lock,*/Cargo.lock");
ignore.push("/Cargo.lock", "^Cargo.lock$", "Cargo.lock");
}

let vcs = opts.version_control.unwrap_or_else(|| {
Expand Down
48 changes: 44 additions & 4 deletions tests/testsuite/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ fn simple_git_ignore_exists() {
# already existing elements were commented out\n\
\n\
#/target\n\
Cargo.lock\n",
/Cargo.lock\n",
);

cargo_process("build").cwd(&paths::root().join("foo")).run();
Expand All @@ -105,7 +105,7 @@ fn git_ignore_exists_no_conflicting_entries() {
# Added by cargo\n\
\n\
/target\n\
Cargo.lock\n",
/Cargo.lock\n",
);
}

Expand Down Expand Up @@ -337,7 +337,9 @@ fn git_autodetect() {
assert!(paths::root().join("Cargo.toml").is_file());
assert!(paths::root().join("src/lib.rs").is_file());
assert!(paths::root().join(".git").is_dir());
assert!(paths::root().join(".gitignore").is_file());
let path = paths::root().join(".gitignore");
assert!(paths::root().join(&path).is_file());
assert_eq!(fs::read_to_string(&path).unwrap(), "/target\n/Cargo.lock\n",);
}

#[cargo_test]
Expand All @@ -349,7 +351,45 @@ fn mercurial_autodetect() {
assert!(paths::root().join("Cargo.toml").is_file());
assert!(paths::root().join("src/lib.rs").is_file());
assert!(!paths::root().join(".git").is_dir());
assert!(paths::root().join(".hgignore").is_file());
let path = paths::root().join(".hgignore");
assert!(paths::root().join(&path).is_file());
assert_eq!(
fs::read_to_string(&path).unwrap(),
"^target/\n^Cargo.lock$\n",
);
}

#[cargo_test]
fn fossil_autodetect() {
fs::create_dir(&paths::root().join(".fossil")).unwrap();

cargo_process("init --lib").run();

assert!(paths::root().join("Cargo.toml").is_file());
assert!(paths::root().join("src/lib.rs").is_file());
assert!(!paths::root().join(".git").is_dir());
for path in [
".fossil-settings/ignore-glob",
".fossil-settings/clean-glob",
] {
let path = paths::root().join(path);
assert!(paths::root().join(&path).is_file());
assert_eq!(fs::read_to_string(&path).unwrap(), "target\nCargo.lock\n",);
}
}

#[cargo_test]
fn pijul_autodetect() {
fs::create_dir(&paths::root().join(".pijul")).unwrap();

cargo_process("init --lib").run();

assert!(paths::root().join("Cargo.toml").is_file());
assert!(paths::root().join("src/lib.rs").is_file());
assert!(!paths::root().join(".git").is_dir());
let path = paths::root().join(".ignore");
assert!(paths::root().join(&path).is_file());
assert_eq!(fs::read_to_string(&path).unwrap(), "/target\n/Cargo.lock\n",);
}

#[cargo_test]
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ fn simple_git() {

let fp = paths::root().join("foo/.gitignore");
let contents = fs::read_to_string(&fp).unwrap();
assert_eq!(contents, "/target\nCargo.lock\n",);
assert_eq!(contents, "/target\n/Cargo.lock\n",);

cargo_process("build").cwd(&paths::root().join("foo")).run();
}
Expand Down