Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
Fix AheadBehind column to show ⋯ when not loaded (#573)
Maximilian Roos0137f362270d
diff --git a/src/commands/list/collect.rs b/src/commands/list/collect.rsindex a5ab94a2b..4be3cb7f9 100644--- a/src/commands/list/collect.rs+++ b/src/commands/list/collect.rs@@ -387,7 +387,7 @@ fn apply_default(items: &mut [ListItem], status_contexts: &mut [StatusContext],items[idx].commit = Some(CommitDetails::default());}TaskKind::AheadBehind => {- items[idx].counts = Some(AheadBehind::default());+ // Leave as None — UI shows `⋯` for not-loaded tasks// Conservative: don't claim orphan if we couldn't checkitems[idx].is_orphan = Some(false);}diff --git a/src/commands/list/mod.rs b/src/commands/list/mod.rsindex 2fae4e9f3..5ca5929f9 100644--- a/src/commands/list/mod.rs+++ b/src/commands/list/mod.rs@@ -256,8 +256,7 @@ impl SummaryMetrics {}}- let counts = item.counts();- if counts.ahead > 0 {+ if item.counts.is_some_and(|c| c.ahead > 0) {self.ahead_items += 1;}}diff --git a/src/commands/list/model.rs b/src/commands/list/model.rsindex c2a6d2dc7..4075e7abf 100644--- a/src/commands/list/model.rs+++ b/src/commands/list/model.rs@@ -434,10 +434,6 @@ impl ListItem {self.commit.clone().unwrap_or_default()}- pub fn counts(&self) -> AheadBehind {- self.counts.unwrap_or_default()- }-pub fn branch_diff(&self) -> Option<&BranchDiffTotals> {self.branch_diff.as_ref()}@@ -551,8 +547,9 @@ impl ListItem {}// 4. Commits ahead/behind main (priority 4)- if let Some(formatted) =- ColumnKind::AheadBehind.format_diff_plain(self.counts().ahead, self.counts().behind)+ if let Some(counts) = self.counts+ && let Some(formatted) =+ ColumnKind::AheadBehind.format_diff_plain(counts.ahead, counts.behind){segments.push(StatuslineSegment::from_column(formatted,@@ -2059,17 +2056,17 @@ mod tests {#[test]fn test_list_item_counts() {+ // New items have no counts computed yetlet item = ListItem::new_branch("abc123".to_string(), "feature".to_string());- let counts = item.counts();- assert_eq!(counts.ahead, 0);- assert_eq!(counts.behind, 0);+ assert!(item.counts.is_none());+ // After setting counts, they're accessiblelet mut item = ListItem::new_branch("abc123".to_string(), "feature".to_string());item.counts = Some(AheadBehind {ahead: 5,behind: 3,});- let counts = item.counts();+ let counts = item.counts.unwrap();assert_eq!(counts.ahead, 5);assert_eq!(counts.behind, 3);}diff --git a/src/commands/list/render.rs b/src/commands/list/render.rsindex f685c20ed..ff68cb586 100644--- a/src/commands/list/render.rs+++ b/src/commands/list/render.rs@@ -333,7 +333,8 @@ impl LayoutConfig {struct ListRowContext<'a> {item: &'a ListItem,worktree_data: Option<&'a WorktreeData>,- counts: AheadBehind,+ /// None means not yet loaded (show `⋯`), Some means computed (may be zero)+ counts: Option<AheadBehind>,/// None means task was skipped (show `…`), Some means computed (may be zero)branch_diff: Option<LineDiff>,upstream: UpstreamStatus,@@ -347,7 +348,7 @@ struct ListRowContext<'a> {impl<'a> ListRowContext<'a> {fn new(item: &'a ListItem, previous_branch: Option<&str>) -> Self {let worktree_data = item.worktree_data();- let counts = item.counts();+ let counts = item.counts;let commit = item.commit_details();let branch_diff = item.branch_diff().map(|bd| bd.diff);let upstream = item.upstream();@@ -469,12 +470,18 @@ impl ColumnLayout {if ctx.item.is_main() {return StyledLine::new();}- let ahead = ctx.counts.ahead;- let behind = ctx.counts.behind;- if ahead == 0 && behind == 0 {- return StyledLine::new();+ match ctx.counts {+ Some(counts) if counts.ahead == 0 && counts.behind == 0 => StyledLine::new(),+ Some(counts) => self.render_diff_cell(counts.ahead, counts.behind),+ None => {+ // Not loaded yet — show spinner+ let mut cell = StyledLine::new();+ let padding = self.width.saturating_sub(1);+ cell.push_raw(" ".repeat(padding));+ cell.push_styled("⋯", Style::new().dimmed());+ cell+ }}- self.render_diff_cell(ahead, behind)}ColumnKind::BranchDiff => {if ctx.item.is_main() {diff --git a/src/commands/select.rs b/src/commands/select.rsindex 8ec050ec2..233d3637c 100644--- a/src/commands/select.rs+++ b/src/commands/select.rs@@ -515,7 +515,7 @@ impl WorktreeSkimItem {let Some(default_branch) = repo.default_branch() else {return cformat!("{INFO_SYMBOL} <bold>{branch}</> has no commits ahead of main\n");};- if self.item.counts().ahead == 0 {+ if self.item.counts.is_some_and(|c| c.ahead == 0) {return cformat!("{INFO_SYMBOL} <bold>{branch}</> has no commits ahead of <bold>{default_branch}</>\n");diff --git a/tests/snapshots/integration__integration_tests__list__list_shows_warning_on_git_error.snap b/tests/snapshots/integration__integration_tests__list__list_shows_warning_on_git_error.snapindex 6057c0608..601cfda01 100644--- a/tests/snapshots/integration__integration_tests__list__list_shows_warning_on_git_error.snap+++ b/tests/snapshots/integration__integration_tests__list__list_shows_warning_on_git_error.snap@@ -31,7 +31,7 @@ exit_code: 0----- stdout -----[1mBranch[0m [1mStatus[0m [1mHEAD±[0m [1mmain↕[0m [1mPath[0m [1mRemote⇅[0m [1mCommit[0m [1mAge[0m [1mMessage@ main [2m^[22m . [2ma1e809f5[0m [2m1d[0m [2mInitial commit-+ feature [33m✗[39m ../repo.feature [2m00000000[0m [2m55y[0m [2m++ feature [33m✗[39m [2m⋯[0m ../repo.feature [2m00000000[0m [2m55y[0m [2m[2m○[22m [2mShowing 2 worktreesdiff --git a/tests/snapshots/integration__integration_tests__list__list_skips_operations_for_prunable_worktrees.snap b/tests/snapshots/integration__integration_tests__list__list_skips_operations_for_prunable_worktrees.snapindex 835d95dd3..9db489cdc 100644--- a/tests/snapshots/integration__integration_tests__list__list_skips_operations_for_prunable_worktrees.snap+++ b/tests/snapshots/integration__integration_tests__list__list_skips_operations_for_prunable_worktrees.snap@@ -7,7 +7,7 @@ info:env:APPDATA: "[TEST_CONFIG_HOME]"CLICOLOR_FORCE: "1"- COLUMNS: "150"+ COLUMNS: "500"GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"@@ -31,7 +31,7 @@ exit_code: 0----- stdout -----[1mBranch[0m [1mStatus[0m [1mHEAD±[0m [1mmain↕[0m [1mPath[0m [1mRemote⇅[0m [1mCommit[0m [1mAge[0m [1mMessage@ main [2m^[22m . [2ma1e809f5[0m [2m1d[0m [2mInitial commit-+ feature [33m⊟[39m ../repo.feature [2ma1e809f5[0m [2m⋯[0m [2m⋯++ feature [33m⊟[39m [2m⋯[0m ../repo.feature [2ma1e809f5[0m [2m⋯[0m [2m⋯[2m○[22m [2mShowing 2 worktrees