mirror of
https://github.com/rust-lang/cargo.git
synced 2025-10-01 11:30:39 +00:00
Only include "already existing ..." comment in gitignore on conflict
This comment was previously confusing when there were no existing items that conflict.
This commit is contained in:
parent
0c0f9aeccf
commit
3e8cdd7ce0
@ -487,10 +487,14 @@ impl IgnoreList {
|
||||
_ => &self.ignore,
|
||||
};
|
||||
|
||||
let mut out = "\n\n#Added by cargo\n\
|
||||
#\n\
|
||||
#already existing elements are commented out\n\n"
|
||||
.to_string();
|
||||
let mut out = "\n\n#Added by cargo\n".to_string();
|
||||
if ignore_items
|
||||
.iter()
|
||||
.any(|item| existing_items.contains(item))
|
||||
{
|
||||
out.push_str("#\n#already existing elements are commented out\n");
|
||||
}
|
||||
out.push('\n');
|
||||
|
||||
for item in ignore_items {
|
||||
if existing_items.contains(item) {
|
||||
|
@ -99,6 +99,33 @@ fn simple_git_ignore_exists() {
|
||||
cargo_process("build").cwd(&paths::root().join("foo")).run();
|
||||
}
|
||||
|
||||
#[cargo_test]
|
||||
fn git_ignore_exists_no_conflicting_entries() {
|
||||
// write a .gitignore file with one entry
|
||||
fs::create_dir_all(paths::root().join("foo")).unwrap();
|
||||
fs::write(paths::root().join("foo/.gitignore"), "**/some.file").unwrap();
|
||||
|
||||
cargo_process("init --lib foo --edition 2015")
|
||||
.env("USER", "foo")
|
||||
.run();
|
||||
|
||||
let fp = paths::root().join("foo/.gitignore");
|
||||
let mut contents = String::new();
|
||||
File::open(&fp)
|
||||
.unwrap()
|
||||
.read_to_string(&mut contents)
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
contents,
|
||||
"**/some.file\n\n\
|
||||
#Added by cargo\n\
|
||||
\n\
|
||||
/target\n\
|
||||
**/*.rs.bk\n\
|
||||
Cargo.lock\n",
|
||||
);
|
||||
}
|
||||
|
||||
#[cargo_test]
|
||||
fn both_lib_and_bin() {
|
||||
cargo_process("init --lib --bin")
|
||||
|
Loading…
x
Reference in New Issue
Block a user