Skip to content

Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows

Refactor template expansion to unified signature

Maximilian Roos413a099dcfa3
diff --git a/src/commands/command_executor.rs b/src/commands/command_executor.rs
index 1d1fca8c5..36b0f500a 100644
--- a/src/commands/command_executor.rs
+++ b/src/commands/command_executor.rs
@@ -166,14 +166,15 @@ fn expand_commands(
Ok(result)
}
-/// Prepare project commands for execution
+/// Prepare commands for execution.
///
-/// This function:
-/// 1. Expands command templates with context variables
-/// 2. Returns prepared commands ready for execution, each with JSON context for stdin
+/// Expands command templates with context variables and returns prepared
+/// commands ready for execution, each with JSON context for stdin.
///
-/// Note: Approval is handled at the gate (command entry point), not here.
-pub fn prepare_project_commands(
+/// Note: Approval logic (for project commands) is handled at the call site,
+/// not here. User commands don't require approval since users implicitly
+/// approve them by adding them to their config.
+pub fn prepare_commands(
command_config: &CommandConfig,
ctx: &CommandContext<'_>,
extra_vars: &[(&str, &str)],
@@ -195,36 +196,3 @@ pub fn prepare_project_commands(
})
.collect())
}
-
-/// Prepare user hooks for execution without approval
-///
-/// Unlike project commands, user hooks don't require approval because they're
-/// defined in the user's own config file. The user implicitly approves them
-/// by adding them to their config.
-///
-/// This function:
-/// 1. Expands command templates with context variables
-/// 2. Returns prepared commands ready for execution, each with JSON context for stdin
-pub fn prepare_user_commands(
- command_config: &CommandConfig,
- ctx: &CommandContext<'_>,
- extra_vars: &[(&str, &str)],
- hook_type: HookType,
-) -> anyhow::Result<Vec<PreparedCommand>> {
- let commands = command_config.commands_with_phase(hook_type);
- if commands.is_empty() {
- return Ok(Vec::new());
- }
-
- // Expand commands (no approval needed for user hooks)
- let expanded_with_json = expand_commands(&commands, ctx, extra_vars)?;
-
- Ok(expanded_with_json
- .into_iter()
- .map(|(cmd, context_json)| PreparedCommand {
- name: cmd.name,
- expanded: cmd.expanded,
- context_json,
- })
- .collect())
-}
diff --git a/src/commands/hooks.rs b/src/commands/hooks.rs
index 00217f6bd..249364f39 100644
--- a/src/commands/hooks.rs
+++ b/src/commands/hooks.rs
@@ -18,9 +18,7 @@ use worktrunk::config::{CommandConfig, ProjectConfig};
use worktrunk::git::WorktrunkError;
use worktrunk::styling::{format_bash_with_gutter, progress_message, warning_message};
-use super::command_executor::{
- CommandContext, PreparedCommand, prepare_project_commands, prepare_user_commands,
-};
+use super::command_executor::{CommandContext, PreparedCommand, prepare_commands};
use crate::commands::process::spawn_detached;
use crate::output::execute_command_in_worktree;
@@ -73,18 +71,11 @@ impl<'a> HookPipeline<'a> {
&self,
command_config: &CommandConfig,
hook_type: HookType,
- source: &HookSource,
+ _source: &HookSource,
extra_vars: &[(&str, &str)],
name_filter: Option<&str>,
) -> anyhow::Result<Vec<PreparedCommand>> {
- let commands = match source {
- HookSource::User => {
- prepare_user_commands(command_config, &self.ctx, extra_vars, hook_type)?
- }
- HookSource::Project => {
- prepare_project_commands(command_config, &self.ctx, extra_vars, hook_type)?
- }
- };
+ let commands = prepare_commands(command_config, &self.ctx, extra_vars, hook_type)?;
Ok(Self::filter_by_name(commands, name_filter))
}
diff --git a/src/commands/merge.rs b/src/commands/merge.rs
index 5e13802d1..ec919842f 100644
--- a/src/commands/merge.rs
+++ b/src/commands/merge.rs
@@ -47,7 +47,7 @@ impl<'a> MergeCommandCollector<'a> {
};
// Collect original commands (not expanded) for approval
- // Expansion happens later in prepare_project_commands during execution
+ // Expansion happens later in prepare_commands during execution
// Collect pre-commit commands if we'll commit (direct or via squash)
// These run before: (1) direct commit (line 179), or (2) squash commit (line 194 → handle_dev_squash)