]> git.proxmox.com Git - cargo.git/commitdiff
Add a newline before appended VCS ignore lines
authorJonathan Giddy <jongiddy@gmail.com>
Sat, 21 Oct 2017 15:15:52 +0000 (16:15 +0100)
committerJonathan Giddy <jongiddy@gmail.com>
Sat, 21 Oct 2017 15:15:52 +0000 (16:15 +0100)
src/cargo/ops/cargo_new.rs
tests/init.rs

index 9c597df85112dd937a3023383f022d11d61c11a9..10174d0a142c3f24388455b8eef642f952e9b91f 100644 (file)
@@ -393,13 +393,13 @@ fn mk(config: &Config, opts: &MkOptions) -> CargoResult<()> {
     let name = opts.name;
     let cfg = global_config(config)?;
     // Please ensure that ignore and hgignore are in sync.
-    let ignore = ["/target/\n", "**/*.rs.bk\n",
+    let ignore = ["\n", "/target/\n", "**/*.rs.bk\n",
         if !opts.bin { "Cargo.lock\n" } else { "" }]
         .concat();
     // Mercurial glob ignores can't be rooted, so just sticking a 'syntax: glob' at the top of the
     // file will exclude too much. Instead, use regexp-based ignores. See 'hg help ignore' for
     // more.
-    let hgignore = ["^target/\n", "glob:*.rs.bk\n",
+    let hgignore = ["\n", "^target/\n", "glob:*.rs.bk\n",
         if !opts.bin { "glob:Cargo.lock\n" } else { "" }]
         .concat();
 
index 47efa3b97c907c2724a30efd0e9df08851bf18ce..c0b3fcd75f2530bf7f44b51920183f55bcbd1bf3 100644 (file)
@@ -335,6 +335,40 @@ fn gitignore_appended_not_replaced() {
     assert!(contents.contains(r#"qqqqqq"#));
 }
 
+#[test]
+fn gitignore_added_newline_if_required() {
+    fs::create_dir(&paths::root().join(".git")).unwrap();
+
+    File::create(&paths::root().join(".gitignore")).unwrap().write_all(b"first").unwrap();
+
+    assert_that(cargo_process("init").arg("--lib")
+                                     .env("USER", "foo"),
+                execs().with_status(0));
+
+    assert_that(&paths::root().join(".gitignore"), existing_file());
+
+    let mut contents = String::new();
+    File::open(&paths::root().join(".gitignore")).unwrap().read_to_string(&mut contents).unwrap();
+    assert!(contents.starts_with("first\n"));
+}
+
+#[test]
+fn mercurial_added_newline_if_required() {
+    fs::create_dir(&paths::root().join(".hg")).unwrap();
+
+    File::create(&paths::root().join(".hgignore")).unwrap().write_all(b"first").unwrap();
+
+    assert_that(cargo_process("init").arg("--lib")
+                                     .env("USER", "foo"),
+                execs().with_status(0));
+
+    assert_that(&paths::root().join(".hgignore"), existing_file());
+
+    let mut contents = String::new();
+    File::open(&paths::root().join(".hgignore")).unwrap().read_to_string(&mut contents).unwrap();
+    assert!(contents.starts_with("first\n"));
+}
+
 #[test]
 fn cargo_lock_gitignored_if_lib1() {
     fs::create_dir(&paths::root().join(".git")).unwrap();