Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
feat: Acknowledge base branch in switch message
Maximilian Roos5fcf6b50cf19
diff --git a/CLAUDE.md b/CLAUDE.mdindex 1ed186266..a432fe05c 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -28,6 +28,41 @@ When the project reaches v1.0 or gains users, we'll adopt stability commitments.## CLI Output Formatting Standards+### User Message Principles++**Core Principle: Acknowledge user-supplied arguments in output messages.**++When users provide explicit arguments (flags, options, values), the output should recognize and reflect those choices. This confirms the program understood their intent and used their input correctly.++**Examples:**++```rust+// User runs: wt switch --create feature --base=main+// ✅ GOOD - acknowledges the base branch+"Created new worktree for feature from main at /path/to/worktree"++// ❌ BAD - ignores the base argument+"Created new worktree for feature at /path/to/worktree"++// User runs: wt merge --squash+// ✅ GOOD - acknowledges squash mode+"Squashing 3 commits into 1..."++// ❌ BAD - doesn't mention squashing+"Merging commits..."+```++**Why this matters:**+- Builds confidence that arguments were parsed correctly+- Helps users understand what the command actually did+- Makes output more informative and traceable+- Prevents confusion about which options were applied++**Implementation pattern:**+- When formatting messages, include information from user-supplied arguments+- Don't just use defaults silently—show what was chosen+- For optional arguments, conditionally include them in the message+### The anstyle EcosystemAll styling uses the **anstyle ecosystem** for composable, auto-detecting terminal output:diff --git a/src/commands/worktree.rs b/src/commands/worktree.rsindex 9aabec873..334fa99ac 100644--- a/src/commands/worktree.rs+++ b/src/commands/worktree.rs@@ -117,7 +117,11 @@ pub enum SwitchResult {/// Switched to existing worktree at the given pathExistingWorktree(PathBuf),/// Created new worktree at the given path- CreatedWorktree { path: PathBuf, created_branch: bool },+ CreatedWorktree {+ path: PathBuf,+ created_branch: bool,+ base_branch: Option<String>,+ },}impl SwitchResult {@@ -233,6 +237,7 @@ pub fn handle_switch(Ok(SwitchResult::CreatedWorktree {path: worktree_path,created_branch: create,+ base_branch: base.map(String::from),})}diff --git a/src/output/directive.rs b/src/output/directive.rsindex de77655c2..ab12c40a8 100644--- a/src/output/directive.rs+++ b/src/output/directive.rs@@ -87,8 +87,14 @@ impl DirectiveOutput {////// In directive mode, the shell wrapper will actually change directories,/// so we can say "changed directory to {path}"- pub fn format_switch_success(&self, branch: &str, path: &Path, created_branch: bool) -> String {- super::format_switch_success_message(branch, path, created_branch, true)+ pub fn format_switch_success(+ &self,+ branch: &str,+ path: &Path,+ created_branch: bool,+ base_branch: Option<&str>,+ ) -> String {+ super::format_switch_success_message(branch, path, created_branch, base_branch, true)}}diff --git a/src/output/global.rs b/src/output/global.rsindex 8125d1602..30d324991 100644--- a/src/output/global.rs+++ b/src/output/global.rs@@ -141,10 +141,19 @@ pub fn terminate_output() -> io::Result<()> {////// In interactive mode: "at {path}" (can't actually change directory)/// In directive mode: "changed directory to {path}" (shell will change it)-pub fn format_switch_success(branch: &str, path: &Path, created_branch: bool) -> String {+pub fn format_switch_success(+ branch: &str,+ path: &Path,+ created_branch: bool,+ base_branch: Option<&str>,+) -> String {OUTPUT_CONTEXT.with(|ctx| match &*ctx.borrow() {- OutputHandler::Interactive(i) => i.format_switch_success(branch, path, created_branch),- OutputHandler::Directive(d) => d.format_switch_success(branch, path, created_branch),+ OutputHandler::Interactive(i) => {+ i.format_switch_success(branch, path, created_branch, base_branch)+ }+ OutputHandler::Directive(d) => {+ d.format_switch_success(branch, path, created_branch, base_branch)+ }})}diff --git a/src/output/handlers.rs b/src/output/handlers.rsindex a14604a67..224f84c6a 100644--- a/src/output/handlers.rs+++ b/src/output/handlers.rs@@ -9,14 +9,15 @@ fn format_switch_message(result: &SwitchResult, branch: &str) -> String {match result {SwitchResult::ExistingWorktree(path) => {// created_branch=false means we switched to existing worktree- format_switch_success(branch, path, false)+ format_switch_success(branch, path, false, None)}SwitchResult::CreatedWorktree {path,created_branch,+ base_branch,} => {- // Pass through whether we created a new branch- format_switch_success(branch, path, *created_branch)+ // Pass through whether we created a new branch and the base branch+ format_switch_success(branch, path, *created_branch, base_branch.as_deref())}}}diff --git a/src/output/interactive.rs b/src/output/interactive.rsindex e4b0374eb..3cd940f5e 100644--- a/src/output/interactive.rs+++ b/src/output/interactive.rs@@ -71,8 +71,14 @@ impl InteractiveOutput {/// Format a switch success message for interactive mode////// In interactive mode, we can't actually change directories, so we say "at {path}"- pub fn format_switch_success(&self, branch: &str, path: &Path, created_branch: bool) -> String {- super::format_switch_success_message(branch, path, created_branch, false)+ pub fn format_switch_success(+ &self,+ branch: &str,+ path: &Path,+ created_branch: bool,+ base_branch: Option<&str>,+ ) -> String {+ super::format_switch_success_message(branch, path, created_branch, base_branch, false)}}diff --git a/src/output/mod.rs b/src/output/mod.rsindex c16f8c334..6ca4ab171 100644--- a/src/output/mod.rs+++ b/src/output/mod.rs@@ -77,12 +77,13 @@ use std::path::Path;/// Format a switch success message with mode-specific location phrase////// The message format differs between interactive and directive modes:-/// - Interactive: "Created new worktree for {branch} at {path}"-/// - Directive: "Created new worktree for {branch}, changed directory to {path}"+/// - Interactive: "Created new worktree for {branch} from {base} at {path}"+/// - Directive: "Created new worktree for {branch} from {base}, changed directory to {path}"pub(crate) fn format_switch_success_message(branch: &str,path: &Path,created_branch: bool,+ base_branch: Option<&str>,use_past_tense: bool,) -> String {use worktrunk::styling::{GREEN, SUCCESS_EMOJI};@@ -93,6 +94,9 @@ pub(crate) fn format_switch_success_message(} else {"Switched to worktree for"};+ let base_suffix = base_branch+ .map(|b| format!(" from {green_bold}{b}{green_bold:#}{GREEN}"))+ .unwrap_or_default();let location = if use_past_tense {", changed directory to"} else {@@ -100,7 +104,7 @@ pub(crate) fn format_switch_success_message(};format!(- "{SUCCESS_EMOJI} {GREEN}{action} {green_bold}{branch}{green_bold:#}{GREEN}{location} {green_bold}{}{green_bold:#}{GREEN:#}",+ "{SUCCESS_EMOJI} {GREEN}{action} {green_bold}{branch}{green_bold:#}{GREEN}{base_suffix}{location} {green_bold}{}{green_bold:#}{GREEN:#}",path.display())}diff --git a/tests/snapshots/integration__integration_tests__switch__switch_with_base.snap b/tests/snapshots/integration__integration_tests__switch__switch_with_base.snapindex a7046b5be..e7ac7de6b 100644--- a/tests/snapshots/integration__integration_tests__switch__switch_with_base.snap+++ b/tests/snapshots/integration__integration_tests__switch__switch_with_base.snap@@ -19,12 +19,12 @@ info:LANG: CLC_ALL: CSOURCE_DATE_EPOCH: "1761609600"- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpVSODsv/test-config.toml+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpqwZYuj/test-config.toml---success: trueexit_code: 0----- stdout ------✅ [32mCreated new worktree for [1m[32mfeature-with-base[0m[32m at [1m[32m[REPO].feature-with-base[0m[0m+✅ [32mCreated new worktree for [1m[32mfeature-with-base[0m[32m from [1m[32mmain[0m[32m at [1m[32m[REPO].feature-with-base[0m[0mTo enable automatic cd, run: wt config shell