Repository: ashleygwilliams/cargo-generate (rust)

Issue:
Creates an empty `.cargo-ok` file
```console
> cargo generate --git https://github.com/Michael-F-Bryan/github-template --name const-arrayvec
> ls const-arrayvec/.cargo-ok
const-arrayvec/.cargo-ok
> cargo generate --version
cargo-generate 0.5.1
```

This file causes issues for `cargo` (though that should be fixed in 1.49) https://github.com/rust-lang/cargo/issues/8816

Pull request description:
Ignore .cargo-ok files by default.
I was going to write a script that wraps `cargo-generate` and then automatically deletes this, but it's pretty easy to just add to the default ignore set.

This file serves no purpose and causes clutter, and many users either fail to notice it or think it should be kept: https://sourcegraph.com/search?q=file:.cargo-ok&patternType=literal

I suspect any case where this file is actually part of the template is either broken or at best fragile (as it's existence can prevent cargo from detecting failure to extract the tarball), depending on cargo's behavior. (That said, if any do exist, it seems very likely they came into existence by something like using `cargo-generate` to generate a template repo).

Fixes #259

Patch:
diff --git a/src/ignoreme.rs b/src/ignoreme.rs
index 9e1c70e..0d67fe9 100644
--- a/src/ignoreme.rs
+++ b/src/ignoreme.rs
@@ -3,13 +3,22 @@ use remove_dir_all::*;
 use std::fs::remove_file;
 use std::{
     collections::HashSet,
-    iter,
     path::{Path, PathBuf},
 };
 
 use crate::config::CONFIG_FILE_NAME;
 pub(crate) const IGNORE_FILE_NAME: &str = ".genignore";
 
+// We ignore the `.cargo-ok` file if one is present. This file is a somewhat
+// obscure marker that cargo leaves around after extracting a tarball to
+// indicate that the extraction succeeded, and is very likely not part of the
+// actual template.
+//
+// Leaving it around is mostly harmless in the version of cargo we depend on
+// (prior to 1.49, cargo could get very confused by it) but it serves no purpose
+// after expanding the template, other than cluttering a user's repository.
+const CARGO_OK_FILE_NAME: &str = ".cargo-ok";
+
 /// Takes the directory path and removes the files/directories specified in the
 /// `.genignore` file
 /// It handles all errors internally
@@ -26,12 +35,11 @@ fn check_if_genignore_exists(location: &Path) -> bool {
 }
 
 fn get_ignored(location: &Path) -> Vec<PathBuf> {
-    let configs = Iterator::chain(
-        iter::once(location.join(IGNORE_FILE_NAME)),
-        iter::once(location.join(CONFIG_FILE_NAME)),
-    );
+    let default_ignored = [IGNORE_FILE_NAME, CONFIG_FILE_NAME, CARGO_OK_FILE_NAME]
+        .iter()
+        .map(|&file_name| location.join(file_name));
     if !check_if_genignore_exists(location) {
-        return configs.collect();
+        return default_ignored.collect();
     }
     let all = WalkBuilder::new(location)
         .standard_filters(false)
@@ -45,7 +53,7 @@ fn get_ignored(location: &Path) -> Vec<PathBuf> {
         .map(unwrap_path)
         .collect();
 
-    configs
+    default_ignored
         .chain(all.filter(|it| !whitelisted.contains(it)))
         .collect()
 }


Test patch:
diff --git a/tests/integration/basics.rs b/tests/integration/basics.rs
index 96c2eea..1446adc 100644
--- a/tests/integration/basics.rs
+++ b/tests/integration/basics.rs
@@ -356,6 +356,39 @@ version = "0.1.0"
     assert_eq!(dir.exists("foobar-project/.genignore"), false);
 }
 
+#[test]
+fn it_always_removes_cargo_ok_file() {
+    let template = dir("template")
+        .file(
+            "Cargo.toml",
+            r#"[package]
+name = "{{project-name}}"
+description = "A wonderful project"
+version = "0.1.0"
+"#,
+        )
+        .file(".genignore", r#"farts"#)
+        .init_git()
+        .build();
+
+    let dir = dir("main").build();
+
+    binary()
+        .arg("gen")
+        .arg("--git")
+        .arg(template.path())
+        .arg("-n")
+        .arg("foobar-project")
+        .arg("--branch")
+        .arg("main")
+        .current_dir(&dir.path())
+        .assert()
+        .success()
+        .stdout(predicates::str::contains("Done!").from_utf8());
+
+    assert_eq!(dir.exists("foobar-project/.cargo-ok"), false);
+}
+
 #[test]
 fn it_removes_genignore_files_before_substitution() {
     let template = dir("template")