Skip to content

feat: show origin merge status and fix file counts in worktree commands#4

Merged
bhagyamudgal merged 3 commits intomainfrom
feat/show-origin-branch-status
Apr 17, 2026
Merged

feat: show origin merge status and fix file counts in worktree commands#4
bhagyamudgal merged 3 commits intomainfrom
feat/show-origin-branch-status

Conversation

@bhagyamudgal
Copy link
Copy Markdown
Owner

@bhagyamudgal bhagyamudgal commented Apr 17, 2026

Summary by CodeRabbit

  • New Features

    • Commands now show origin merge status alongside local branch info
    • Worktree selection hints include merge status and local-change indicators
    • Configurable default base branch used for origin merge comparisons
  • Behavior Changes

    • Remove fetches origin before checks (fetch failures treated non‑fatally), always prompts once, and shows detailed status (uncommitted changes, unpushed commits, merge state)
    • List/open use the configured default base when evaluating branch status
  • Bug Fixes

    • Improved file-count accuracy in status reporting
  • Chores

    • Version bumped to 1.2.0

@bhagyamudgal bhagyamudgal self-assigned this Apr 17, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 17, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 4f0ebc41-32eb-4e55-be71-1ea924206893

📥 Commits

Reviewing files that changed from the base of the PR and between f0348ed and fec75e6.

📒 Files selected for processing (2)
  • CHANGELOG.md
  • src/lib/git.ts
✅ Files skipped from review due to trivial changes (1)
  • CHANGELOG.md

📝 Walkthrough

Walkthrough

Added origin-merge awareness and default-branch resolution via a new BranchStatus type and git helpers; list/open/remove now compute and display merge status relative to a configurable DEFAULT_BASE (from .worktreerc). remove fetches origin before checks and reports detailed pre-removal branch state.

Changes

Cohort / File(s) Summary
Configuration & Metadata
/.worktreerc, CHANGELOG.md, package.json
Add .worktreerc entry DEFAULT_BASE=origin/main; bump package version to 1.2.0; document origin-merge visibility and enhanced remove reporting; switch file-counting to git status --porcelain=v2 -uall.
Git Utilities
src/lib/git.ts
Introduce exported BranchStatus type and new helpers: getDefaultBranch(), checkMergedIntoOrigin(), gitBranchStatus(), formatBranchStatusHint(); update gitStatusCount to use --porcelain=v2 -uall; change selectWorktree() to accept optional defaultBranch; remove gitStatusCount/gitAheadBehind from public surface.
Commands: list
src/commands/list.ts
Compute defaultBranch, prefetch per-worktree gitBranchStatus() concurrently, change printWorktreeInfo to accept BranchStatus, and append origin: merged/not-merged to status output.
Commands: open
src/commands/open.ts
Load defaultBranch and pass it into selectWorktree() during interactive selection when opts.name is omitted.
Commands: remove
src/commands/remove.ts
Run git fetch (non-fatal) and compute defaultBranch up-front; use gitBranchStatus() and gitBranchShowCurrent() to show uncommitted/unpushed/merge status; adjust confirmation flow to a single prompt and apply forced removal only when needed.

Sequence Diagram

sequenceDiagram
    actor User
    participant CLI as Worktree CLI
    participant GitLib as Git Utilities
    participant Origin as Remote(origin)
    participant Repo as Local Repo

    User->>CLI: run remove command
    activate CLI
    CLI->>GitLib: gitFetch()  (parallel)
    CLI->>GitLib: getDefaultBranch(config.DEFAULT_BASE)
    GitLib->>Origin: fetch
    GitLib->>Repo: resolve refs/remotes/origin/HEAD or use config
    GitLib-->>CLI: defaultBranch (or null) & fetch result
    CLI->>GitLib: gitBranchStatus(worktreePath, defaultBranch)
    GitLib->>Repo: count changes (--porcelain=v2 -uall)
    GitLib->>Repo: compute ahead/behind vs defaultBranch
    GitLib->>Repo: checkMergedIntoOrigin(origin/defaultBranch)
    GitLib-->>CLI: BranchStatus {changes,ahead,behind,isMerged}
    CLI->>User: display status (uncommitted, unpushed, origin merged?)
    User->>CLI: confirm removal
    CLI->>Repo: git worktree remove [maybe --force]
    CLI->>User: success/warning based on merge status
    deactivate CLI
Loading

Estimated Code Review Effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly Related PRs

Poem

🐇 I hopped through refs and counted files,

I sniffed for origin, crossed the miles,
I fetched, I checked, then gave a sign —
"Are you sure?" I asked, polite and fine,
The rabbit nods: your branches align.

🚥 Pre-merge checks | ✅ 2 | ❌ 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%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely summarizes the two main changes: adding origin merge status visibility across worktree commands and fixing file count calculations via the --porcelain=v2 flag.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/show-origin-branch-status

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/lib/git.ts`:
- Around line 180-222: getDefaultBranch currently returns configBase verbatim
which can be "origin/main" causing checkMergedIntoOrigin to form
"origin/origin/main" and always fail; update getDefaultBranch to normalize
configBase by stripping any "refs/remotes/origin/" or leading "origin/" prefix
and return just the bare branch name (e.g., "main"), so checkMergedIntoOrigin's
`origin/${defaultBranch}` is correct; keep existing auto-detect behavior that
already strips "refs/remotes/origin/". Also add unit tests that assert behavior
for both a configured DEFAULT_BASE of "origin/main" and the auto-detect path
returning "main" and that checkMergedIntoOrigin returns the expected
merged/unmerged results.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: cf61970f-c524-4b12-9d99-adfb05e0e494

📥 Commits

Reviewing files that changed from the base of the PR and between d423184 and 1726f49.

📒 Files selected for processing (7)
  • .worktreerc
  • CHANGELOG.md
  • package.json
  • src/commands/list.ts
  • src/commands/open.ts
  • src/commands/remove.ts
  • src/lib/git.ts

Comment thread src/lib/git.ts
@bhagyamudgal
Copy link
Copy Markdown
Owner Author

@coderabbitai full review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 17, 2026

✅ Actions performed

Full review triggered.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/commands/list.ts (1)

76-93: Consider noting (or refreshing) stale origin state in list.

Unlike remove, list never calls gitFetch(), so status.isMerged reflects whatever was last fetched into origin/<defaultBranch>. Users running worktree list in a stale clone may see "not merged" for branches that have already been merged upstream (or vice versa). Two lightweight options:

  • Perform a non-fatal gitFetch() (same pattern as remove) before computing statuses.
  • Or just append a one-time hint (e.g., "origin status may be stale; run 'git fetch' for latest") to the header when any isMerged value is shown.

Not a blocker — the current behavior is defensible for a "fast read-only" command, but worth a conscious decision.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/commands/list.ts` around lines 76 - 93, The list command computes branch
status from gitBranchStatus for each worktree (using worktreeEntries, rows,
getDefaultBranch) but never refreshes origin, so status.isMerged can be stale;
update list to perform a non-fatal gitFetch() before mapping worktreeEntries to
rows (mirror the pattern used in remove: call gitFetch() and ignore fetch
errors) so statuses reflect up-to-date origin/<defaultBranch>, or alternatively,
if you prefer not to fetch, append a one-time hint to the printed header (after
printHeader/under the divider) warning that "origin status may be stale; run
'git fetch' for latest" whenever any status.isMerged value is displayed.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/lib/git.ts`:
- Around line 215-228: The checkMergedIntoOrigin function currently treats any
non-zero exit from run as "not merged"; change it to distinguish exitCode 0 =>
return true, exitCode 1 => return false, and any other non-zero exit (errors
such as missing origin/{defaultBranch} or invalid HEAD) => return null so
callers can show unknown state; use the existing run call and inspect
result.exitCode (and optionally result.stderr) to decide between these three
outcomes, keeping the early return for null defaultBranch.

---

Nitpick comments:
In `@src/commands/list.ts`:
- Around line 76-93: The list command computes branch status from
gitBranchStatus for each worktree (using worktreeEntries, rows,
getDefaultBranch) but never refreshes origin, so status.isMerged can be stale;
update list to perform a non-fatal gitFetch() before mapping worktreeEntries to
rows (mirror the pattern used in remove: call gitFetch() and ignore fetch
errors) so statuses reflect up-to-date origin/<defaultBranch>, or alternatively,
if you prefer not to fetch, append a one-time hint to the printed header (after
printHeader/under the divider) warning that "origin status may be stale; run
'git fetch' for latest" whenever any status.isMerged value is displayed.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 8f7598b1-7f72-4b7b-9428-328d7deadfa1

📥 Commits

Reviewing files that changed from the base of the PR and between d423184 and f0348ed.

📒 Files selected for processing (7)
  • .worktreerc
  • CHANGELOG.md
  • package.json
  • src/commands/list.ts
  • src/commands/open.ts
  • src/commands/remove.ts
  • src/lib/git.ts

Comment thread src/lib/git.ts
@bhagyamudgal bhagyamudgal merged commit 5b80977 into main Apr 17, 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.

1 participant