From 67d0fada5ae59ca692022ec9f7f5392d7479206a Mon Sep 17 00:00:00 2001 From: Matthew Callens Date: Fri, 11 Mar 2022 19:41:01 -0500 Subject: [PATCH 1/4] cli: `anchor init` now initialized a new git repository --- cli/src/lib.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/cli/src/lib.rs b/cli/src/lib.rs index f8c486e1e8..ff643f293c 100644 --- a/cli/src/lib.rs +++ b/cli/src/lib.rs @@ -574,6 +574,16 @@ fn init(cfg_override: &ConfigOverride, name: String, javascript: bool) -> Result println!("Failed to install node dependencies") } + let git_result = std::process::Command::new("git") + .arg("init") + .stdout(Stdio::inherit()) + .stderr(Stdio::inherit()) + .output() + .map_err(|e| anyhow::format_err!("git init failed: {}", e.to_string()))?; + if !git_result.status.success() { + eprintln!("Failed to automatically initialize a new git repository"); + } + println!("{} initialized", name); Ok(()) From 94898c2425fa2ea32070914dba1088c64e8a1708 Mon Sep 17 00:00:00 2001 From: Matthew Callens Date: Fri, 11 Mar 2022 19:43:24 -0500 Subject: [PATCH 2/4] update CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 381833fcf3..95c88b5a1d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ incremented for features. ### Features * cli: Add `anchor clean` command that's the same as `cargo clean` but preserves keypairs inside `target/deploy` ([#1470](https://github.com/project-serum/anchor/issues/1470)). +* cli: Running `anchor init` now initializes a new git repository for the workspace ([#1605](https://github.com/project-serum/anchor/pull/1605)). * lang: Add new `AccountSysvarMismatch` error code and test cases for sysvars ([#1535](https://github.com/project-serum/anchor/pull/1535)). * spl: Add support for revoke instruction ([#1493](https://github.com/project-serum/anchor/pull/1493)). * ts: Add provider parameter to `Spl.token` factory method ([#1597](https://github.com/project-serum/anchor/pull/1597)). From 8e51811b7adb3967bfcf174b19c70c9a01c32681 Mon Sep 17 00:00:00 2001 From: Matthew Callens Date: Sun, 13 Mar 2022 22:50:16 -0400 Subject: [PATCH 3/4] add `--no-git` option to `anchor init` to skip vcs setup --- cli/src/lib.rs | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/cli/src/lib.rs b/cli/src/lib.rs index ff643f293c..0181322039 100644 --- a/cli/src/lib.rs +++ b/cli/src/lib.rs @@ -64,6 +64,8 @@ pub enum Command { name: String, #[clap(short, long)] javascript: bool, + #[clap(long)] + no_git: bool, }, /// Builds the workspace. Build { @@ -363,7 +365,11 @@ pub enum ClusterCommand { pub fn entry(opts: Opts) -> Result<()> { match opts.command { - Command::Init { name, javascript } => init(&opts.cfg_override, name, javascript), + Command::Init { + name, + javascript, + no_git, + } => init(&opts.cfg_override, name, javascript, no_git), Command::New { name } => new(&opts.cfg_override, name), Command::Build { idl, @@ -461,7 +467,7 @@ pub fn entry(opts: Opts) -> Result<()> { } } -fn init(cfg_override: &ConfigOverride, name: String, javascript: bool) -> Result<()> { +fn init(cfg_override: &ConfigOverride, name: String, javascript: bool, no_git: bool) -> Result<()> { if Config::discover(cfg_override)?.is_some() { return Err(anyhow!("Workspace already initialized")); } @@ -574,14 +580,16 @@ fn init(cfg_override: &ConfigOverride, name: String, javascript: bool) -> Result println!("Failed to install node dependencies") } - let git_result = std::process::Command::new("git") - .arg("init") - .stdout(Stdio::inherit()) - .stderr(Stdio::inherit()) - .output() - .map_err(|e| anyhow::format_err!("git init failed: {}", e.to_string()))?; - if !git_result.status.success() { - eprintln!("Failed to automatically initialize a new git repository"); + if !no_git { + let git_result = std::process::Command::new("git") + .arg("init") + .stdout(Stdio::inherit()) + .stderr(Stdio::inherit()) + .output() + .map_err(|e| anyhow::format_err!("git init failed: {}", e.to_string()))?; + if !git_result.status.success() { + eprintln!("Failed to automatically initialize a new git repository"); + } } println!("{} initialized", name); From 17275a725a31e0ece5e9fb14a7e488aeb1c4d361 Mon Sep 17 00:00:00 2001 From: Paul Schaaf Date: Mon, 14 Mar 2022 11:42:20 -0400 Subject: [PATCH 4/4] update changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 95c88b5a1d..080b119de0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,7 +14,7 @@ incremented for features. ### Features * cli: Add `anchor clean` command that's the same as `cargo clean` but preserves keypairs inside `target/deploy` ([#1470](https://github.com/project-serum/anchor/issues/1470)). -* cli: Running `anchor init` now initializes a new git repository for the workspace ([#1605](https://github.com/project-serum/anchor/pull/1605)). +* cli: Running `anchor init` now initializes a new git repository for the workspace. This can be disabled with the `--no-git` flag ([#1605](https://github.com/project-serum/anchor/pull/1605)). * lang: Add new `AccountSysvarMismatch` error code and test cases for sysvars ([#1535](https://github.com/project-serum/anchor/pull/1535)). * spl: Add support for revoke instruction ([#1493](https://github.com/project-serum/anchor/pull/1493)). * ts: Add provider parameter to `Spl.token` factory method ([#1597](https://github.com/project-serum/anchor/pull/1597)).