Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
fix: align all pre-* hooks to FailFast — no exceptions (#1708)
worktrunk-botf8b80afd94cd
diff --git a/docs/content/hook.md b/docs/content/hook.mdindex b61935419..8d1d3979d 100644--- a/docs/content/hook.md+++ b/docs/content/hook.md@@ -23,7 +23,7 @@ Hooks are shell commands that run at key points in the worktree lifecycle — au| **merge** | `pre-merge` | `post-merge` || **remove** | `pre-remove` | `post-remove` |-`pre-*` hooks block — failure aborts the operation (except `pre-start`, which warns and continues). `post-*` hooks run in the background with output logged to `.git/wt/logs/{branch}-{source}-{hook}-{name}.log`. Use `-v` to see expanded command details for background hooks.+`pre-*` hooks block — failure aborts the operation. `post-*` hooks run in the background with output logged to `.git/wt/logs/{branch}-{source}-{hook}-{name}.log`. Use `-v` to see expanded command details for background hooks.The most common starting point is `post-start` — it runs background tasks (dev servers, file copying, builds) when creating a worktree.diff --git a/skills/worktrunk/reference/hook.md b/skills/worktrunk/reference/hook.mdindex 7ad732919..4c75d329f 100644--- a/skills/worktrunk/reference/hook.md+++ b/skills/worktrunk/reference/hook.md@@ -14,7 +14,7 @@ Hooks are shell commands that run at key points in the worktree lifecycle — au| **merge** | `pre-merge` | `post-merge` || **remove** | `pre-remove` | `post-remove` |-`pre-*` hooks block — failure aborts the operation (except `pre-start`, which warns and continues). `post-*` hooks run in the background with output logged to `.git/wt/logs/{branch}-{source}-{hook}-{name}.log`. Use `-v` to see expanded command details for background hooks.+`pre-*` hooks block — failure aborts the operation. `post-*` hooks run in the background with output logged to `.git/wt/logs/{branch}-{source}-{hook}-{name}.log`. Use `-v` to see expanded command details for background hooks.The most common starting point is `post-start` — it runs background tasks (dev servers, file copying, builds) when creating a worktree.diff --git a/src/cli/mod.rs b/src/cli/mod.rsindex 625f37ce1..0d4ceaa53 100644--- a/src/cli/mod.rs+++ b/src/cli/mod.rs@@ -1114,7 +1114,7 @@ Alias names that match a built-in step command (`commit`, `squash`, etc.) are sh| **merge** | `pre-merge` | `post-merge` || **remove** | `pre-remove` | `post-remove` |-`pre-*` hooks block — failure aborts the operation (except `pre-start`, which warns and continues). `post-*` hooks run in the background with output logged to `.git/wt/logs/{branch}-{source}-{hook}-{name}.log`. Use `-v` to see expanded command details for background hooks.+`pre-*` hooks block — failure aborts the operation. `post-*` hooks run in the background with output logged to `.git/wt/logs/{branch}-{source}-{hook}-{name}.log`. Use `-v` to see expanded command details for background hooks.The most common starting point is `post-start` — it runs background tasks (dev servers, file copying, builds) when creating a worktree.diff --git a/src/commands/worktree/hooks.rs b/src/commands/worktree/hooks.rsindex 1990bcdb4..298d89404 100644--- a/src/commands/worktree/hooks.rs+++ b/src/commands/worktree/hooks.rs@@ -25,7 +25,7 @@ impl<'a> CommandContext<'a> {self,HookType::PreStart,extra_vars,- HookFailureStrategy::Warn,+ HookFailureStrategy::FailFast,None,crate::output::post_hook_display_path(self.worktree_path),)diff --git a/tests/integration_tests/post_start_commands.rs b/tests/integration_tests/post_start_commands.rsindex 143488fd7..3ae7f344b 100644--- a/tests/integration_tests/post_start_commands.rs+++ b/tests/integration_tests/post_start_commands.rs@@ -108,7 +108,7 @@ approved-commands = ["exit 1"]"#,);- // Should show warning but continue (worktree should still be created)+ // Failing pre-start hook (via deprecated post-create name) aborts with FailFastsnapshot_switch("post_create_failing_command",&repo,diff --git a/tests/integration_tests/user_hooks.rs b/tests/integration_tests/user_hooks.rsindex ef369d72d..b6620570b 100644--- a/tests/integration_tests/user_hooks.rs+++ b/tests/integration_tests/user_hooks.rs@@ -165,14 +165,16 @@ failing = "exit 1""#,);- // Failing user hook should produce warning but not block creation+ // Failing pre-start hook (via deprecated post-create name) aborts with FailFast.+ // The worktree is already created before pre-start runs (it was renamed from+ // post-create), so the worktree exists but the command exits non-zero.snapshot_switch("user_post_create_failure", &repo, &["--create", "feature"]);- // Worktree should still be created despite hook failure+ // Worktree exists (created before pre-start ran) but the command failedlet worktree_path = repo.root_path().parent().unwrap().join("repo.feature");assert!(worktree_path.exists(),- "Worktree should be created even if post-create hook fails"+ "Worktree should exist — it was created before pre-start ran");}@@ -1125,6 +1127,24 @@ fn test_standalone_hook_post_create(repo: TestRepo) {assert!(content.contains("STANDALONE_POST_CREATE"));}+#[rstest]+fn test_standalone_hook_pre_start_fails_on_failure(repo: TestRepo) {+ // pre-start hooks use FailFast like all other pre-* hooks — consistent with+ // the symmetric pre (blocking, fail-fast) / post (background, warn) pattern.+ repo.write_project_config(r#"pre-start = "exit 1""#);++ let output = repo+ .wt_command()+ .args(["hook", "pre-start", "--yes"])+ .output()+ .unwrap();++ assert!(+ !output.status.success(),+ "wt hook pre-start should exit non-zero when the hook fails (fail-fast, like all pre-* hooks)"+ );+}+#[rstest]fn test_standalone_hook_post_start(repo: TestRepo) {// Write project config with post-start hookdiff --git a/tests/snapshots/integration__integration_tests__post_start_commands__post_create_failing_command.snap b/tests/snapshots/integration__integration_tests__post_start_commands__post_create_failing_command.snapindex aae955ba5..28d150025 100644--- a/tests/snapshots/integration__integration_tests__post_start_commands__post_create_failing_command.snap+++ b/tests/snapshots/integration__integration_tests__post_start_commands__post_create_failing_command.snap@@ -38,16 +38,13 @@ info:WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"----success: true-exit_code: 0+success: false+exit_code: 1----- stdout ---------- stderr -----[33m▲[39m [33mProject config has deprecated settings. Run [1mwt config show[22m for details or [1mwt config update[22m to apply updates[39m[36m◎[39m [36mRunning pre-start project hook @ [1m_REPO_.feature[22m[39m[107m [0m [2m[0m[2m[34mexit[0m[2m 1-[0m[31m✗[39m [31mCommand failed: exit status: 1[39m-[32m✓[39m [32mCreated branch [1mfeature[22m from [1mmain[22m and worktree @ [1m_REPO_.feature[22m[39m-[2m↳[22m [2mTo customize worktree locations, run [4mwt config create[24m[22m-[33m▲[39m [33mCannot change directory — shell integration not installed[39m-[2m↳[22m [2mTo enable automatic cd, run [4mwt config shell install[24m[22m+[0m[31m✗[39m [31mpre-start command failed: exit status: 1[39m+[2m↳[22m [2mTo skip pre-start hooks, re-run with [4m--no-verify[24m[22mdiff --git a/tests/snapshots/integration__integration_tests__user_hooks__user_post_create_failure.snap b/tests/snapshots/integration__integration_tests__user_hooks__user_post_create_failure.snapindex 568e37ebb..546461185 100644--- a/tests/snapshots/integration__integration_tests__user_hooks__user_post_create_failure.snap+++ b/tests/snapshots/integration__integration_tests__user_hooks__user_post_create_failure.snap@@ -38,16 +38,13 @@ info:WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"----success: true-exit_code: 0+success: false+exit_code: 1----- stdout ---------- stderr -----[33m▲[39m [33mUser config has deprecated settings. Run [1mwt config show[22m for details or [1mwt config update[22m to apply updates[39m[36m◎[39m [36mRunning pre-start [1muser:failing[22m @ [1m_REPO_.feature[22m[39m[107m [0m [2m[0m[2m[34mexit[0m[2m 1-[0m[31m✗[39m [31mCommand [1mfailing[22m failed: exit status: 1[39m-[32m✓[39m [32mCreated branch [1mfeature[22m from [1mmain[22m and worktree @ [1m_REPO_.feature[22m[39m-[2m↳[22m [2mTo customize worktree locations, run [4mwt config create[24m[22m-[33m▲[39m [33mCannot change directory — shell integration not installed[39m-[2m↳[22m [2mTo enable automatic cd, run [4mwt config shell install[24m[22m+[0m[31m✗[39m [31mpre-start command failed: [1mfailing[22m: exit status: 1[39m+[2m↳[22m [2mTo skip pre-start hooks, re-run with [4m--no-verify[24m[22m