Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
Implement `--no-verify` flag for merge command
Maximilian Roos3f3dacb3c03d
diff --git a/README.md b/README.mdindex e0c3c4543..caa710e24 100644--- a/README.md+++ b/README.md@@ -1,7 +1,6 @@# Worktrunk[](https://opensource.org/licenses/MIT)-[](https://crates.io/crates/worktrunk)Git worktree lifecycle automation, designed around running concurrent AI coding agents.diff --git a/src/commands/merge.rs b/src/commands/merge.rsindex a123ac0ce..af248127e 100644--- a/src/commands/merge.rs+++ b/src/commands/merge.rs@@ -41,16 +41,15 @@ impl<'a> MergeCommandCollector<'a> {// These run before: (1) direct commit (line 179), or (2) squash commit (line 194 β handle_dev_squash)let mut hooks = Vec::new();- if !self.no_commit && self.repo.is_dirty()? {+ if !self.no_commit && !self.no_verify && self.repo.is_dirty()? {hooks.push(HookType::PreCommit);}if !self.no_verify {hooks.push(HookType::PreMerge);+ hooks.push(HookType::PostMerge);}- hooks.push(HookType::PostMerge);-all_commands.extend(collect_commands_for_hooks(&project_config, &hooks));let project_id = self.repo.project_identifier()?;@@ -208,20 +207,22 @@ pub fn handle_merge(handle_merge_summary_output(None)?;}- // Execute post-merge commands in the main worktree- // This runs after cleanup so the context is clear to the user- // Create a fresh Repository instance at the primary worktree (the old repo may be invalid)- let primary_repo = Repository::at(&primary_worktree_dir);- let primary_repo_root = primary_worktree_dir.clone();- let ctx = CommandContext::new(- &primary_repo,- config,- ¤t_branch,- &primary_worktree_dir,- &primary_repo_root,- force,- );- execute_post_merge_commands(&ctx, &target_branch)?;+ if !no_verify {+ // Execute post-merge commands in the main worktree+ // This runs after cleanup so the context is clear to the user+ // Create a fresh Repository instance at the primary worktree (the old repo may be invalid)+ let primary_repo = Repository::at(&primary_worktree_dir);+ let primary_repo_root = primary_worktree_dir.clone();+ let ctx = CommandContext::new(+ &primary_repo,+ config,+ ¤t_branch,+ &primary_worktree_dir,+ &primary_repo_root,+ force,+ );+ execute_post_merge_commands(&ctx, &target_branch)?;+ }Ok(())}diff --git a/tests/integration_tests/merge.rs b/tests/integration_tests/merge.rsindex a8b03b324..b02eacb48 100644--- a/tests/integration_tests/merge.rs+++ b/tests/integration_tests/merge.rs@@ -1212,6 +1212,66 @@ fn test_merge_post_merge_command_success() {);}+#[test]+fn test_merge_post_merge_command_skipped_with_no_verify() {+ let mut repo = TestRepo::new();+ repo.commit("Initial commit");+ repo.setup_remote("main");++ // Create project config with post-merge command that writes a marker file+ let config_dir = repo.root_path().join(".config");+ fs::create_dir_all(&config_dir).expect("Failed to create config dir");+ fs::write(+ config_dir.join("wt.toml"),+ r#"post-merge-command = "echo 'merged {branch} to {target}' > post-merge-ran.txt""#,+ )+ .expect("Failed to write config");++ repo.commit("Add config");++ // Create a worktree for main+ let main_wt = repo.root_path().parent().unwrap().join("test-repo.main-wt");+ let mut cmd = Command::new("git");+ repo.configure_git_cmd(&mut cmd);+ cmd.args(["worktree", "add", main_wt.to_str().unwrap(), "main"])+ .current_dir(repo.root_path())+ .output()+ .expect("Failed to add worktree");++ // Create a feature worktree and make a commit+ let feature_wt = repo.add_worktree("feature", "feature");+ fs::write(feature_wt.join("feature.txt"), "feature content").expect("Failed to write file");++ let mut cmd = Command::new("git");+ repo.configure_git_cmd(&mut cmd);+ cmd.args(["add", "feature.txt"])+ .current_dir(&feature_wt)+ .output()+ .expect("Failed to add file");++ let mut cmd = Command::new("git");+ repo.configure_git_cmd(&mut cmd);+ cmd.args(["commit", "-m", "Add feature file"])+ .current_dir(&feature_wt)+ .output()+ .expect("Failed to commit");++ // Merge with --no-verify - hook should be skipped entirely+ snapshot_merge(+ "merge_post_merge_command_no_verify",+ &repo,+ &["main", "--force", "--no-verify"],+ Some(&feature_wt),+ );++ // Verify the command did not run in the main worktree+ let marker_file = repo.root_path().join("post-merge-ran.txt");+ assert!(+ !marker_file.exists(),+ "Post-merge command should not run when --no-verify is set"+ );+}+#[test]fn test_merge_post_merge_command_failure() {let mut repo = TestRepo::new();diff --git a/tests/snapshots/integration__integration_tests__merge__merge_post_merge_command_no_verify.snap b/tests/snapshots/integration__integration_tests__merge__merge_post_merge_command_no_verify.snapnew file mode 100644index 000000000..e0e583126--- /dev/null+++ b/tests/snapshots/integration__integration_tests__merge__merge_post_merge_command_no_verify.snap@@ -0,0 +1,34 @@+---+source: tests/integration_tests/merge.rs+info:+ program: wt+ args:+ - merge+ - main+ - "--force"+ - "--no-verify"+ env:+ CLICOLOR_FORCE: "1"+ COLUMNS: "150"+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"+ GIT_CONFIG_GLOBAL: /dev/null+ GIT_CONFIG_SYSTEM: /dev/null+ LANG: C+ LC_ALL: C+ SOURCE_DATE_EPOCH: "1761609600"+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpUCbYQE/test-config.toml+---+success: true+exit_code: 0+----- stdout -----+π [36mMerging 1 commit to [1m[36mmain[0m[36m @ [2m[SHA][0m (no commit/squash/rebase needed)++[40m [0m * [SHA][33m ([m[1;36mHEAD[m[33m -> [m[1;32mfeature[m[33m)[m Add feature file+[40m [0m feature.txt | 1 [32m+[m+[40m [0m 1 file changed, 1 insertion(+)+β [32mMerged to [1m[32mmain[0m[0m (1 commit, 1 file, [32m+1[0m)+π [36mRemoving worktree & branch...[0m+β [32mRemoved worktree & branch for [1m[32mfeature[0m[32m, returned to primary at [1m[32m[REPO][0m[0m++----- stderr -----