Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
fix: add missing context to hook show outside git repo (#1809)
Axel H.0d809defaa7d
diff --git a/src/commands/hook_commands.rs b/src/commands/hook_commands.rsindex 9db774da2..245d25fa2 100644--- a/src/commands/hook_commands.rs+++ b/src/commands/hook_commands.rs@@ -432,7 +432,7 @@ pub fn clear_approvals(global: bool) -> anyhow::Result<()> {pub fn handle_hook_show(hook_type_filter: Option<&str>, expanded: bool) -> anyhow::Result<()> {use crate::help_pager::show_help_in_pager;- let repo = Repository::current()?;+ let repo = Repository::current().context("Failed to show hooks")?;let config = UserConfig::load().context("Failed to load user config")?;let approvals = Approvals::load().context("Failed to load approvals")?;let project_config = repo.load_project_config()?;diff --git a/tests/common/mod.rs b/tests/common/mod.rsindex 556bc0db8..7913015e6 100644--- a/tests/common/mod.rs+++ b/tests/common/mod.rs@@ -2909,6 +2909,14 @@ pub fn setup_home_snapshot_settings(temp_home: &TempDir) -> insta::Settings {settings.add_filter(r"(?m)^.*for powershell .*\n", "");// Normalize Windows executable extension in help outputsettings.add_filter(r"wt\.exe", "wt");+ // Normalize git "not a git repository" messages across environments.+ // Local: "fatal: not a git repository (or any parent up to mount point /)\n+ // Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set)."+ // CI/Docker: "fatal: not a git repository (or any of the parent directories): .git"+ settings.add_filter(+ r"fatal: not a git repository \(or any[^\n]*(?:\n[^\n]*filesystem boundary[^\n]*)?",+ "fatal: not a git repository [GIT_DISCOVERY_MSG]",+ );add_standard_env_redactions(&mut settings);diff --git a/tests/snapshots/integration__integration_tests__hook_show__error_with_context_formatting.snap b/tests/snapshots/integration__integration_tests__hook_show__error_with_context_formatting.snapindex 1259d3e4b..b09f74d43 100644--- a/tests/snapshots/integration__integration_tests__hook_show__error_with_context_formatting.snap+++ b/tests/snapshots/integration__integration_tests__hook_show__error_with_context_formatting.snap@@ -8,19 +8,26 @@ info:APPDATA: "[TEST_CONFIG_HOME]"CLICOLOR_FORCE: "1"COLUMNS: "500"- GIT_EDITOR: ""+ GIT_BRANCH_ICON: ""+ GIT_DIR_ICON: ""+ GIT_REMOTE_BRANCH_ICON: ""+ GIT_WORKTREE_ICON: ""HOME: "[TEST_HOME]"LANG: CLC_ALL: C+ NO_COLOR: ""PSModulePath: ""RUST_LOG: warnSHELL: ""TERM: alacrittyUSERPROFILE: "[TEST_HOME]"+ WORKTRUNK_APPROVALS_PATH: "[TEST_APPROVALS]"WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"+ WORKTRUNK_SYSTEM_CONFIG_PATH: "[TEST_SYSTEM_CONFIG]"WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"WORKTRUNK_TEST_EPOCH: "1735776000"+ WORKTRUNK_TEST_NUSHELL_ENV: "0"WORKTRUNK_TEST_POWERSHELL_ENV: "0"WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"@@ -31,4 +38,4 @@ exit_code: 1----- stderr -----[31m✗[39m [31mFailed to remove worktree[39m-[107m [0m fatal: not a git repository (or any of the parent directories): .git+[107m [0m fatal: not a git repository [GIT_DISCOVERY_MSG]diff --git a/tests/snapshots/integration__integration_tests__hook_show__hook_show_outside_git_repo.snap b/tests/snapshots/integration__integration_tests__hook_show__hook_show_outside_git_repo.snapindex 2493b594f..d48717734 100644--- a/tests/snapshots/integration__integration_tests__hook_show__hook_show_outside_git_repo.snap+++ b/tests/snapshots/integration__integration_tests__hook_show__hook_show_outside_git_repo.snap@@ -9,19 +9,26 @@ info:APPDATA: "[TEST_CONFIG_HOME]"CLICOLOR_FORCE: "1"COLUMNS: "500"- GIT_EDITOR: ""+ GIT_BRANCH_ICON: ""+ GIT_DIR_ICON: ""+ GIT_REMOTE_BRANCH_ICON: ""+ GIT_WORKTREE_ICON: ""HOME: "[TEST_HOME]"LANG: CLC_ALL: C+ NO_COLOR: ""PSModulePath: ""RUST_LOG: warnSHELL: ""TERM: alacrittyUSERPROFILE: "[TEST_HOME]"+ WORKTRUNK_APPROVALS_PATH: "[TEST_APPROVALS]"WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"+ WORKTRUNK_SYSTEM_CONFIG_PATH: "[TEST_SYSTEM_CONFIG]"WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"WORKTRUNK_TEST_EPOCH: "1735776000"+ WORKTRUNK_TEST_NUSHELL_ENV: "0"WORKTRUNK_TEST_POWERSHELL_ENV: "0"WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"@@ -31,4 +38,5 @@ exit_code: 1----- stdout ---------- stderr ------[31m✗[39m [31mfatal: not a git repository (or any of the parent directories): .git[39m+[31m✗[39m [31mFailed to show hooks[39m+[107m [0m fatal: not a git repository [GIT_DISCOVERY_MSG]diff --git a/tests/snapshots/integration__integration_tests__switch__switch_outside_git_repo.snap b/tests/snapshots/integration__integration_tests__switch__switch_outside_git_repo.snapindex 843053cf1..7edfbe6c7 100644--- a/tests/snapshots/integration__integration_tests__switch__switch_outside_git_repo.snap+++ b/tests/snapshots/integration__integration_tests__switch__switch_outside_git_repo.snap@@ -10,19 +10,26 @@ info:APPDATA: "[TEST_CONFIG_HOME]"CLICOLOR_FORCE: "1"COLUMNS: "500"- GIT_EDITOR: ""+ GIT_BRANCH_ICON: ""+ GIT_DIR_ICON: ""+ GIT_REMOTE_BRANCH_ICON: ""+ GIT_WORKTREE_ICON: ""HOME: "[TEST_HOME]"LANG: CLC_ALL: C+ NO_COLOR: ""PSModulePath: ""RUST_LOG: warnSHELL: ""TERM: alacrittyUSERPROFILE: "[TEST_HOME]"+ WORKTRUNK_APPROVALS_PATH: "[TEST_APPROVALS]"WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"+ WORKTRUNK_SYSTEM_CONFIG_PATH: "[TEST_SYSTEM_CONFIG]"WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"WORKTRUNK_TEST_EPOCH: "1735776000"+ WORKTRUNK_TEST_NUSHELL_ENV: "0"WORKTRUNK_TEST_POWERSHELL_ENV: "0"WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"@@ -33,4 +40,4 @@ exit_code: 1----- stderr -----[31m✗[39m [31mFailed to switch worktree[39m-[107m [0m fatal: not a git repository (or any of the parent directories): .git+[107m [0m fatal: not a git repository [GIT_DISCOVERY_MSG]