Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
fix(hook show): merge per-project user hooks into display (#2844)
Worktrunk Bot2b0077b64206
diff --git a/src/commands/hook_commands.rs b/src/commands/hook_commands.rsindex 6215ce062..72e8d3e38 100644--- a/src/commands/hook_commands.rs+++ b/src/commands/hook_commands.rs@@ -421,7 +421,13 @@ pub fn handle_hook_show(let mut output = String::new();// Render user hooks- render_user_hooks(&mut output, config, filter, ctx.as_ref())?;+ render_user_hooks(+ &mut output,+ config,+ project_id.as_deref(),+ filter,+ ctx.as_ref(),+ )?;output.push('\n');// Render project hooks@@ -492,8 +498,8 @@ fn emit_hook_show_json(Ok(())};- // User hooks- let user_hooks = &user_config.hooks;+ // User hooks (merge global + per-project so the listing matches what runs)+ let user_hooks = user_config.hooks(project_id);for hook_type in HookType::iter() {if let Some(f) = filter&& f != hook_type@@ -527,6 +533,7 @@ fn emit_hook_show_json(fn render_user_hooks(out: &mut String,config: &UserConfig,+ project_id: Option<&str>,filter: Option<HookType>,ctx: Option<&CommandContext>,) -> anyhow::Result<()> {@@ -546,10 +553,9 @@ fn render_user_hooks())?;- // Collect all user hooks (global hooks from the user config file)- // Note: uses overrides.hooks for display, not the merged hooks() accessor.- // get() handles the post-create → pre-start deprecation merge.- let user_hooks = &config.hooks;+ // Merge global and per-project user hooks so display matches what+ // actually runs (the execution path also uses `config.hooks(project_id)`).+ let user_hooks = config.hooks(project_id);let hooks: Vec<_> = HookType::iter().filter_map(|ht| user_hooks.get(ht).map(|cfg| (ht, cfg))).collect();diff --git a/tests/integration_tests/hook_show.rs b/tests/integration_tests/hook_show.rsindex 8d7448aef..0f45806cb 100644--- a/tests/integration_tests/hook_show.rs+++ b/tests/integration_tests/hook_show.rs@@ -232,6 +232,47 @@ approved-commands = ["cargo build"]});}+/// Hooks defined under `[projects."<id>"]` in the user config must show up+/// in `wt hook show` alongside global user hooks, matching the merged set+/// that the execution path actually runs.+#[rstest]+fn test_hook_show_merges_user_project_hooks(repo: TestRepo, temp_home: TempDir) {+ // Remove origin so project_identifier falls back to the canonical path+ repo.run_git(&["remote", "remove", "origin"]);+ let project_id_str = repo.project_id();++ let canonical_home = crate::common::canonicalize(temp_home.path())+ .unwrap_or_else(|_| temp_home.path().to_path_buf());+ let global_config_dir = canonical_home.join(".config").join("worktrunk");+ fs::create_dir_all(&global_config_dir).unwrap();+ let config_path = global_config_dir.join("config.toml");+ fs::write(+ &config_path,+ format!(+ r#"worktree-path = "../{{{{ repo }}}}.{{{{ branch }}}}"++[post-start]+global-hook = "echo global"++[projects.'{project_id_str}'.post-start]+project-hook = "echo per-project"+"#+ ),+ )+ .unwrap();++ let settings = setup_snapshot_settings_with_home(&repo, &temp_home);+ settings.bind(|| {+ let mut cmd = wt_command();+ repo.configure_wt_cmd(&mut cmd);+ cmd.env("WORKTRUNK_CONFIG_PATH", &config_path);+ cmd.arg("hook").arg("show").current_dir(repo.root_path());+ set_temp_home_env(&mut cmd, temp_home.path());++ assert_cmd_snapshot!(cmd);+ });+}+#[rstest]fn test_error_with_context_formatting(temp_home: TempDir) {let temp_dir = tempfile::tempdir().unwrap();diff --git a/tests/snapshots/integration__integration_tests__hook_show__hook_show_merges_user_project_hooks.snap b/tests/snapshots/integration__integration_tests__hook_show__hook_show_merges_user_project_hooks.snapnew file mode 100644index 000000000..179ca8eea--- /dev/null+++ b/tests/snapshots/integration__integration_tests__hook_show__hook_show_merges_user_project_hooks.snap@@ -0,0 +1,66 @@+---+source: tests/integration_tests/hook_show.rs+info:+ program: wt+ args:+ - hook+ - show+ env:+ APPDATA: "[TEST_CONFIG_HOME]"+ CLICOLOR_FORCE: "1"+ COLUMNS: "500"+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"+ GIT_COMMON_DIR: ""+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"+ GIT_CONFIG_SYSTEM: /dev/null+ GIT_DIR: ""+ GIT_EDITOR: ""+ GIT_INDEX_FILE: ""+ GIT_OBJECT_DIRECTORY: ""+ GIT_TERMINAL_PROMPT: "0"+ GIT_WORK_TREE: ""+ HOME: "[TEST_HOME]"+ LANG: C+ LC_ALL: C+ LLVM_PROFILE_FILE: "[LLVM_PROFILE_FILE]"+ MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"+ NO_COLOR: ""+ OPENCODE_CONFIG_DIR: "[TEST_OPENCODE_CONFIG]"+ PATH: "[PATH]"+ PSModulePath: ""+ RUST_LOG: warn+ SHELL: ""+ TERM: alacritty+ USERPROFILE: "[TEST_HOME]"+ WORKTRUNK_APPROVALS_PATH: "[TEST_APPROVALS]"+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"+ WORKTRUNK_SYSTEM_CONFIG_PATH: "[TEST_SYSTEM_CONFIG]"+ WORKTRUNK_TEST_BASH_INSTALLED: "0"+ WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"+ WORKTRUNK_TEST_CODEX_INSTALLED: "0"+ WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"+ WORKTRUNK_TEST_EPOCH: "1735776000"+ WORKTRUNK_TEST_FISH_INSTALLED: "0"+ WORKTRUNK_TEST_GEMINI_INSTALLED: "0"+ WORKTRUNK_TEST_NUSHELL_ENV: "0"+ WORKTRUNK_TEST_OPENCODE_INSTALLED: "0"+ WORKTRUNK_TEST_POWERSHELL_ENV: "0"+ WORKTRUNK_TEST_POWERSHELL_INSTALLED: "0"+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"+ WORKTRUNK_TEST_ZSH_INSTALLED: "0"+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"+---+success: true+exit_code: 0+----- stdout -----+[36mUSER HOOKS[39m @ ~/.config/worktrunk/config.toml+[2m○[22m post-start [1mglobal-hook[22m:+[107m [0m [2m[0m[2m[34mecho[0m[2m global+[2m○[22m post-start [1mproject-hook[22m:+[107m [0m [2m[0m[2m[34mecho[0m[2m per-project++[36mPROJECT HOOKS[39m @ _REPO_/.config/wt.toml+[2m↳[22m [2m(not found)[22m++----- stderr -----