From 4c22338df3866aa31ee14a6d3755231bf9c5ca76 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Thu, 28 Dec 2023 22:08:16 +0530 Subject: [PATCH 1/4] add: --no-git flag while cargo shuttle init command --- cargo-shuttle/src/args.rs | 3 +++ cargo-shuttle/src/init.rs | 11 +++++++---- cargo-shuttle/src/lib.rs | 2 ++ 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/cargo-shuttle/src/args.rs b/cargo-shuttle/src/args.rs index bf7aa959c..2b963f48a 100644 --- a/cargo-shuttle/src/args.rs +++ b/cargo-shuttle/src/args.rs @@ -304,6 +304,9 @@ pub struct InitArgs { /// Whether to start the container for this project on Shuttle, and claim the project name #[arg(long)] pub create_env: bool, + /// Whethere to initialize git repository or not during the init command + #[arg(long)] + pub no_git: bool, #[command(flatten)] pub login_args: LoginArgs, } diff --git a/cargo-shuttle/src/init.rs b/cargo-shuttle/src/init.rs index 26179eec2..6bed95f27 100644 --- a/cargo-shuttle/src/init.rs +++ b/cargo-shuttle/src/init.rs @@ -19,7 +19,7 @@ use url::Url; use crate::args::TemplateLocation; -pub fn generate_project(dest: PathBuf, name: &str, temp_loc: TemplateLocation) -> Result<()> { +pub fn generate_project(dest: PathBuf, name: &str, temp_loc: TemplateLocation, no_git: bool) -> Result<()> { println!(r#"Creating project "{name}" in "{}""#, dest.display()); let temp_dir: TempDir = setup_template(&temp_loc.auto_path) @@ -52,9 +52,12 @@ pub fn generate_project(dest: PathBuf, name: &str, temp_loc: TemplateLocation) - // Initialize a Git repository in the destination directory if there // is no existing Git repository present in the surrounding folders. - let no_git_repo = gix::discover(&dest).is_err(); - if no_git_repo { - gix::init(&dest).context("Failed to initialize project repository")?; + // only if no-git argument is not passed otherwise initialize git repo + if !no_git { + let no_git_repo = gix::discover(&dest).is_err(); + if no_git_repo { + gix::init(&dest).context("Failed to initialize project repository")?; + } } Ok(()) diff --git a/cargo-shuttle/src/lib.rs b/cargo-shuttle/src/lib.rs index 362c8c124..5cb327d0e 100644 --- a/cargo-shuttle/src/lib.rs +++ b/cargo-shuttle/src/lib.rs @@ -320,6 +320,7 @@ impl Shuttle { ) -> Result { // Turns the template or git args (if present) to a repo+folder. let git_template = args.git_template()?; + let no_git = args.no_git; let unauthorized = self.ctx.api_key().is_err() && args.login_args.api_key.is_none(); @@ -459,6 +460,7 @@ impl Shuttle { .as_ref() .expect("to have a project name provided"), template, + no_git )?; println!(); From 88fce4d983e371e51652c50c28ccc825a2280d44 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Fri, 29 Dec 2023 06:46:01 +0530 Subject: [PATCH 2/4] ref: fixed some fmt issues --- cargo-shuttle/src/init.rs | 7 ++++++- cargo-shuttle/src/lib.rs | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/cargo-shuttle/src/init.rs b/cargo-shuttle/src/init.rs index 6bed95f27..39a38efcc 100644 --- a/cargo-shuttle/src/init.rs +++ b/cargo-shuttle/src/init.rs @@ -19,7 +19,12 @@ use url::Url; use crate::args::TemplateLocation; -pub fn generate_project(dest: PathBuf, name: &str, temp_loc: TemplateLocation, no_git: bool) -> Result<()> { +pub fn generate_project( + dest: PathBuf, + name: &str, + temp_loc: TemplateLocation, + no_git: bool +) -> Result<()> { println!(r#"Creating project "{name}" in "{}""#, dest.display()); let temp_dir: TempDir = setup_template(&temp_loc.auto_path) diff --git a/cargo-shuttle/src/lib.rs b/cargo-shuttle/src/lib.rs index 5cb327d0e..2adc5e750 100644 --- a/cargo-shuttle/src/lib.rs +++ b/cargo-shuttle/src/lib.rs @@ -460,7 +460,7 @@ impl Shuttle { .as_ref() .expect("to have a project name provided"), template, - no_git + no_git, )?; println!(); From 120712cbb3c923f6661bd92ba2fba75b2e81e10e Mon Sep 17 00:00:00 2001 From: Dhruv <91935072+dhruvdabhi101@users.noreply.github.com> Date: Fri, 29 Dec 2023 07:47:14 +0530 Subject: [PATCH 3/4] chore: Update args.rs ( rephrasing to make docs simple ) Co-authored-by: jonaro00 <54029719+jonaro00@users.noreply.github.com> --- cargo-shuttle/src/args.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cargo-shuttle/src/args.rs b/cargo-shuttle/src/args.rs index 2b963f48a..9b9164db3 100644 --- a/cargo-shuttle/src/args.rs +++ b/cargo-shuttle/src/args.rs @@ -304,7 +304,7 @@ pub struct InitArgs { /// Whether to start the container for this project on Shuttle, and claim the project name #[arg(long)] pub create_env: bool, - /// Whethere to initialize git repository or not during the init command + /// Don't initialize a new git repository #[arg(long)] pub no_git: bool, #[command(flatten)] From 357203384122518829bdc4d8782977ac18290ad2 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Fri, 29 Dec 2023 16:57:47 +0530 Subject: [PATCH 4/4] chore: fmt fixes --- cargo-shuttle/src/init.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cargo-shuttle/src/init.rs b/cargo-shuttle/src/init.rs index 39a38efcc..f12f16fb6 100644 --- a/cargo-shuttle/src/init.rs +++ b/cargo-shuttle/src/init.rs @@ -20,10 +20,10 @@ use url::Url; use crate::args::TemplateLocation; pub fn generate_project( - dest: PathBuf, - name: &str, - temp_loc: TemplateLocation, - no_git: bool + dest: PathBuf, + name: &str, + temp_loc: TemplateLocation, + no_git: bool, ) -> Result<()> { println!(r#"Creating project "{name}" in "{}""#, dest.display());