Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
fix: exit 0 when wt hook has no hooks configured (#2056)
Worktrunk Botabe8854ae7d1
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex c268caf90..f991c57eb 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -8,6 +8,10 @@- **Fewer redundant `git worktree list` calls in prune and multi-remove**: `prepare_worktree_removal()` now accepts a pre-fetched worktree list, eliminating N+1 subprocess calls when removing many worktrees. ([#2025](https://github.com/max-sixty/worktrunk/pull/2025))+### Changed++- **`wt hook <type>` exits successfully when no hooks are configured**: Previously `wt hook pre-merge` (and every other hook type) errored when neither the user nor the project config defined hooks of that type. It now prints a warning and exits 0, so scripts and CI can invoke `wt hook` unconditionally without special-casing empty configuration. ([#2055](https://github.com/max-sixty/worktrunk/issues/2055))+### Fixed- **Picker preview UI lag**: The picker's preview cache now stores pager-rendered output, so cache hits skip the pager subprocess entirely. Previously, scrolling past an item with a large diff froze the UI briefly on every re-render because the pager ran on every call. ([#2021](https://github.com/max-sixty/worktrunk/pull/2021))diff --git a/src/commands/hook_commands.rs b/src/commands/hook_commands.rsindex 012eed7b6..2c6dbe50d 100644--- a/src/commands/hook_commands.rs+++ b/src/commands/hook_commands.rs@@ -18,7 +18,7 @@ use worktrunk::git::{GitError, Repository};use worktrunk::path::format_path_for_display;use worktrunk::styling::{INFO_SYMBOL, PROMPT_SYMBOL, eprintln, format_bash_with_gutter, format_heading, hint_message,- info_message, success_message,+ info_message, success_message, warning_message,};use super::command_approval::approve_hooks_filtered;@@ -210,28 +210,22 @@ pub fn run_hook(.map(|(k, v)| (k.as_str(), v.as_str())).collect();- /// Helper to require at least one hook is configured (for standalone `wt hook` command)- fn require_hooks(- user: Option<&CommandConfig>,- project: Option<&CommandConfig>,- hook_type: HookType,- ) -> anyhow::Result<()> {- if user.is_none() && project.is_none() {- return Err(worktrunk::git::GitError::Other {- message: format!("No {hook_type} hook configured; checked both user and project"),- }- .into());- }- Ok(())- }-// Get effective user hooks (global + per-project merged)let user_hooks = ctx.config.hooks(ctx.project_id().as_deref());let (user_config, proj_config) = (user_hooks.get(hook_type),project_config.as_ref().and_then(|c| c.hooks.get(hook_type)),);- require_hooks(user_config, proj_config, hook_type)?;+ // No hooks configured: warn and exit successfully. Running hooks that+ // don't exist is a no-op, so scripts can invoke `wt hook <type>`+ // unconditionally without special-casing empty configuration.+ if user_config.is_none() && proj_config.is_none() {+ eprintln!(+ "{}",+ warning_message(format!("No {hook_type} hooks configured"))+ );+ return Ok(());+ }// Build extra vars per hook type (shared by dry-run and execution paths)let default_branch = repo.default_branch();diff --git a/tests/integration_tests/user_hooks.rs b/tests/integration_tests/user_hooks.rsindex 983d6f6a6..f69e7360a 100644--- a/tests/integration_tests/user_hooks.rs+++ b/tests/integration_tests/user_hooks.rs@@ -1439,7 +1439,8 @@ fn test_standalone_hook_post_remove_foreground(repo: TestRepo) {#[rstest]fn test_standalone_hook_no_hooks_configured(repo: TestRepo) {- // No project config, no user config with hooks+ // No project config, no user config with hooks: `wt hook` should exit 0+ // with a warning — running hooks that don't exist is a no-op, not an error.let mut cmd = crate::common::wt_command();cmd.current_dir(repo.root_path());cmd.env("WORKTRUNK_CONFIG_PATH", repo.test_config_path());@@ -1447,14 +1448,15 @@ fn test_standalone_hook_no_hooks_configured(repo: TestRepo) {let output = cmd.output().unwrap();assert!(- !output.status.success(),- "wt hook should fail when no hooks configured"+ output.status.success(),+ "wt hook should exit 0 when no hooks configured, got: {}",+ String::from_utf8_lossy(&output.stderr));let stderr = String::from_utf8_lossy(&output.stderr);assert!(- stderr.contains("No pre-start hook configured"),- "Error should mention no hook configured, got: {stderr}"+ stderr.contains("No pre-start hooks configured"),+ "stderr should warn about missing hooks, got: {stderr}");}