Skip to content

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

feat: Improve command context labels in UI

Maximilian Roosd3f8077f3366
diff --git a/src/commands/command_approval.rs b/src/commands/command_approval.rs
index 044b68652..add5bb8cd 100644
--- a/src/commands/command_approval.rs
+++ b/src/commands/command_approval.rs
@@ -33,7 +33,7 @@ pub fn approve_command_batch(
let approved = if force {
true
} else {
- prompt_for_batch_approval(&needs_approval, project_id)?
+ prompt_for_batch_approval(&needs_approval, project_id, context)?
};
if !approved {
@@ -72,7 +72,11 @@ fn log_approval_warning(message: &str, error: impl std::fmt::Display) {
println!("{WARNING_EMOJI} {WARNING}{message}: {error}{WARNING:#}");
}
-fn prompt_for_batch_approval(commands: &[&Command], project_id: &str) -> std::io::Result<bool> {
+fn prompt_for_batch_approval(
+ commands: &[&Command],
+ project_id: &str,
+ context: &str,
+) -> std::io::Result<bool> {
use std::io::{self, Write};
let project_name = project_id.split('/').next_back().unwrap_or(project_id);
@@ -87,10 +91,17 @@ fn prompt_for_batch_approval(commands: &[&Command], project_id: &str) -> std::io
"{WARNING_EMOJI} {WARNING}Permission required to execute {warning_bold}{count}{warning_bold:#} command{plural}{WARNING:#}",
);
println!();
+ println!("{bold}{project_name}{bold:#} ({dim}{project_id}{dim:#}) wants to execute:");
+ println!();
for cmd in commands {
- println!("{bold}{project_name}{bold:#} ({dim}{project_id}{dim:#}) wants to execute:");
- println!();
+ // Format as: {context} {bold}{name}{bold:#}:
+ // context is provided by caller in lowercase (e.g., "post-create", "pre-merge")
+ let label = match &cmd.name {
+ Some(name) => format!("{context} {bold}{name}{bold:#}:"),
+ None => format!("{context}:"),
+ };
+ println!("{label}");
print!("{}", format_bash_with_gutter(&cmd.expanded, ""));
println!();
}
diff --git a/src/commands/merge.rs b/src/commands/merge.rs
index 221dd2952..96c07ece4 100644
--- a/src/commands/merge.rs
+++ b/src/commands/merge.rs
@@ -158,13 +158,7 @@ pub fn handle_merge(
// Approve all commands in a single batch
// Commands collected here are not yet expanded - expansion happens later in prepare_project_commands
- approve_command_batch(
- &all_commands,
- &project_id,
- &config,
- force,
- "Merge operation",
- )?;
+ approve_command_batch(&all_commands, &project_id, &config, force, "merge")?;
// Handle uncommitted changes (skip if --no-commit) - track whether commit occurred
let committed = if !no_commit && repo.is_dirty()? {
@@ -504,7 +498,7 @@ pub fn run_pre_merge_commands(
&ctx,
false,
&[("target", target_branch)],
- "Pre-merge commands",
+ "pre-merge",
)?;
for prepared in commands {
let label = crate::commands::format_command_label("pre-merge", prepared.name.as_deref());
@@ -561,7 +555,7 @@ pub fn execute_post_merge_commands(
&ctx,
false,
&[("target", target_branch)],
- "Post-merge commands",
+ "post-merge",
)?;
if commands.is_empty() {
@@ -624,13 +618,8 @@ pub fn run_pre_commit_commands(
vec![]
};
- let commands = prepare_project_commands(
- pre_commit_config,
- &ctx,
- false,
- &extra_vars,
- "Pre-commit commands",
- )?;
+ let commands =
+ prepare_project_commands(pre_commit_config, &ctx, false, &extra_vars, "pre-commit")?;
if commands.is_empty() {
return Ok(());
diff --git a/src/commands/worktree.rs b/src/commands/worktree.rs
index cb4397bcf..9033c00e3 100644
--- a/src/commands/worktree.rs
+++ b/src/commands/worktree.rs
@@ -452,8 +452,7 @@ pub fn execute_post_create_commands(
let repo_root = repo.main_worktree_root()?;
let ctx = CommandContext::new(repo, config, branch, worktree_path, &repo_root, force);
- let commands =
- prepare_project_commands(post_create_config, &ctx, false, &[], "Post-create commands")?;
+ let commands = prepare_project_commands(post_create_config, &ctx, false, &[], "post-create")?;
if commands.is_empty() {
return Ok(());
@@ -502,8 +501,7 @@ pub fn spawn_post_start_commands(
let repo_root = repo.main_worktree_root()?;
let ctx = CommandContext::new(repo, config, branch, worktree_path, &repo_root, force);
- let commands =
- prepare_project_commands(post_start_config, &ctx, false, &[], "Post-start commands")?;
+ let commands = prepare_project_commands(post_start_config, &ctx, false, &[], "post-start")?;
if commands.is_empty() {
return Ok(());
@@ -559,8 +557,7 @@ pub fn execute_post_start_commands_sequential(
let repo_root = repo.main_worktree_root()?;
let ctx = CommandContext::new(repo, config, branch, worktree_path, &repo_root, force);
- let commands =
- prepare_project_commands(post_start_config, &ctx, false, &[], "Post-start commands")?;
+ let commands = prepare_project_commands(post_start_config, &ctx, false, &[], "post-start")?;
if commands.is_empty() {
return Ok(());
diff --git a/src/config/mod.rs b/src/config/mod.rs
index 00d097eb6..9eef0026c 100644
--- a/src/config/mod.rs
+++ b/src/config/mod.rs
@@ -275,8 +275,7 @@ impl<'de> Deserialize<'de> for CommandConfig {
CommandConfigToml::Single(cmd) => vec![Command::new(None, cmd)],
CommandConfigToml::Multiple(cmds) => cmds
.into_iter()
- .enumerate()
- .map(|(i, template)| Command::new(Some((i + 1).to_string()), template))
+ .map(|template| Command::new(None, template))
.collect(),
CommandConfigToml::Named(map) => {
// IndexMap preserves insertion order from TOML
@@ -879,14 +878,8 @@ mod tests {
let cmd_config = config.post_create_command.unwrap();
let commands = cmd_config.commands();
assert_eq!(commands.len(), 2);
- assert_eq!(
- commands[0],
- Command::new(Some("1".to_string()), "npm install".to_string())
- );
- assert_eq!(
- commands[1],
- Command::new(Some("2".to_string()), "npm test".to_string())
- );
+ assert_eq!(commands[0], Command::new(None, "npm install".to_string()));
+ assert_eq!(commands[1], Command::new(None, "npm test".to_string()));
}
#[test]
@@ -1000,12 +993,9 @@ task2 = "echo 'Task 2 running' > task2.txt"
assert_eq!(commands.len(), 2);
assert_eq!(
commands[0],
- Command::new(Some("1".to_string()), "cargo fmt -- --check".to_string())
- );
- assert_eq!(
- commands[1],
- Command::new(Some("2".to_string()), "cargo test".to_string())
+ Command::new(None, "cargo fmt -- --check".to_string())
);
+ assert_eq!(commands[1], Command::new(None, "cargo test".to_string()));
}
#[test]
diff --git a/tests/integration_tests/approval_ui.rs b/tests/integration_tests/approval_ui.rs
index 8430dc253..6c5bec974 100644
--- a/tests/integration_tests/approval_ui.rs
+++ b/tests/integration_tests/approval_ui.rs
@@ -253,3 +253,30 @@ approved-commands = ["echo 'Second command'"]
false,
);
}
+
+#[test]
+fn test_approval_named_commands() {
+ let repo = TestRepo::new();
+ repo.commit("Initial commit");
+
+ let config_dir = repo.root_path().join(".config");
+ fs::create_dir_all(&config_dir).expect("Failed to create .config dir");
+ fs::write(
+ config_dir.join("wt.toml"),
+ r#"[post-create-command]
+install = "echo 'Installing dependencies...'"
+build = "echo 'Building project...'"
+test = "echo 'Running tests...'"
+"#,
+ )
+ .expect("Failed to write config");
+
+ repo.commit("Add config");
+
+ snapshot_approval(
+ "approval_named_commands",
+ &repo,
+ &["--create", "test-named"],
+ false,
+ );
+}
diff --git a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__switch_with_hooks_bash.snap b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__switch_with_hooks_bash.snap
index cc6d34d4f..704874d9a 100644
--- a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__switch_with_hooks_bash.snap
+++ b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__switch_with_hooks_bash.snap
@@ -2,12 +2,12 @@
source: tests/integration_tests/shell_wrapper.rs
expression: output.normalized()
---
-πŸ”„ Running post-create: 1
+πŸ”„ Running post-create:
  echo 'Installing dependencies...'
Installing dependencies...
-πŸ”„ Running post-create: 2
+πŸ”„ Running post-create:
  echo 'Building project...'
Building project...
diff --git a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__switch_with_hooks_zsh.snap b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__switch_with_hooks_zsh.snap
index 3f048aa63..96327de94 100644
--- a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__switch_with_hooks_zsh.snap
+++ b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__switch_with_hooks_zsh.snap
@@ -4,11 +4,11 @@ expression: output.normalized()
---
Installing dependencies...
Building project...
-πŸ”„ Running post-create: 1
+πŸ”„ Running post-create:
  echo 'Installing dependencies...'
-πŸ”„ Running post-create: 2
+πŸ”„ Running post-create:
  echo 'Building project...'
diff --git a/tests/snapshots/integration__integration_tests__approval_ui__approval_mixed_approved_unapproved.snap b/tests/snapshots/integration__integration_tests__approval_ui__approval_mixed_approved_unapproved.snap
index 260bb3868..44e8f6b39 100644
--- a/tests/snapshots/integration__integration_tests__approval_ui__approval_mixed_approved_unapproved.snap
+++ b/tests/snapshots/integration__integration_tests__approval_ui__approval_mixed_approved_unapproved.snap
@@ -9,14 +9,14 @@ exit_code: 0
test-repo (test-repo) wants to execute:
+post-create:
  echo 'First command'
-test-repo (test-repo) wants to execute:
-
+post-create:
  echo 'Third command'
-Post-create commands declined
+post-create declined
βœ… Created new worktree for test-mixed from main at [REPO].test-mixed
To enable automatic cd, run: wt config shell
diff --git a/tests/snapshots/integration__integration_tests__approval_ui__approval_multiple_commands.snap b/tests/snapshots/integration__integration_tests__approval_ui__approval_multiple_commands.snap
index 1f1bdbe7a..6ceb27503 100644
--- a/tests/snapshots/integration__integration_tests__approval_ui__approval_multiple_commands.snap
+++ b/tests/snapshots/integration__integration_tests__approval_ui__approval_multiple_commands.snap
@@ -9,22 +9,20 @@ exit_code: 0
test-repo (test-repo) wants to execute:
+post-create:
  echo 'Branch: test-nested-branch'
-test-repo (test-repo) wants to execute:
-
+post-create:
  echo 'Worktree: [REPO].test-nested-branch'
-test-repo (test-repo) wants to execute:
-
+post-create:
  echo 'Repo: test-repo'
-test-repo (test-repo) wants to execute:
-
+post-create:
  cd [REPO].test-nested-branch && pwd
-Post-create commands declined
+post-create declined
βœ… Created new worktree for test/nested-branch from main at [REPO].test-nested-branch
To enable automatic cd, run: wt config shell
diff --git a/tests/snapshots/integration__integration_tests__approval_ui__approval_named_commands.snap b/tests/snapshots/integration__integration_tests__approval_ui__approval_named_commands.snap
new file mode 100644
index 000000000..a628ef7f1
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__approval_ui__approval_named_commands.snap
@@ -0,0 +1,28 @@
+---
+source: tests/integration_tests/approval_ui.rs
+expression: combined
+---
+exit_code: 0
+----- stdout -----
+
+🟑 Permission required to execute 3 commands
+
+test-repo (test-repo) wants to execute:
+
+post-create install:
+  echo 'Installing dependencies...'
+
+post-create build:
+  echo 'Building project...'
+
+post-create test:
+  echo 'Running tests...'
+
+
+post-create declined
+βœ… Created new worktree for test-named from main at [REPO].test-named
+
+To enable automatic cd, run: wt config shell
+
+----- stderr -----
+πŸ’‘ Allow and remember? [y/N]
diff --git a/tests/snapshots/integration__integration_tests__approval_ui__approval_single_command.snap b/tests/snapshots/integration__integration_tests__approval_ui__approval_single_command.snap
index 87f3be190..567b7bc20 100644
--- a/tests/snapshots/integration__integration_tests__approval_ui__approval_single_command.snap
+++ b/tests/snapshots/integration__integration_tests__approval_ui__approval_single_command.snap
@@ -9,10 +9,11 @@ exit_code: 0
test-repo (test-repo) wants to execute:
+post-create:
  echo 'Worktree path: [REPO].feature-test-approval'
-Post-create commands declined
+post-create declined
βœ… Created new worktree for feature/test-approval from main at [REPO].feature-test-approval
To enable automatic cd, run: wt config shell
diff --git a/tests/snapshots/integration__integration_tests__approval_ui__decline_approval_skips_only_unapproved.snap b/tests/snapshots/integration__integration_tests__approval_ui__decline_approval_skips_only_unapproved.snap
index 06eaa11fe..ce98ad141 100644
--- a/tests/snapshots/integration__integration_tests__approval_ui__decline_approval_skips_only_unapproved.snap
+++ b/tests/snapshots/integration__integration_tests__approval_ui__decline_approval_skips_only_unapproved.snap
@@ -9,14 +9,14 @@ exit_code: 0
test-repo (test-repo) wants to execute:
+post-create:
  echo 'First command'
-test-repo (test-repo) wants to execute:
-
+post-create:
  echo 'Third command'
-Post-create commands declined
+post-create declined
βœ… Created new worktree for test-decline from main at [REPO].test-decline
To enable automatic cd, run: wt config shell
diff --git a/tests/snapshots/integration__integration_tests__approval_ui__force_does_not_save_approvals_second_run.snap b/tests/snapshots/integration__integration_tests__approval_ui__force_does_not_save_approvals_second_run.snap
index 90b08af90..d1d3c0c8d 100644
--- a/tests/snapshots/integration__integration_tests__approval_ui__force_does_not_save_approvals_second_run.snap
+++ b/tests/snapshots/integration__integration_tests__approval_ui__force_does_not_save_approvals_second_run.snap
@@ -9,10 +9,11 @@ exit_code: 0
test-repo (test-repo) wants to execute:
+post-create:
  echo 'test command' > output.txt
-Post-create commands declined
+post-create declined
βœ… Created new worktree for test-force-2 from main at [REPO].test-force-2
To enable automatic cd, run: wt config shell
diff --git a/tests/snapshots/integration__integration_tests__post_start_commands__post_create_multiple_commands_array.snap b/tests/snapshots/integration__integration_tests__post_start_commands__post_create_multiple_commands_array.snap
index a609d18ab..e77d9f446 100644
--- a/tests/snapshots/integration__integration_tests__post_start_commands__post_create_multiple_commands_array.snap
+++ b/tests/snapshots/integration__integration_tests__post_start_commands__post_create_multiple_commands_array.snap
@@ -17,15 +17,15 @@ info:
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1761609600"
- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpqTsQ2h/test-config.toml
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmp3fiKSk/test-config.toml
---
success: true
exit_code: 0
----- stdout -----
-πŸ”„ Running post-create: 1
+πŸ”„ Running post-create:
  echo 'First'
-πŸ”„ Running post-create: 2
+πŸ”„ Running post-create:
  echo 'Second'
βœ… Created new worktree for feature from main at [REPO].feature
diff --git a/tests/snapshots/integration__integration_tests__post_start_commands__post_create_template_expansion.snap b/tests/snapshots/integration__integration_tests__post_start_commands__post_create_template_expansion.snap
index ed55d9c9a..34f89ae54 100644
--- a/tests/snapshots/integration__integration_tests__post_start_commands__post_create_template_expansion.snap
+++ b/tests/snapshots/integration__integration_tests__post_start_commands__post_create_template_expansion.snap
@@ -17,21 +17,21 @@ info:
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1761609600"
- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpI8VcDn/test-config.toml
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpEHiur6/test-config.toml
---
success: true
exit_code: 0
----- stdout -----
-πŸ”„ Running post-create: 1
+πŸ”„ Running post-create:
  echo 'Repo: test-repo' > info.txt
-πŸ”„ Running post-create: 2
+πŸ”„ Running post-create:
  echo 'Branch: feature-test' >> info.txt
-πŸ”„ Running post-create: 3
+πŸ”„ Running post-create:
  echo 'Worktree: [REPO].feature-test' >> info.txt
-πŸ”„ Running post-create: 4
+πŸ”„ Running post-create:
  echo 'Root: [REPO]' >> info.txt
βœ… Created new worktree for feature/test from main at [REPO].feature-test