diff --git a/src/cargo/ops/cargo_new.rs b/src/cargo/ops/cargo_new.rs index 7fa667364742..0e432e2fe4ca 100644 --- a/src/cargo/ops/cargo_new.rs +++ b/src/cargo/ops/cargo_new.rs @@ -742,7 +742,7 @@ fn mk(config: &Config, opts: &MkOptions<'_>) -> CargoResult<()> { // Using the push method with multiple arguments ensures that the entries // for all mutually-incompatible VCS in terms of syntax are in sync. let mut ignore = IgnoreList::new(); - ignore.push("/target", "^target/", "target"); + ignore.push("/target", "^target$", "target"); if !opts.bin { ignore.push("/Cargo.lock", "^Cargo.lock$", "Cargo.lock"); } diff --git a/tests/testsuite/init/mercurial_autodetect/out/.hgignore b/tests/testsuite/init/mercurial_autodetect/out/.hgignore index 1ae6a78bbc9f..0cc56e7ff73a 100644 --- a/tests/testsuite/init/mercurial_autodetect/out/.hgignore +++ b/tests/testsuite/init/mercurial_autodetect/out/.hgignore @@ -1,2 +1,2 @@ -^target/ +^target$ ^Cargo.lock$ diff --git a/tests/testsuite/init/simple_hg/out/.hgignore b/tests/testsuite/init/simple_hg/out/.hgignore index 1ae6a78bbc9f..0cc56e7ff73a 100644 --- a/tests/testsuite/init/simple_hg/out/.hgignore +++ b/tests/testsuite/init/simple_hg/out/.hgignore @@ -1,2 +1,2 @@ -^target/ +^target$ ^Cargo.lock$ diff --git a/tests/testsuite/init/simple_hg_ignore_exists/out/.hgignore b/tests/testsuite/init/simple_hg_ignore_exists/out/.hgignore index 2ab1fce0101b..dd9ddffeb23a 100644 --- a/tests/testsuite/init/simple_hg_ignore_exists/out/.hgignore +++ b/tests/testsuite/init/simple_hg_ignore_exists/out/.hgignore @@ -2,5 +2,5 @@ # Added by cargo -^target/ +^target$ ^Cargo.lock$