feat: show origin merge status and fix file counts in worktree commands#4
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
✅ Files skipped from review due to trivial changes (1)
📝 WalkthroughWalkthroughAdded 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
Sequence DiagramsequenceDiagram
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
Estimated Code Review Effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly Related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (7)
.worktreercCHANGELOG.mdpackage.jsonsrc/commands/list.tssrc/commands/open.tssrc/commands/remove.tssrc/lib/git.ts
|
@coderabbitai full review |
✅ Actions performedFull review triggered. |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/commands/list.ts (1)
76-93: Consider noting (or refreshing) stale origin state inlist.Unlike
remove,listnever callsgitFetch(), sostatus.isMergedreflects whatever was last fetched intoorigin/<defaultBranch>. Users runningworktree listin 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 asremove) 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 anyisMergedvalue 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
📒 Files selected for processing (7)
.worktreercCHANGELOG.mdpackage.jsonsrc/commands/list.tssrc/commands/open.tssrc/commands/remove.tssrc/lib/git.ts
…, distinguish merge-check errors
Summary by CodeRabbit
New Features
Behavior Changes
Bug Fixes
Chores