From b17521063a75840d721ee19872bf543da6e2e5b7 Mon Sep 17 00:00:00 2001 From: Jacob Marshall Date: Tue, 8 Apr 2025 17:03:42 +0100 Subject: [PATCH] feat: init new git repo for new projects (#558) --- crates/tuono/src/commands/new.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/crates/tuono/src/commands/new.rs b/crates/tuono/src/commands/new.rs index 22b3ce9f..538b1396 100644 --- a/crates/tuono/src/commands/new.rs +++ b/crates/tuono/src/commands/new.rs @@ -6,6 +6,8 @@ use std::env; use std::fs::{self, File, OpenOptions, create_dir}; use std::io::{self, prelude::*}; use std::path::{Path, PathBuf}; +use std::process::Command; +use tracing::trace; #[derive(Deserialize, Debug)] enum GithubFileType { @@ -156,6 +158,9 @@ pub fn create_new_project( update_package_json_version(&folder_path).expect("Failed to update package.json version"); update_cargo_toml_version(&folder_path).expect("Failed to update Cargo.toml version"); + + init_new_git_repo(&folder_path); + outro(folder); } @@ -265,6 +270,16 @@ fn update_cargo_toml_version(folder_path: &Path) -> io::Result<()> { Ok(()) } +fn init_new_git_repo(folder_path: &Path) { + if let Ok(output) = Command::new("git").arg("init").arg(folder_path).output() { + if !output.status.success() { + trace!("Failed to initialise a new git repo") + } + } else { + trace!("Failed to initialise a new git repo") + } +} + fn outro(folder_name: String) { println!("Success! 🎉");