Skip to content

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

fix(list): count branch scope structurally, not by '/' in name (#3687)

Worktrunk Bot3d166a81ebe1
diff --git a/src/commands/list/mod.rs b/src/commands/list/mod.rs
index 4eb46de7f..ecc6f18e8 100644
--- a/src/commands/list/mod.rs
+++ b/src/commands/list/mod.rs
@@ -46,7 +46,8 @@
//! First run in a repo without cached default branch adds ~100-300ms for network lookup.
//!
//! After the skeleton appears, cells fill in progressively as git operations complete.
-//! The slowest operation (CI status) only runs with `--full`.
+//! The slowest operation (CI status) runs with `--full`, or when `[list] columns`
+//! names `ci` (which forces the column and its fetch on without `--full`).
//!
//! ## Git Commands Per Worktree
//!
@@ -133,7 +134,7 @@ pub(crate) mod render;
// Layout is calculated in collect/mod.rs
use anstyle::Style;
use anyhow::Context;
-use model::{ListData, ListItem};
+use model::{BranchScope, ItemKind, ListData, ListItem};
use progressive::RenderTarget;
use worktrunk::git::Repository;
use worktrunk::styling::INFO_SYMBOL;
@@ -309,12 +310,14 @@ impl SummaryMetrics {
self.dirty_worktrees += 1;
}
} else {
- // Distinguish local vs remote branches by presence of '/' in name
- // Remote branches are like "origin/feature", local are like "feature"
- if item.branch.as_ref().is_some_and(|b| b.contains('/')) {
- self.remote_branches += 1;
- } else {
- self.local_branches += 1;
+ // Local vs remote is recorded structurally on the item
+ // (`BranchScope`), never inferred from the name — a local branch
+ // may legitimately be named `origin/foo`, so a name-prefix
+ // heuristic would misclassify it. See `BranchScope` in
+ // `model/item.rs`.
+ match item.kind {
+ ItemKind::Branch(BranchScope::Remote) => self.remote_branches += 1,
+ _ => self.local_branches += 1,
}
}
@@ -408,6 +411,26 @@ mod tests {
assert_eq!(metrics.ahead_items, 0);
}
+ #[test]
+ fn test_summary_metrics_classifies_by_scope_not_name() {
+ // A local branch may legitimately contain '/' (e.g. `feature/login`);
+ // it must be counted as local on its structural `BranchScope`, not on
+ // a name-prefix heuristic that would misread the '/' as "remote".
+ // Regression test for the prior `b.contains('/')` classification.
+ let items = vec![
+ ListItem::new_branch("aaaaaaa".to_string(), "feature/login".to_string()),
+ ListItem::new_branch("bbbbbbb".to_string(), "main".to_string()),
+ ListItem::new_remote_branch("ccccccc".to_string(), "origin/feature".to_string()),
+ ];
+ let metrics = SummaryMetrics::from_items(&items);
+ assert_eq!(
+ metrics.local_branches, 2,
+ "`feature/login` must count as a local branch"
+ );
+ assert_eq!(metrics.remote_branches, 1);
+ assert_eq!(metrics.worktrees, 0);
+ }
+
#[test]
fn test_summary_metrics_summary_parts_single_worktree() {
let metrics = SummaryMetrics {