Skip to content

Commit

Permalink
chore: fix target in generated hg ignore file
Browse files Browse the repository at this point in the history
  • Loading branch information
robjtede committed Mar 15, 2023
1 parent 4a3c588 commit 8183c31
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/cargo/ops/cargo_new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/init/mercurial_autodetect/out/.hgignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
^target/
^target$
^Cargo.lock$
2 changes: 1 addition & 1 deletion tests/testsuite/init/simple_hg/out/.hgignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
^target/
^target$
^Cargo.lock$
2 changes: 1 addition & 1 deletion tests/testsuite/init/simple_hg_ignore_exists/out/.hgignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

# Added by cargo

^target/
^target$
^Cargo.lock$
17 changes: 17 additions & 0 deletions tests/testsuite/new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 8183c31

Please sign in to comment.