Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
feat(list): Show merge conflicts with main
Maximilian Roosead77bf48899
diff --git a/src/commands/list/layout.rs b/src/commands/list/layout.rsindex 14a7cda93..fe7c430c7 100644--- a/src/commands/list/layout.rs+++ b/src/commands/list/layout.rs@@ -58,6 +58,7 @@ pub struct ColumnWidths {pub branch: usize,pub time: usize,pub ci_status: usize,+ pub conflicts: usize,pub message: usize,pub ahead_behind: DiffWidths,pub working_diff: DiffWidths,@@ -75,6 +76,7 @@ pub struct ColumnPositions {pub working_diff: usize,pub ahead_behind: usize,pub branch_diff: usize,+ pub conflicts: usize,pub states: usize,pub path: usize,pub upstream: usize,@@ -210,10 +212,15 @@ pub fn calculate_column_widths(items: &[ListItem]) -> ColumnWidths {let has_ci_status = items.iter().any(|item| item.pr_status().is_some());let ci_status_width = if has_ci_status { 2 } else { 0 };+ // Conflicts column: Always 2 chars wide if any item has conflicts+ let has_conflicts = items.iter().any(|item| item.has_conflicts());+ let conflicts_width = if has_conflicts { 2 } else { 0 };+ColumnWidths {branch: max_branch,time: max_time,ci_status: ci_status_width,+ conflicts: conflicts_width,message: max_message,ahead_behind: DiffWidths {total: ahead_behind_total,@@ -273,14 +280,16 @@ pub fn calculate_responsive_layout(items: &[ListItem]) -> LayoutConfig {// 2. working_diff - uncommitted changes (CRITICAL: do I need to commit?)// 3. ahead_behind - commits difference (CRITICAL: am I ahead/behind?)// 4. branch_diff - line diff in commits (work volume in those commits)- // 5. states - special states like [rebasing] (rare but urgent when present)- // 6. path - location (where is this?)- // 7. upstream - tracking configuration (sync context)- // 8. time - recency (nice-to-have context)- // 9. commit - hash (reference info, rarely needed)- // 10. message - description (nice-to-have, space-hungry)+ // 5. conflicts - merge conflicts with main (CRITICAL: will merge fail?)+ // 6. states - special states like [rebasing] (rare but urgent when present)+ // 7. path - location (where is this?)+ // 8. upstream - tracking configuration (sync context)+ // 9. time - recency (nice-to-have context)+ // 10. ci_status - CI/PR status (contextual when available)+ // 11. commit - hash (reference info, rarely needed)+ // 12. message - description (nice-to-have, space-hungry)//- // Note: ahead_behind and branch_diff are adjacent (both describe commits vs main)+ // Note: ahead_behind, branch_diff, and conflicts are adjacent (all describe commits vs main and mergeability)// Each column is shown if it has any data (ideal_width > 0) and fits in remaining space.// All columns participate in priority allocation - nothing is "essential".@@ -289,6 +298,7 @@ pub fn calculate_responsive_layout(items: &[ListItem]) -> LayoutConfig {branch: 0,time: 0,ci_status: 0,+ conflicts: 0,message: 0,ahead_behind: DiffWidths::zero(),working_diff: DiffWidths::zero(),@@ -335,6 +345,9 @@ pub fn calculate_responsive_layout(items: &[ListItem]) -> LayoutConfig {widths.branch_diff = ideal_widths.branch_diff;}+ // Conflicts column (merge conflicts indicator - critical for mergeability)+ widths.conflicts = try_allocate(&mut remaining, ideal_widths.conflicts, spacing, false);+// States column (rare but urgent when present)widths.states = try_allocate(&mut remaining, ideal_widths.states, spacing, false);@@ -402,6 +415,7 @@ pub fn calculate_responsive_layout(items: &[ListItem]) -> LayoutConfig {working_diff: advance(widths.working_diff.total),ahead_behind: advance(widths.ahead_behind.total),branch_diff: advance(widths.branch_diff.total),+ conflicts: advance(widths.conflicts),states: advance(widths.states),path: advance(widths.path),upstream: advance(widths.upstream.total),@@ -455,6 +469,7 @@ mod tests {upstream: UpstreamStatus::from_parts(Some("origin".to_string()), 4, 0),worktree_state: None,pr_status: None,+ has_conflicts: false,display: DisplayFields::default(),working_diff_display: None,};@@ -526,6 +541,7 @@ mod tests {upstream: UpstreamStatus::from_parts(Some("origin".to_string()), 4, 2),worktree_state: None,pr_status: None,+ has_conflicts: false,display: DisplayFields::default(),working_diff_display: None,};@@ -608,6 +624,7 @@ mod tests {upstream: UpstreamStatus::default(),worktree_state: None,pr_status: None,+ has_conflicts: false,display: DisplayFields::default(),working_diff_display: None,};@@ -670,6 +687,7 @@ mod tests {upstream: UpstreamStatus::default(), // Hidden: no upstreamworktree_state: None, // Hidden: no statepr_status: None,+ has_conflicts: false,display: DisplayFields::default(),working_diff_display: None,};diff --git a/src/commands/list/mod.rs b/src/commands/list/mod.rsindex 918cd436d..6c2c8b9d9 100644--- a/src/commands/list/mod.rs+++ b/src/commands/list/mod.rs@@ -74,12 +74,13 @@ pub fn handle_list(format: crate::OutputFormat,show_branches: bool,fetch_ci: bool,+ check_conflicts: bool,) -> Result<(), GitError> {let repo = Repository::current();let Some(ListData {items,current_worktree_path,- }) = gather_list_data(&repo, show_branches, fetch_ci)?+ }) = gather_list_data(&repo, show_branches, fetch_ci, check_conflicts)?else {return Ok(());};diff --git a/src/commands/list/model.rs b/src/commands/list/model.rsindex 2a5b57fe7..0bef76da7 100644--- a/src/commands/list/model.rs+++ b/src/commands/list/model.rs@@ -34,6 +34,7 @@ pub struct WorktreeInfo {pub upstream: UpstreamStatus,pub worktree_state: Option<String>,pub pr_status: Option<PrStatus>,+ pub has_conflicts: bool,// Display fields for json-pretty format (with ANSI colors)#[serde(flatten)]@@ -55,6 +56,7 @@ pub struct BranchInfo {#[serde(flatten)]pub upstream: UpstreamStatus,pub pr_status: Option<PrStatus>,+ pub has_conflicts: bool,// Display fields for json-pretty format (with ANSI colors)#[serde(flatten)]@@ -244,6 +246,13 @@ impl ListItem {ListItem::Branch(info) => info.pr_status.as_ref(),}}++ pub fn has_conflicts(&self) -> bool {+ match self {+ ListItem::Worktree(info) => info.has_conflicts,+ ListItem::Branch(info) => info.has_conflicts,+ }+ }}impl BranchInfo {@@ -253,6 +262,7 @@ impl BranchInfo {repo: &Repository,primary_branch: Option<&str>,fetch_ci: bool,+ check_conflicts: bool,) -> Result<Self, GitError> {// Get the commit SHA for this branchlet head = repo.run_command(&["rev-parse", branch])?.trim().to_string();@@ -268,6 +278,16 @@ impl BranchInfo {None};+ let has_conflicts = if check_conflicts {+ if let Some(base) = primary_branch {+ repo.has_merge_conflicts(base, &head)?+ } else {+ false+ }+ } else {+ false+ };+Ok(BranchInfo {name: branch.to_string(),head,@@ -276,6 +296,7 @@ impl BranchInfo {branch_diff,upstream,pr_status,+ has_conflicts,display: DisplayFields::default(),})}@@ -287,6 +308,7 @@ impl WorktreeInfo {wt: &worktrunk::git::Worktree,primary: &worktrunk::git::Worktree,fetch_ci: bool,+ check_conflicts: bool,) -> Result<Self, GitError> {let wt_repo = Repository::at(&wt.path);let is_primary = wt.path == primary.path;@@ -310,6 +332,16 @@ impl WorktreeInfo {None};+ let has_conflicts = if check_conflicts {+ if let Some(base) = base_branch {+ wt_repo.has_merge_conflicts(base, &wt.head)?+ } else {+ false+ }+ } else {+ false+ };+Ok(WorktreeInfo {worktree: wt.clone(),commit,@@ -320,6 +352,7 @@ impl WorktreeInfo {upstream,worktree_state,pr_status,+ has_conflicts,display: DisplayFields::default(),working_diff_display: None,})@@ -331,6 +364,7 @@ pub fn gather_list_data(repo: &Repository,show_branches: bool,fetch_ci: bool,+ check_conflicts: bool,) -> Result<Option<ListData>, GitError> {let worktrees = repo.list_worktrees()?;@@ -347,7 +381,7 @@ pub fn gather_list_data(// Gather enhanced information for all worktrees in parallellet worktree_results: Vec<Result<WorktreeInfo, GitError>> = worktrees.par_iter()- .map(|wt| WorktreeInfo::from_worktree(wt, &primary, fetch_ci))+ .map(|wt| WorktreeInfo::from_worktree(wt, &primary, fetch_ci, check_conflicts)).collect();// Build list of items to display (worktrees + optional branches)@@ -372,7 +406,13 @@ pub fn gather_list_data(let branch_results: Vec<(String, Result<BranchInfo, GitError>)> = available_branches.par_iter().map(|branch| {- let result = BranchInfo::from_branch(branch, repo, primary_branch, fetch_ci);+ let result = BranchInfo::from_branch(+ branch,+ repo,+ primary_branch,+ fetch_ci,+ check_conflicts,+ );(branch.clone(), result)}).collect();diff --git a/src/commands/list/render.rs b/src/commands/list/render.rsindex 2c95667be..fb6199b01 100644--- a/src/commands/list/render.rs+++ b/src/commands/list/render.rs@@ -283,6 +283,7 @@ pub fn format_header_line(layout: &LayoutConfig) {positions.branch_diff,dim,);+ push_header_at(&mut line, "⚠️", widths.conflicts, positions.conflicts, dim);push_header_at(&mut line, "State", widths.states, positions.states, dim);push_header_at(&mut line, "Path", widths.path, positions.path, dim);push_header_at(@@ -426,6 +427,19 @@ pub fn format_list_item_line(}}+ // Conflicts indicator+ if widths.conflicts > 0 {+ line.pad_to(positions.conflicts);+ if item.has_conflicts() {+ line.push_styled(+ "⚠️".to_string(),+ Style::new().fg_color(Some(Color::Ansi(AnsiColor::Yellow))),+ );+ } else {+ push_blank(&mut line, widths.conflicts);+ }+ }+// States (worktrees only)if widths.states > 0 {line.pad_to(positions.states);diff --git a/src/git.rs b/src/git.rsindex d5ca07fdf..7ff750765 100644--- a/src/git.rs+++ b/src/git.rs@@ -722,6 +722,28 @@ impl Repository {Ok(output.trim().to_owned())}+ /// Check if merging head into base would result in conflicts.+ ///+ /// Uses `git merge-tree` to simulate a merge without touching the working tree.+ /// Returns true if conflicts would occur, false for a clean merge.+ ///+ /// # Examples+ /// ```no_run+ /// use worktrunk::git::Repository;+ ///+ /// let repo = Repository::current();+ /// let has_conflicts = repo.has_merge_conflicts("main", "feature-branch")?;+ /// # Ok::<(), worktrunk::git::GitError>(())+ /// ```+ pub fn has_merge_conflicts(&self, base: &str, head: &str) -> Result<bool, GitError> {+ let merge_base = self.merge_base(base, head)?;++ // git merge-tree exits with 0 for clean merge, 1 for conflicts+ // run_command_check returns true for exit 0, false otherwise+ let clean_merge = self.run_command_check(&["merge-tree", &merge_base, base, head])?;+ Ok(!clean_merge)+ }+/// Get commit subjects (first line of commit message) from a range.pub fn commit_subjects(&self, range: &str) -> Result<Vec<String>, GitError> {let output = self.run_command(&["log", "--format=%s", range])?;diff --git a/src/main.rs b/src/main.rsindex 98d3b2882..f0361cff8 100644--- a/src/main.rs+++ b/src/main.rs@@ -143,6 +143,15 @@ enum Commands {/// WARNING: Slow! Adds ~0.5-2s per branch (makes network requests).#[arg(long)]ci: bool,++ /// Show all information (CI status + conflict detection)+ ///+ /// Enables both --ci and conflict detection. Shows ⚠️ indicator for branches+ /// that would have merge conflicts with main.+ ///+ /// WARNING: Slow! Runs git merge-tree for every branch to detect conflicts.+ #[arg(long)]+ full: bool,},/// Switch to a worktree@@ -412,7 +421,12 @@ fn main() {format,branches,ci,- } => handle_list(format, branches, ci),+ full,+ } => {+ let fetch_ci = ci || full;+ let check_conflicts = full;+ handle_list(format, branches, fetch_ci, check_conflicts)+ }Commands::Switch {branch,create,diff --git a/tests/snapshots/integration__integration_tests__init__init_bash.snap b/tests/snapshots/integration__integration_tests__init__init_bash.snapindex 38783f861..1482e8cd0 100644--- a/tests/snapshots/integration__integration_tests__init__init_bash.snap+++ b/tests/snapshots/integration__integration_tests__init__init_bash.snap@@ -16,7 +16,7 @@ info:LANG: CLC_ALL: CSOURCE_DATE_EPOCH: "1761609600"- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmptSlwtE/test-config.toml+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpto9WHD/test-config.toml---success: trueexit_code: 0@@ -384,7 +384,7 @@ _wt() {return 0;;wt__list)- opts="-v -h --format --branches --ci --verbose --help"+ opts="-v -h --format --branches --ci --full --verbose --help"if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; thenCOMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )return 0diff --git a/tests/snapshots/integration__integration_tests__init__init_fish.snap b/tests/snapshots/integration__integration_tests__init__init_fish.snapindex dd7ab1751..fb169a385 100644--- a/tests/snapshots/integration__integration_tests__init__init_fish.snap+++ b/tests/snapshots/integration__integration_tests__init__init_fish.snap@@ -16,7 +16,7 @@ info:LANG: CLC_ALL: CSOURCE_DATE_EPOCH: "1761609600"- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpEtNUfC/test-config.toml+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpj1imH2/test-config.toml---success: trueexit_code: 0@@ -253,6 +253,7 @@ complete -c wt -n "__fish_wt_using_subcommand list" -l format -d 'Output format'json\t'JSON format with colored unicode display fields'"complete -c wt -n "__fish_wt_using_subcommand list" -l branches -d 'Also display branches that don\'t have worktrees'complete -c wt -n "__fish_wt_using_subcommand list" -l ci -d 'Fetch CI status from GitHub/GitLab PRs/MRs'+complete -c wt -n "__fish_wt_using_subcommand list" -l full -d 'Show all information (CI status + conflict detection)'complete -c wt -n "__fish_wt_using_subcommand list" -s v -l verbose -d 'Enable verbose output (show git commands and debug info)'complete -c wt -n "__fish_wt_using_subcommand list" -s h -l help -d 'Print help (see more with \'--help\')'complete -c wt -n "__fish_wt_using_subcommand switch" -s b -l base -d 'Base branch to create from (only with --create)' -rdiff --git a/tests/snapshots/integration__integration_tests__init__init_zsh.snap b/tests/snapshots/integration__integration_tests__init__init_zsh.snapindex 70367a81a..121b5a383 100644--- a/tests/snapshots/integration__integration_tests__init__init_zsh.snap+++ b/tests/snapshots/integration__integration_tests__init__init_zsh.snap@@ -16,7 +16,7 @@ info:LANG: CLC_ALL: CSOURCE_DATE_EPOCH: "1761609600"- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpG3qBik/test-config.toml+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpwPTuOe/test-config.toml---success: trueexit_code: 0@@ -261,6 +261,7 @@ _arguments "${_arguments_options[@]}" : \json\:"JSON format with colored unicode display fields"))' \'--branches[Also display branches that don'\''t have worktrees]' \'--ci[Fetch CI status from GitHub/GitLab PRs/MRs]' \+'--full[Show all information (CI status + conflict detection)]' \'-v[Enable verbose output (show git commands and debug info)]' \'--verbose[Enable verbose output (show git commands and debug info)]' \'-h[Print help (see more with '\''--help'\'')]' \diff --git a/tests/snapshots/integration__integration_tests__list__json_with_display_fields.snap b/tests/snapshots/integration__integration_tests__list__json_with_display_fields.snapindex 3646d59f5..247813e9b 100644--- a/tests/snapshots/integration__integration_tests__list__json_with_display_fields.snap+++ b/tests/snapshots/integration__integration_tests__list__json_with_display_fields.snap@@ -16,7 +16,7 @@ info:LANG: CLC_ALL: CSOURCE_DATE_EPOCH: "1761609600"- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpXgpxYO/test-config.toml+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmp3pOwWk/test-config.toml---success: trueexit_code: 0@@ -50,7 +50,8 @@ exit_code: 0"upstream_ahead": 0,"upstream_behind": 0,"worktree_state": null,- "pr_status": null+ "pr_status": null,+ "has_conflicts": false},{"type": "worktree",@@ -81,6 +82,7 @@ exit_code: 0"upstream_behind": 0,"worktree_state": null,"pr_status": null,+ "has_conflicts": false,"commits_display": "[GREEN]↑2[RESET] [DIM][RED]↓2[RESET]","branch_diff_display": "[GREEN]+1[RESET]","working_diff_display": "[GREEN]+1[RESET] [RED]-1[RESET]"@@ -114,6 +116,7 @@ exit_code: 0"upstream_behind": 0,"worktree_state": null,"pr_status": null,+ "has_conflicts": false,"commits_display": "[DIM][RED]↓2[RESET]"}]diff --git a/tests/snapshots/integration__integration_tests__list__json_with_metadata.snap b/tests/snapshots/integration__integration_tests__list__json_with_metadata.snapindex ad746b0a0..16f0e1294 100644--- a/tests/snapshots/integration__integration_tests__list__json_with_metadata.snap+++ b/tests/snapshots/integration__integration_tests__list__json_with_metadata.snap@@ -16,7 +16,7 @@ info:LANG: CLC_ALL: CSOURCE_DATE_EPOCH: "1761609600"- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpWeDjZA/test-config.toml+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpDlUXIn/test-config.toml---success: trueexit_code: 0@@ -50,7 +50,8 @@ exit_code: 0"upstream_ahead": 0,"upstream_behind": 0,"worktree_state": null,- "pr_status": null+ "pr_status": null,+ "has_conflicts": false},{"type": "worktree",@@ -80,7 +81,8 @@ exit_code: 0"upstream_ahead": 0,"upstream_behind": 0,"worktree_state": null,- "pr_status": null+ "pr_status": null,+ "has_conflicts": false},{"type": "worktree",@@ -110,7 +112,8 @@ exit_code: 0"upstream_ahead": 0,"upstream_behind": 0,"worktree_state": null,- "pr_status": null+ "pr_status": null,+ "has_conflicts": false}]