-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Description
Doing cargo init in an existing git repository will either create a new .gitignore or append to an existing one. However if we already have a .gitignore file with both /target and **/*.rs.bk ignored, cargo init will still add these to the existing file.
Steps
$ mkdir foo && cd foo
$ git init
$ echo "/target\n**/*.rs.bk" > .gitignore
$ cargo init
The new .gitignore will now contain
/target
**/*.rs.bk
/target
**/*.rs.bk
Possible Solution(s)
Before creating or adding to the existing .gitignore, we could perhaps check the contents and only add what is missing. Looks like the code handling this is
cargo/src/cargo/ops/cargo_new.rs
Lines 460 to 465 in 485670b
| let ignore = if path.join(".gitignore").exists() { | |
| format!("\n{}", ignore) | |
| } else { | |
| ignore | |
| }; | |
| paths::append(&path.join(".gitignore"), ignore.as_bytes())?; |
cargo/src/cargo/ops/cargo_new.rs
Lines 471 to 476 in 485670b
| let hgignore = if path.join(".hgignore").exists() { | |
| format!("\n{}", hgignore) | |
| } else { | |
| hgignore | |
| }; | |
| paths::append(&path.join(".hgignore"), hgignore.as_bytes())?; |
cargo/src/cargo/ops/cargo_new.rs
Lines 482 to 487 in 485670b
| let ignore = if path.join(".ignore").exists() { | |
| format!("\n{}", ignore) | |
| } else { | |
| ignore | |
| }; | |
| paths::append(&path.join(".ignore"), ignore.as_bytes())?; |
Version: cargo 1.31.0-nightly (2d0863f 2018-10-20)