From 4ce2714da1f079e81b6887b52b1acfbc283a3d63 Mon Sep 17 00:00:00 2001
From: mo8it <mo8it@proton.me>
Date: Mon, 22 Apr 2024 00:38:34 +0200
Subject: [PATCH] Add --no-git

---
 src/dev.rs     | 10 +++++++---
 src/dev/new.rs | 13 +++++++------
 2 files changed, 14 insertions(+), 9 deletions(-)

diff --git a/src/dev.rs b/src/dev.rs
index 68777d1..d7f9af6 100644
--- a/src/dev.rs
+++ b/src/dev.rs
@@ -11,7 +11,11 @@ mod update;
 
 #[derive(Subcommand)]
 pub enum DevCommands {
-    New { path: PathBuf },
+    New {
+        path: PathBuf,
+        #[arg(long)]
+        no_git: bool,
+    },
     Check,
     Update,
 }
@@ -19,12 +23,12 @@ pub enum DevCommands {
 impl DevCommands {
     pub fn run(self) -> Result<()> {
         match self {
-            DevCommands::New { path } => {
+            DevCommands::New { path, no_git } => {
                 if DEBUG_PROFILE {
                     bail!("Disabled in the debug build");
                 }
 
-                new::new(&path).context(INIT_ERR)
+                new::new(&path, no_git).context(INIT_ERR)
             }
             DevCommands::Check => check::check(),
             DevCommands::Update => update::update(),
diff --git a/src/dev/new.rs b/src/dev/new.rs
index b0828a4..82aba42 100644
--- a/src/dev/new.rs
+++ b/src/dev/new.rs
@@ -26,7 +26,7 @@ where
     Ok(())
 }
 
-pub fn new(path: &Path) -> Result<()> {
+pub fn new(path: &Path, no_git: bool) -> Result<()> {
     let dir_name = path.to_string_lossy();
 
     create_dir(path).with_context(|| format!("Failed to create the directory {dir_name}"))?;
@@ -35,11 +35,12 @@ pub fn new(path: &Path) -> Result<()> {
     set_current_dir(path)
         .with_context(|| format!("Failed to set {dir_name} as the current directory"))?;
 
-    if !Command::new("git")
-        .arg("init")
-        .status()
-        .context("Failed to run `git init`")?
-        .success()
+    if !no_git
+        && !Command::new("git")
+            .arg("init")
+            .status()
+            .context("Failed to run `git init`")?
+            .success()
     {
         bail!("`git init` didn't run successfully. See the error message above");
     }