Skip to content

Commit c9def31

Browse files
authored
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
1 parent ab01854 commit c9def31

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

crates/forge/bin/cmd/init.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ impl InitArgs {
152152
}
153153
}
154154

155-
// install forge-zksync-std
155+
// NOTE(zk): install forge-zksync-std
156156
if zksync && !offline {
157157
if root.join("lib/forge-zksync-std").exists() {
158158
sh_println!("\"lib/forge-zksync-std\" already exists, skipping install....")?;
@@ -161,6 +161,20 @@ impl InitArgs {
161161
let dep = "https://github.com/Moonsong-Labs/forge-zksync-std".parse()?;
162162
self.opts.install(&mut config, vec![dep])?;
163163
}
164+
165+
//Add zkout/ to .gitignore under compiler files if it doesn't exist
166+
let gitignore_path = root.join(".gitignore");
167+
if gitignore_path.exists() {
168+
let mut content = fs::read_to_string(&gitignore_path)?;
169+
if !content.contains("zkout/") {
170+
// Find the compiler files section and add zkout/
171+
if let Some(pos) = content.find("out/") {
172+
let insert_pos = pos + "out/".len();
173+
content.insert_str(insert_pos, "\nzkout/");
174+
fs::write(&gitignore_path, content)?;
175+
}
176+
}
177+
}
164178
}
165179

166180
// init vscode settings

crates/forge/tests/cli/cmd.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3203,3 +3203,16 @@ forgetest_init!(gas_report_include_tests, |prj, cmd| {
32033203
.is_json(),
32043204
);
32053205
});
3206+
3207+
forgetest_init!(zk_can_init_with_zksync, |prj, cmd| {
3208+
cmd.args(["init", "--zksync", "--force"]).assert_success();
3209+
3210+
// Check that zkout/ is in .gitignore
3211+
let gitignore_path = prj.root().join(".gitignore");
3212+
assert!(gitignore_path.exists());
3213+
let gitignore_contents = std::fs::read_to_string(&gitignore_path).unwrap();
3214+
assert!(gitignore_contents.contains("zkout/"));
3215+
3216+
// Assert that forge-zksync-std is installed
3217+
assert!(prj.root().join("lib/forge-zksync-std").exists());
3218+
});

0 commit comments

Comments
 (0)