diff --git a/src/cargo/ops/cargo_new.rs b/src/cargo/ops/cargo_new.rs index 7fa66736474..0e432e2fe4c 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 1ae6a78bbc9..0cc56e7ff73 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 1ae6a78bbc9..0cc56e7ff73 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 2ab1fce0101..dd9ddffeb23 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$ diff --git a/tests/testsuite/new.rs b/tests/testsuite/new.rs index 1564991c247..b9ddcf2d7c9 100644 --- a/tests/testsuite/new.rs +++ b/tests/testsuite/new.rs @@ -100,6 +100,23 @@ fn simple_git() { cargo_process("build").cwd(&paths::root().join("foo")).run(); } +#[cargo_test(requires_hg)] +fn simple_hg() { + cargo_process("new --lib foo --edition 2015 --vcs hg").run(); + + assert!(paths::root().is_dir()); + assert!(paths::root().join("foo/Cargo.toml").is_file()); + assert!(paths::root().join("foo/src/lib.rs").is_file()); + assert!(paths::root().join("foo/.hg").is_dir()); + assert!(paths::root().join("foo/.hgignore").is_file()); + + let fp = paths::root().join("foo/.hgignore"); + let contents = fs::read_to_string(&fp).unwrap(); + assert_eq!(contents, "^target$\n^Cargo.lock$\n",); + + cargo_process("build").cwd(&paths::root().join("foo")).run(); +} + #[cargo_test] fn no_argument() { cargo_process("new")