Skip to content

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

feat: Streamline error handling and improve styling utilities

Maximilian Roos206b72faa0cb
diff --git a/.claude-plugin/skills/worktrunk/reference/README.md b/.claude-plugin/skills/worktrunk/reference/README.md
index ff26e5a83..c3a2f1cb9 100644
--- a/.claude-plugin/skills/worktrunk/reference/README.md
+++ b/.claude-plugin/skills/worktrunk/reference/README.md
@@ -424,7 +424,7 @@ The merge operation follows a strict order designed for fail-fast execution:
worktree so they don't block the push, then restores them after success.
7. **Clean up worktree and branch**
- Removes current worktree, deletes the branch, and switches primary worktree to target
+ Removes current worktree, deletes the branch, and switches to the main worktree or target
branch if needed. Skip removal with --no-remove.
**EXAMPLES:**
diff --git a/CLAUDE.md b/CLAUDE.md
index 7f49b8b84..fe8ba8846 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -261,7 +261,7 @@ println!("{HINT_EMOJI} {HINT}Use 'wt list' to see all worktrees{HINT:#}");
### Composing Styles
-Compose styles using anstyle methods (`.bold()`, `.fg_color()`, etc.). Branch names in messages (not tables) should be bolded. Tables (`wt list`) use conditional styling for branch names to indicate worktree state (current/primary/other).
+Compose styles using anstyle methods (`.bold()`, `.fg_color()`, etc.). Branch names in messages (not tables) should be bolded. Tables (`wt list`) use conditional styling for branch names to indicate worktree state (current/main/other).
Nested style resets leak color. Compose all attributes into a single style object:
@@ -536,7 +536,7 @@ Use `wt list --format=json` for structured data access. The output is an array o
- `working_tree_diff`: `{added, deleted}` - uncommitted changes
- `working_tree_diff_with_main`: `{added, deleted}` or null (null = not computed, `{0,0}` = matches main exactly)
- `worktree_state`: "rebase" | "merge" | null - git operation in progress
-- `is_primary`: boolean - is main worktree
+- `is_main`: boolean - is main worktree
### Branch-Specific Fields
diff --git a/README.md b/README.md
index ff26e5a83..c3a2f1cb9 100644
--- a/README.md
+++ b/README.md
@@ -424,7 +424,7 @@ The merge operation follows a strict order designed for fail-fast execution:
worktree so they don't block the push, then restores them after success.
7. **Clean up worktree and branch**
- Removes current worktree, deletes the branch, and switches primary worktree to target
+ Removes current worktree, deletes the branch, and switches to the main worktree or target
branch if needed. Skip removal with --no-remove.
**EXAMPLES:**
diff --git a/src/commands/list/collect.rs b/src/commands/list/collect.rs
index 358a423c5..3b475a17d 100644
--- a/src/commands/list/collect.rs
+++ b/src/commands/list/collect.rs
@@ -457,7 +457,7 @@ pub fn collect(
.iter()
.find(|wt| wt.branch.as_deref() == Some(default_branch.as_str()))
.cloned()
- .unwrap_or_else(|| worktrees.worktrees[0].clone());
+ .unwrap_or_else(|| worktrees.main().clone());
let current_worktree_path = repo.worktree_root().ok();
// Sort worktrees for display order
diff --git a/src/commands/list/columns.rs b/src/commands/list/columns.rs
index 4b72d4afb..e5961ca49 100644
--- a/src/commands/list/columns.rs
+++ b/src/commands/list/columns.rs
@@ -1,7 +1,7 @@
/// Logical identifier for each column rendered by `wt list`.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum ColumnKind {
- Gutter, // Type indicator: `@` (current), `^` (primary), `+` (worktree), space (branch-only)
+ Gutter, // Type indicator: `@` (current), `^` (main), `+` (worktree), space (branch-only)
Branch,
Status, // Includes both git status symbols and user-defined status
WorkingDiff,
diff --git a/src/commands/list/render.rs b/src/commands/list/render.rs
index 605962a5c..d70cc7517 100644
--- a/src/commands/list/render.rs
+++ b/src/commands/list/render.rs
@@ -549,11 +549,11 @@ impl ColumnLayout {
ColumnKind::Gutter => {
let mut cell = StyledLine::new();
let symbol = if let Some(data) = ctx.worktree_data {
- // Worktree: priority is current > primary > regular
+ // Worktree: priority is current > main > regular
if ctx.is_current {
"@ " // Current worktree
} else if data.is_main {
- "^ " // Primary worktree
+ "^ " // Main worktree
} else {
"+ " // Regular worktree
}
diff --git a/src/commands/merge.rs b/src/commands/merge.rs
index 5871db4b8..3c8648d58 100644
--- a/src/commands/merge.rs
+++ b/src/commands/merge.rs
@@ -95,8 +95,8 @@ pub fn handle_merge(
let target_worktree_path = repo.worktree_for_branch(&target_branch)?;
// When current == target or we're in the main worktree, force --no-remove (can't remove it)
- let in_primary = !repo.is_in_worktree().unwrap_or(false);
- let no_remove_effective = no_remove || current_branch == target_branch || in_primary;
+ let in_main = !repo.is_in_worktree().unwrap_or(false);
+ let no_remove_effective = no_remove || current_branch == target_branch || in_main;
// Collect and approve all commands upfront for batch permission request
let (all_commands, project_id) = MergeCommandCollector {
@@ -176,10 +176,10 @@ pub fn handle_merge(
}),
)?;
- // Destination: prefer the target branch's worktree; fall back to primary when absent
+ // Destination: prefer the target branch's worktree; fall back to main when absent
let destination_path = target_worktree_path
.clone()
- .unwrap_or_else(|| worktrees.worktrees[0].path.clone());
+ .unwrap_or_else(|| worktrees.main().path.clone());
// Finish worktree unless --no-remove was specified
if !no_remove_effective {
@@ -232,7 +232,7 @@ fn format_merge_summary(main_path: Option<&std::path::Path>) -> String {
// Show where we ended up
if let Some(path) = main_path {
format!(
- "{GREEN}Returned to primary at {GREEN_BOLD}{}{GREEN_BOLD:#}{GREEN:#}",
+ "{GREEN}Returned to main at {GREEN_BOLD}{}{GREEN_BOLD:#}{GREEN:#}",
format_path_for_display(path)
)
} else {
diff --git a/src/commands/repository_ext.rs b/src/commands/repository_ext.rs
index 3bdc5b02b..ff2199914 100644
--- a/src/commands/repository_ext.rs
+++ b/src/commands/repository_ext.rs
@@ -96,7 +96,7 @@ impl RepositoryCliExt for Repository {
let (main_path, changed_directory) = if removing_current {
let worktrees = self.list_worktrees()?;
- (worktrees.worktrees[0].path.clone(), true)
+ (worktrees.main().path.clone(), true)
} else {
(current_worktree, false)
};
diff --git a/src/commands/worktree.rs b/src/commands/worktree.rs
index 7ffc0e19a..9a2d80af2 100644
--- a/src/commands/worktree.rs
+++ b/src/commands/worktree.rs
@@ -148,7 +148,7 @@ impl SwitchResult {
/// Result of a worktree remove operation
pub enum RemoveResult {
- /// Removed worktree and returned to primary (if needed)
+ /// Removed worktree and returned to main (if needed)
RemovedWorktree {
main_path: PathBuf,
worktree_path: PathBuf,
diff --git a/src/git/mod.rs b/src/git/mod.rs
index 0689e8d36..162ec48ab 100644
--- a/src/git/mod.rs
+++ b/src/git/mod.rs
@@ -77,11 +77,11 @@ pub struct Worktree {
pub prunable: Option<String>,
}
-/// A list of worktrees with automatic bare worktree filtering and primary identification.
+/// A list of worktrees with automatic bare worktree filtering.
///
/// This type ensures:
/// - Bare worktrees are filtered out (only worktrees with working trees are included)
-/// - The main worktree is always identifiable (first non-bare worktree at index 0)
+/// - The main worktree is always at index 0 (accessible via `.main()`)
/// - Construction fails if no valid worktrees exist
#[derive(Debug, Clone)]
pub struct WorktreeList {
@@ -89,7 +89,7 @@ pub struct WorktreeList {
}
impl WorktreeList {
- /// Create from raw worktrees, filtering bare entries and identifying primary.
+ /// Create from raw worktrees, filtering bare entries.
pub(crate) fn from_raw(raw_worktrees: Vec<Worktree>) -> anyhow::Result<Self> {
let worktrees: Vec<_> = raw_worktrees.into_iter().filter(|wt| !wt.bare).collect();
@@ -99,6 +99,11 @@ impl WorktreeList {
Ok(Self { worktrees })
}
+
+ /// Returns the main worktree (always at index 0).
+ pub fn main(&self) -> &Worktree {
+ &self.worktrees[0]
+ }
}
impl IntoIterator for WorktreeList {
@@ -198,7 +203,7 @@ mod tests {
}
#[test]
- fn test_worktree_list_primary() {
+ fn test_worktree_list_main() {
let worktrees = vec![
Worktree {
path: PathBuf::from("/repo"),
@@ -222,8 +227,9 @@ mod tests {
let list = WorktreeList::from_raw(worktrees).unwrap();
- assert_eq!(list.worktrees[0].branch, Some("main".to_string()));
- assert_eq!(list.worktrees[0].path, PathBuf::from("/repo/main"));
+ let main = list.main();
+ assert_eq!(main.branch, Some("main".to_string()));
+ assert_eq!(main.path, PathBuf::from("/repo/main"));
}
#[test]