Skip to content

Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows

docs+test(hooks): tighten "(else the primary)" wording; cover the no-config approval path (#2727)

Maximilian Roosc67803e8dd6a
diff --git a/src/commands/hooks.rs b/src/commands/hooks.rs
index 71f97c1f5..58d6eede6 100644
--- a/src/commands/hooks.rs
+++ b/src/commands/hooks.rs
@@ -19,7 +19,7 @@
//! | Hook | `ctx.repo` rooted at → config from | Set in |
//! |---|---|---|
//! | `pre-remove` | the worktree being removed (still on disk at hook time) | `output::handlers::execute_pre_remove_hooks_if_needed`; the three approval call sites (`main.rs`'s `approve_remove` for `wt remove`, `merge::collect_merge_commands` for `wt merge`, `step::prune::approve_prune_hooks` for `wt step prune`) all delegate to [`super::project_config::collect_remove_hook_commands`] |
-//! | `post-merge`, `post-remove`, `post-switch` after a removal | the destination — for `wt merge`, the target branch's worktree (else the primary); for `wt remove` / `wt step prune`, the primary worktree — the removed/feature worktree is gone by then | `worktree::finish::finish_after_merge`, `output::handlers::spawn_hooks_after_remove` (approval of `post-remove`/`post-switch` for the three remove flows runs through [`super::project_config::collect_remove_hook_commands`]; `post-merge` is added by `merge::collect_merge_commands` directly) |
+//! | `post-merge`, `post-remove`, `post-switch` after a removal | the post-removal working directory — for `wt remove` / `wt step prune` always the primary worktree; for `wt merge` the target branch's worktree if one exists, otherwise the primary (path choice for the destination, not a config fallback). The removed/feature worktree is gone by then. | `worktree::finish::finish_after_merge`, `output::handlers::spawn_hooks_after_remove` (approval of `post-remove`/`post-switch` for the three remove flows runs through [`super::project_config::collect_remove_hook_commands`]; `post-merge` is added by `merge::collect_merge_commands` directly) |
//! | `pre-commit` / `post-commit` | the worktree being committed — the cwd worktree, or `<b>`'s worktree for `wt step commit --branch <b>` | `commands::commit`, `step::commit` (via `CommandEnv::for_branch`) |
//! | `wt switch`'s `pre-start` / `post-start` / `post-switch` | the new (`--create`) or destination (`wt switch <existing>`) worktree, where these run. For `--create` the target doesn't exist yet at approval time, so the approval prompt and template pre-flight read its base ref's committed `.config/wt.toml` via `git show` (`git fetch`ing a `pr:`/`mr:` fork head first) — the new worktree, once created, is a checkout of that ref | `worktree::switch` — `hook_repo_for_worktree` (execution), `switch_hook_project_config` (approval / pre-flight) |
//! | `pre-switch`, `pre-merge`, `wt hook <type>`, aliases | the worktree `wt` was invoked in (= where they run) | the respective command entry points |
diff --git a/tests/integration_tests/remove.rs b/tests/integration_tests/remove.rs
index 3090207ab..d0bbf1d1f 100644
--- a/tests/integration_tests/remove.rs
+++ b/tests/integration_tests/remove.rs
@@ -1797,6 +1797,51 @@ fn test_remove_aborts_on_malformed_worktree_config(mut repo: TestRepo) {
);
}
+/// Removing a worktree that has no `.config/wt.toml` does NOT fall back to the
+/// primary worktree's config — neither for execution (per #2714) nor for
+/// approval (the shared `collect_remove_hook_commands` helper). Without `--yes`
+/// and without prior approval, the command must succeed (the approval prompt
+/// has no commands to surface) rather than block on the primary's `pre-remove`.
+#[rstest]
+fn test_remove_no_fallback_to_primary_pre_remove(mut repo: TestRepo) {
+ // Add the feature worktree first, off HEAD, so it doesn't carry the
+ // uncommitted config below.
+ let worktree_path = repo.add_worktree("feature-no-config");
+ let marker_file = repo.root_path().join("pre-remove-ran.txt");
+
+ // Primary worktree only — uncommitted, so `feature-no-config` doesn't
+ // inherit it.
+ repo.write_project_config(&format!(
+ r#"pre-remove = "echo ran > {}""#,
+ marker_file.to_slash_lossy()
+ ));
+
+ // No `--yes`: with the bug, the approval helper would surface the primary's
+ // `pre-remove` and `wt remove` would abort with "needs approval" because
+ // tests don't have a TTY. With the fix, the prompt is empty and removal
+ // proceeds. `--force` because the feature branch is unmerged.
+ let output = repo
+ .wt_command()
+ .args(["remove", "--foreground", "--force", "feature-no-config"])
+ .output()
+ .unwrap();
+ let stderr = String::from_utf8_lossy(&output.stderr);
+ assert!(
+ output.status.success(),
+ "wt remove should succeed when the removed worktree has no \
+ .config/wt.toml — no fallback to the primary's; stderr:\n{stderr}"
+ );
+ assert!(
+ !worktree_path.exists(),
+ "feature worktree should be removed"
+ );
+ assert!(
+ !marker_file.exists(),
+ "primary's pre-remove must not fire when the removed worktree has \
+ no .config/wt.toml"
+ );
+}
+
#[rstest]
fn test_pre_remove_hook_failure_aborts(mut repo: TestRepo) {
// Create project config with failing hook