Skip to content

Add visual branch comparison workflow - #19

Merged
Tranthanh98 merged 2 commits into
mainfrom
codex/visual-compare-branches
Sep 21, 2026
Merged

Tranthanh98 merged 2 commits into
mainfrom
codex/visual-compare-branches

Conversation

@Tranthanh98

@Tranthanh98 Tranthanh98 commented Sep 21, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Adds a read-only visual workflow for comparing any two local or remote-tracking branches without checking either branch out. Branch context menus now expose Compare with..., opening History with editable base/target selectors, swap support, merge-base metadata, ahead/behind counts, commit lists, file changes, and per-file diffs.

The comparison defaults to merge-base mode and also supports explicit tip-to-tip mode. Git execution is pinned to resolved commit SHAs, handles rename/binary/empty states, supports cancellable async loads, and guards against stale results updating the UI.

Validation

  • rtk git diff --check
  • rtk proxy xcodebuild -project macgit.xcodeproj -scheme macgit -destination 'platform=macOS' build
  • Earlier focused XCTest pass for branch comparison/controller coverage and related diff tests: 20 tests, 0 failures

Runtime UI interaction was not checked by launching the app, per repo guidance to build without launching.

Closes #13

Summary by CodeRabbit

  • New Features
    • Added branch and reference comparison views with merge-base and tip-to-tip modes.
    • Compare local or remote branches from the sidebar.
    • View changed files, rendered diffs, binary files, renames, and truncated patches.
    • Browse commits unique to either branch with pagination and retry support.
    • Added branch swapping, refresh, cancellation, and comparison status indicators.
    • Context menus now correctly target the selected history row.
  • Bug Fixes
    • Improved handling of detached heads, unrelated histories, stale requests, and comparison errors.
    • Changed-file history now displays previous paths for renamed files.

@coderabbitai

coderabbitai Bot commented Sep 21, 2026 •

Copy link
Copy Markdown

Review Change StackReview Change Stack

Understand this PR’s impact

Explore downstream dependencies and potential security impact with Blast Radius.

View blast radius →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 0776f578-522f-469c-a18e-f66e0ac81baa

📥 Commits

Reviewing files that changed from the base of the PR and between b8128c9 and 384101b.

📒 Files selected for processing (25)
  • macgit/App/ReferenceComparisonController.swift
  • macgit/Models/ComparisonBranch.swift
  • macgit/Models/ReferenceComparisonMode.swift
  • macgit/Models/ReferenceComparisonPatch.swift
  • macgit/Models/ReferenceComparisonSnapshot.swift
  • macgit/Services/Commit.swift
  • macgit/Services/GitDiffModels.swift
  • macgit/Services/GitStatusService+BranchComparison.swift
  • macgit/Services/GitStatusService+Commit.swift
  • macgit/Services/ReferenceComparisonServing.swift
  • macgit/Views/Common/DiffView.swift
  • macgit/Views/Common/ReferenceComparisonCommitsView.swift
  • macgit/Views/Common/ReferenceComparisonFilesView.swift
  • macgit/Views/Common/ReferenceDiffView.swift
  • macgit/Views/History/CommitFileListView.swift
  • macgit/Views/History/HistoryTableScrollCoordinator.swift
  • macgit/Views/History/HistoryView.swift
  • macgit/Views/MainWindow/MainWindowView.swift
  • macgit/Views/MainWindow/Sidebar/SidebarBranchContextMenu.swift
  • macgit/Views/MainWindow/Sidebar/SidebarBranchSectionActions.swift
  • macgit/Views/MainWindow/Sidebar/SidebarRemoteContextMenu.swift
  • macgit/Views/MainWindow/Sidebar/SidebarRemoteSectionActions.swift
  • macgit/Views/MainWindow/SidebarView.swift
  • macgitTests/BranchComparisonServiceTests.swift
  • macgitTests/ReferenceComparisonControllerTests.swift
💤 Files with no reviewable changes (1)
  • macgit/Views/Common/DiffView.swift

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

This change adds a branch comparison workflow with Git-backed snapshots, changed files, patches, unique commits, branch controls, cancellation, stale-result protection, and local or remote branch entry points. It also adds history context-click handling.

Changes

Branch comparison workflow

Layer / File(s) Summary
Comparison contracts and data models
macgit/Models/*, macgit/Services/Commit.swift, macgit/Services/GitDiffModels.swift, macgit/Services/ReferenceComparisonServing.swift
Adds comparison modes, branch and snapshot models, patch data, service contracts, and concurrency conformances.
Git comparison operations
macgit/Services/GitStatusService+BranchComparison.swift, macgit/Services/GitStatusService+Commit.swift
Adds reference validation, snapshots, changed-file parsing, commit pagination, bounded patch retrieval, rename handling, and cancellation checks.
Comparison orchestration and async state
macgit/App/ReferenceComparisonController.swift, macgitTests/ReferenceComparisonControllerTests.swift
Adds reloads, snapshot reuse, cancellation, stale-result checks, file patch loading, commit pagination, and asynchronous controller tests.
Comparison views and file presentation
macgit/Views/Common/ReferenceDiffView.swift, macgit/Views/Common/ReferenceComparisonFilesView.swift, macgit/Views/Common/ReferenceComparisonCommitsView.swift, macgit/Views/Common/DiffView.swift, macgit/Views/History/CommitFileListView.swift
Adds the comparison screen and its file and commit panes. It removes the previous reference comparison view and displays rename paths, binary files, empty diffs, and truncated patches.
Window and sidebar integration
macgit/Views/MainWindow/*, macgit/Views/MainWindow/Sidebar/*, macgitTests/BranchComparisonServiceTests.swift
Adds local and remote Compare with actions, connects branch selections to the main window, renders controller-backed comparisons, and adds Git integration coverage.

History context menu handling

Layer / File(s) Summary
History context-click handling
macgit/Views/History/HistoryTableScrollCoordinator.swift, macgit/Views/History/HistoryView.swift
Adds table-local right-click and control-click monitoring, clicked-row selection, monitor cleanup, and per-cell commit context menus.

Priority: ➖ Normal

Estimated code review effort: 4 (Complex) | ~60 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant SidebarView
  participant MainWindowView
  participant ReferenceComparisonController
  participant GitStatusService
  participant ReferenceDiffView
  SidebarView->>MainWindowView: request comparison for selected branch
  MainWindowView->>ReferenceComparisonController: create base and target state
  ReferenceDiffView->>ReferenceComparisonController: reload comparison
  ReferenceComparisonController->>GitStatusService: fetch snapshot, files, commits, and patches
  GitStatusService-->>ReferenceComparisonController: return comparison results
  ReferenceComparisonController-->>ReferenceDiffView: update loading, errors, and content
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 54 functions across 24 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the primary change: adding a visual branch comparison workflow.
Linked Issues check ✅ Passed Issue #13 coding requirements are implemented. Local and remote-tracking branch menus expose Compare with..., and MainWindowView opens the comparison workflow without checkout. ReferenceComparisonCont…
Out of Scope Changes check ✅ Passed The changes stay within issue #13. Context-menu monitoring enables branch actions. CommitFileChange oldPath and CommitFileListView support rename presentation. ReferenceDiffView replacement and the co…
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

Comment @coderabbitai help to get the list of available commands.

@Tranthanh98
Tranthanh98 merged commit a97630e into main Sep 21, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a visual Compare Branches workflow

1 participant