Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
fix(hooks): propagate Repository::at errors in pre-remove config resolution (#2708)
Maximilian Rooscbe372795800
diff --git a/src/commands/step/prune.rs b/src/commands/step/prune.rsindex 2f7ac9746..74c617af6 100644--- a/src/commands/step/prune.rs+++ b/src/commands/step/prune.rs@@ -412,9 +412,11 @@ fn approve_prune_hooks(continue;};let wt = &worktrees[*wt_idx];- let wt_repo = match Repository::at(&wt.path) {- Ok(r) if r.load_project_config().ok().flatten().is_some() => r,- _ => primary_repo.clone(),+ let wt_at_path = Repository::at(&wt.path)?;+ let wt_repo = if wt_at_path.load_project_config().ok().flatten().is_some() {+ wt_at_path+ } else {+ primary_repo.clone()};if let Some(cfg) = wt_repo.load_project_config()? {all_commands.extend(collect_commands_for_hooks(&cfg, &[HookType::PreRemove]));diff --git a/src/main.rs b/src/main.rsindex 770b5e8bb..b1c63421e 100644--- a/src/main.rs+++ b/src/main.rs@@ -917,9 +917,11 @@ fn handle_remove_command(args: RemoveArgs, yes: bool) -> anyhow::Result<()> {let primary_path = repo.home_path()?;let primary_repo = Repository::at(&primary_path)?;for &wt_path in removed_worktree_paths {- let wt_repo = match Repository::at(wt_path) {- Ok(r) if r.load_project_config().ok().flatten().is_some() => r,- _ => primary_repo.clone(),+ let wt_at_path = Repository::at(wt_path)?;+ let wt_repo = if wt_at_path.load_project_config().ok().flatten().is_some() {+ wt_at_path+ } else {+ primary_repo.clone()};let ctx = CommandContext::new(&wt_repo,diff --git a/src/output/handlers.rs b/src/output/handlers.rsindex 73fd7f5b1..cd1002bdc 100644--- a/src/output/handlers.rs+++ b/src/output/handlers.rs@@ -1197,9 +1197,17 @@ fn execute_pre_remove_hooks_if_needed(// — e.g. it was branched before the project added one — fall back to `repo`// so a project-wide `pre-remove` on the default branch still applies. The// `wt remove` approval helper in `main.rs` resolves the same config.- let pre_remove_repo = match Repository::at(ctx.worktree_path) {- Ok(wt_repo) if wt_repo.load_project_config().ok().flatten().is_some() => wt_repo,- _ => repo.clone(),+ //+ // A `Repository::at` failure means git can't recognize the path as a+ // worktree — propagate rather than silently fall back, matching the+ // approval helpers (`main.rs::approve_remove`, `prune::approve_prune_hooks`).+ // The `UserConfig::load()` silent-skip above is a different case: user+ // config can be benignly malformed and shouldn't fail a remove.+ let wt_at_path = Repository::at(ctx.worktree_path)?;+ let pre_remove_repo = if wt_at_path.load_project_config().ok().flatten().is_some() {+ wt_at_path+ } else {+ repo.clone()};let command_ctx = CommandContext::new(&pre_remove_repo,