From c9def31f50b47ebebde89c7d87d1e490e5b92def Mon Sep 17 00:00:00 2001 From: Juan Rigada <62958725+Jrigada@users.noreply.github.com> Date: Tue, 10 Dec 2024 17:50:27 -0300 Subject: [PATCH] fix: Add zkout to gitignore template when in zksync forge init mode (#772) * Add zkout to gitignore template when in zksync forge init mode * Add test for forge init --zksync --- crates/forge/bin/cmd/init.rs | 16 +++++++++++++++- crates/forge/tests/cli/cmd.rs | 13 +++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/crates/forge/bin/cmd/init.rs b/crates/forge/bin/cmd/init.rs index f6df102fd..ae8341e02 100644 --- a/crates/forge/bin/cmd/init.rs +++ b/crates/forge/bin/cmd/init.rs @@ -152,7 +152,7 @@ impl InitArgs { } } - // install forge-zksync-std + // NOTE(zk): install forge-zksync-std if zksync && !offline { if root.join("lib/forge-zksync-std").exists() { sh_println!("\"lib/forge-zksync-std\" already exists, skipping install....")?; @@ -161,6 +161,20 @@ impl InitArgs { let dep = "https://github.com/Moonsong-Labs/forge-zksync-std".parse()?; self.opts.install(&mut config, vec![dep])?; } + + //Add zkout/ to .gitignore under compiler files if it doesn't exist + let gitignore_path = root.join(".gitignore"); + if gitignore_path.exists() { + let mut content = fs::read_to_string(&gitignore_path)?; + if !content.contains("zkout/") { + // Find the compiler files section and add zkout/ + if let Some(pos) = content.find("out/") { + let insert_pos = pos + "out/".len(); + content.insert_str(insert_pos, "\nzkout/"); + fs::write(&gitignore_path, content)?; + } + } + } } // init vscode settings diff --git a/crates/forge/tests/cli/cmd.rs b/crates/forge/tests/cli/cmd.rs index 7a376678f..bf7f9f6d7 100644 --- a/crates/forge/tests/cli/cmd.rs +++ b/crates/forge/tests/cli/cmd.rs @@ -3203,3 +3203,16 @@ forgetest_init!(gas_report_include_tests, |prj, cmd| { .is_json(), ); }); + +forgetest_init!(zk_can_init_with_zksync, |prj, cmd| { + cmd.args(["init", "--zksync", "--force"]).assert_success(); + + // Check that zkout/ is in .gitignore + let gitignore_path = prj.root().join(".gitignore"); + assert!(gitignore_path.exists()); + let gitignore_contents = std::fs::read_to_string(&gitignore_path).unwrap(); + assert!(gitignore_contents.contains("zkout/")); + + // Assert that forge-zksync-std is installed + assert!(prj.root().join("lib/forge-zksync-std").exists()); +});