#![cfg(unix)]
mod common;
use common::TestRepo;
#[test]
fn post_new_nonzero_exit_fails_gw_new() {
let repo = TestRepo::new();
std::fs::write(
repo.path().join(".cwconfig.json"),
r#"{"hooks":{"post_new":"exit 7"}}"#,
)
.unwrap();
let out = repo.cw(&["new", "feat-postnew-fail", "--no-term"]);
assert!(
!out.status.success(),
"gw new should fail when post_new exits non-zero. stdout={:?} stderr={:?}",
String::from_utf8_lossy(&out.stdout),
String::from_utf8_lossy(&out.stderr),
);
let stderr = String::from_utf8_lossy(&out.stderr);
assert!(
stderr.contains("post_new"),
"stderr should mention post_new failure, got: {:?}",
stderr
);
}
#[test]
fn pre_rm_fires_with_force_flag() {
let repo = TestRepo::new();
let _ = repo.create_worktree("feat-prerm-force");
let marker_dir = tempfile::tempdir().expect("marker tempdir");
let marker = marker_dir.path().join("pre_rm-fired");
let cfg = format!(r#"{{"hooks":{{"pre_rm":"touch '{}'"}}}}"#, marker.display());
std::fs::write(repo.path().join(".cwconfig.json"), cfg).unwrap();
let out = repo.cw(&["rm", "feat-prerm-force", "--force"]);
assert!(
out.status.success(),
"gw rm --force should succeed. stdout={:?} stderr={:?}",
String::from_utf8_lossy(&out.stdout),
String::from_utf8_lossy(&out.stderr),
);
assert!(
marker.exists(),
"pre_rm hook should have fired even with --force"
);
}
#[test]
fn pre_rm_nonzero_exit_aborts_rm_with_force() {
let repo = TestRepo::new();
let wt_path = repo.create_worktree("feat-prerm-abort");
std::fs::write(
repo.path().join(".cwconfig.json"),
r#"{"hooks":{"pre_rm":"exit 9"}}"#,
)
.unwrap();
let out = repo.cw(&["rm", "feat-prerm-abort", "--force"]);
assert!(
!out.status.success(),
"gw rm --force should fail when pre_rm exits non-zero"
);
assert!(
wt_path.exists(),
"worktree dir should still exist after pre_rm aborted the remove"
);
}