Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
Simplify `WorkingTreeDiff` and `StatusSymbols`
Maximilian Roosdd50fde58a58
diff --git a/src/commands/list/collect.rs b/src/commands/list/collect.rsindex 872e3f435..24affa89d 100644--- a/src/commands/list/collect.rs+++ b/src/commands/list/collect.rs@@ -56,7 +56,6 @@ pub(super) enum CellUpdate {working_tree_diff_with_main: Option<LineDiff>,/// Symbols for uncommitted changes (?, !, +, », ✘)working_tree_symbols: String,- is_dirty: bool,has_conflicts: bool,},/// Potential merge conflicts with main (merge-tree simulation)@@ -214,6 +213,8 @@ fn compute_item_status_symbols(default_branch: Option<&str>,has_merge_tree_conflicts: bool,user_status: Option<String>,+ working_tree_symbols: Option<&str>,+ has_conflicts: bool,) {// Common fields for both worktrees and brancheslet default_counts = AheadBehind::default();@@ -253,7 +254,6 @@ fn compute_item_status_symbols(};// Combine conflicts and branch state (mutually exclusive)- let has_conflicts = data.has_conflicts.unwrap_or(false);let branch_state = if has_conflicts {BranchState::Conflicts} else if has_merge_tree_conflicts {@@ -266,15 +266,9 @@ fn compute_item_status_symbols(branch_state,git_operation,item_attrs,- locked: data.locked.clone(),- prunable: data.prunable.clone(),main_divergence,upstream_divergence,- working_tree: data- .working_tree_symbols- .as_deref()- .unwrap_or("")- .to_string(),+ working_tree: working_tree_symbols.unwrap_or("").to_string(),user_status,});}@@ -300,8 +294,6 @@ fn compute_item_status_symbols(branch_state,git_operation: GitOperation::None,item_attrs: "⎇".to_string(), // Branch indicator- locked: None,- prunable: None,main_divergence,upstream_divergence,working_tree: String::new(),@@ -320,11 +312,13 @@ fn compute_item_status_symbols(fn drain_cell_updates(rx: chan::Receiver<CellUpdate>,items: &mut [ListItem],- mut on_update: impl FnMut(usize, &mut ListItem, bool, Option<String>),+ mut on_update: impl FnMut(usize, &mut ListItem, bool, Option<String>, Option<&str>, bool),) {// Temporary storage for data needed by status_symbols computationlet mut merge_tree_conflicts_map: Vec<Option<bool>> = vec![None; items.len()];let mut user_status_map: Vec<Option<Option<String>>> = vec![None; items.len()];+ let mut working_tree_symbols_map: Vec<Option<String>> = vec![None; items.len()];+ let mut has_conflicts_map: Vec<Option<bool>> = vec![None; items.len()];// Process cell updates as they arrivewhile let Ok(update) = rx.recv() {@@ -348,16 +342,15 @@ fn drain_cell_updates(working_tree_diff,working_tree_diff_with_main,working_tree_symbols,- is_dirty,has_conflicts,} => {if let ItemKind::Worktree(data) = &mut items[item_idx].kind {data.working_tree_diff = Some(working_tree_diff);data.working_tree_diff_with_main = Some(working_tree_diff_with_main);- data.working_tree_symbols = Some(working_tree_symbols);- data.is_dirty = Some(is_dirty);- data.has_conflicts = Some(has_conflicts);}+ // Store temporarily for status_symbols computation+ working_tree_symbols_map[item_idx] = Some(working_tree_symbols);+ has_conflicts_map[item_idx] = Some(has_conflicts);}CellUpdate::MergeTreeConflicts {item_idx,@@ -396,11 +389,15 @@ fn drain_cell_updates(// Invoke rendering callback (progressive mode re-renders rows, buffered mode does nothing)let has_merge_tree_conflicts = merge_tree_conflicts_map[item_idx].unwrap_or(false);let user_status = user_status_map[item_idx].clone().unwrap_or(None);+ let working_tree_symbols = working_tree_symbols_map[item_idx].as_deref();+ let has_conflicts = has_conflicts_map[item_idx].unwrap_or(false);on_update(item_idx,&mut items[item_idx],has_merge_tree_conflicts,user_status,+ working_tree_symbols,+ has_conflicts,);}}@@ -694,7 +691,12 @@ pub fn collect(drain_cell_updates(rx,&mut all_items,- |item_idx, item, has_merge_tree_conflicts, user_status| {+ |item_idx,+ item,+ has_merge_tree_conflicts,+ user_status,+ working_tree_symbols,+ has_conflicts| {// Compute/recompute status symbols as data arrives (both modes)// This is idempotent and updates status as new data (like upstream) arriveslet item_default_branch = if item.is_main() {@@ -707,6 +709,8 @@ pub fn collect(item_default_branch,has_merge_tree_conflicts,user_status,+ working_tree_symbols,+ has_conflicts,);// Progressive mode only: update UIdiff --git a/src/commands/list/collect_progressive_impl.rs b/src/commands/list/collect_progressive_impl.rsindex 920ec1d65..d35a2bd44 100644--- a/src/commands/list/collect_progressive_impl.rs+++ b/src/commands/list/collect_progressive_impl.rs@@ -146,7 +146,6 @@ fn spawn_working_tree_diff<'scope>(working_tree_diff: LineDiff::default(),working_tree_diff_with_main: None,working_tree_symbols: String::new(),- is_dirty: false,has_conflicts: false,});return;@@ -175,7 +174,6 @@ fn spawn_working_tree_diff<'scope>(working_tree_diff,working_tree_diff_with_main,working_tree_symbols,- is_dirty,has_conflicts,});});diff --git a/src/commands/list/layout.rs b/src/commands/list/layout.rsindex 00abe6cc6..4860453db 100644--- a/src/commands/list/layout.rs+++ b/src/commands/list/layout.rs@@ -841,9 +841,6 @@ mod tests {working_tree_diff_with_main: Some(Some(LineDiff::default())),worktree_state: None,is_main: false,- working_tree_symbols: Some(String::new()),- is_dirty: Some(false),- has_conflicts: Some(false),working_diff_display: None,})),};@@ -927,9 +924,6 @@ mod tests {working_tree_diff_with_main: Some(Some(LineDiff::default())),worktree_state: None,is_main: true, // Primary worktree: no ahead/behind shown- working_tree_symbols: Some(String::new()),- is_dirty: Some(false),- has_conflicts: Some(false),working_diff_display: None,})),};diff --git a/src/commands/list/model.rs b/src/commands/list/model.rsindex 22c501000..64c58c37c 100644--- a/src/commands/list/model.rs+++ b/src/commands/list/model.rs@@ -61,9 +61,9 @@ pub struct WorktreeData {pub path: PathBuf,pub bare: bool,pub detached: bool,- #[serde(skip)]+ #[serde(skip_serializing_if = "Option::is_none")]pub locked: Option<String>,- #[serde(skip)]+ #[serde(skip_serializing_if = "Option::is_none")]pub prunable: Option<String>,#[serde(skip_serializing_if = "Option::is_none")]pub working_tree_diff: Option<LineDiff>,@@ -76,15 +76,6 @@ pub struct WorktreeData {pub working_tree_diff_with_main: Option<Option<LineDiff>>,pub worktree_state: Option<String>,pub is_main: bool,- /// Working tree symbols (?, !, +, », ✘) - used for status computation, not serialized- #[serde(skip)]- pub(crate) working_tree_symbols: Option<String>,- /// is_dirty flag - used for status computation, not serialized- #[serde(skip)]- pub(crate) is_dirty: Option<bool>,- /// Unresolved paths present in working tree (merge or rebase conflicts)- #[serde(skip)]- pub(crate) has_conflicts: Option<bool>,#[serde(skip_serializing_if = "Option::is_none")]pub working_diff_display: Option<String>,}@@ -506,15 +497,8 @@ pub struct StatusSymbols {/// Item type attributes: ⎇ for branches, ⌫⊠ for worktrees (priority-only: prunable > locked)/// Priority-only rendering (shows highest priority symbol when multiple states exist)- /// Note: Serialized as "worktree_attrs" in JSON for API compatibilitypub(crate) item_attrs: String,- /// Worktree locked status - None for branches, Some("reason") or None for worktrees- pub(crate) locked: Option<String>,-- /// Worktree prunable status - None for branches, Some("reason") or None for worktrees- pub(crate) prunable: Option<String>,-/// Main branch divergence state (mutually exclusive)pub(crate) main_divergence: MainDivergence,@@ -716,20 +700,11 @@ impl WorkingTreeChanges {}}-/// Worktree attributes (locked/prunable info)-#[derive(Debug, Clone, serde::Serialize)]-struct WorktreeAttrs {- locked: Option<String>,- prunable: Option<String>,-}-/// Status variant names (for queryability)#[derive(Debug, Clone, serde::Serialize)]struct QueryableStatus {branch_state: &'static str,git_operation: &'static str,- #[serde(skip_serializing_if = "Option::is_none")]- worktree_attrs: Option<WorktreeAttrs>,main_divergence: &'static str,upstream_divergence: &'static str,working_tree: WorkingTreeChanges,@@ -787,20 +762,9 @@ impl serde::Serialize for StatusSymbols {UpstreamDivergence::Diverged => "Diverged",};- // Create worktree_attrs if this is a worktree (has locked/prunable)- let worktree_attrs = if self.locked.is_some() || self.prunable.is_some() {- Some(WorktreeAttrs {- locked: self.locked.clone(),- prunable: self.prunable.clone(),- })- } else {- None- };-let queryable_status = QueryableStatus {branch_state: branch_state_variant,git_operation: git_operation_variant,- worktree_attrs,main_divergence: main_divergence_variant,upstream_divergence: upstream_divergence_variant,working_tree: WorkingTreeChanges::from_symbols(&self.working_tree),diff --git a/tests/snapshots/integration__integration_tests__list__json_with_metadata.snap b/tests/snapshots/integration__integration_tests__list__json_with_metadata.snapindex 8bdc984f3..b7ff961de 100644--- a/tests/snapshots/integration__integration_tests__list__json_with_metadata.snap+++ b/tests/snapshots/integration__integration_tests__list__json_with_metadata.snap@@ -145,10 +145,6 @@ exit_code: 0"status": {"branch_state": "MatchesMain","git_operation": "",- "worktree_attrs": {- "locked": "Testing",- "prunable": null- },"main_divergence": "","upstream_divergence": "","working_tree": {@@ -171,6 +167,7 @@ exit_code: 0"path": "[WORKTREE_LOCKED_FEATURE]","bare": false,"detached": false,+ "locked": "Testing","working_tree_diff": {"added": 0,"deleted": 0