Conversation
If using git worktrees, appends the path of the branch's checkout to the output of gb. If not using git worktrees, the output is unaffected. Sample output: » gb * [1] main [2] tmp + [3] worktree-support (/tmp/worktree-support)
|
@coderabbitai /review |
|
✅ Actions performedReview triggered.
|
📝 WalkthroughWalkthroughThe git branch shortcuts shell script undergoes comprehensive refactoring, replacing simple line numbering with Ruby-driven formatting logic. New helper functions parse worktrees, map branches, detect current branch, compute alignment widths, and format output with conditional worktree path annotations. Changes
Estimated Code Review Effort🎯 4 (Complex) | ⏱️ ~40 minutes 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
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@lib/git/branch_shortcuts.sh`:
- Around line 26-39: The build_worktree_to_branch_map function currently only
records worktrees that have a branch line (worktree_map), so detached current
worktrees are ignored; update this routine to also count total worktrees
discovered from git worktree list --porcelain (e.g., increment a total_worktrees
counter whenever you see a "worktree " line) and return that count alongside
worktree_map (or expose it via a renamed return like [worktree_map,
total_worktrees]) so callers (where show_worktrees is decided) can use
total_worktrees instead of worktree_map.size to decide whether to show paths;
keep using the existing variables (worktree_output, current_worktree,
worktree_map) and only add a total counter and the corresponding return change
so callers at the other usage sites (lines ~91-96) can be updated to read the
new count.
| def build_worktree_to_branch_map(git_cmd) | ||
| worktree_map = {} | ||
| worktree_output = %x(#{git_cmd} worktree list --porcelain 2>/dev/null) | ||
| current_worktree = nil | ||
| worktree_output.lines.each do |line| | ||
| if line.start_with?('worktree ') | ||
| current_worktree = line[9..-1].strip | ||
| elsif line.start_with?('branch refs/heads/') && current_worktree | ||
| branch_name = line[18..-1].strip | ||
| worktree_map[branch_name] = current_worktree | ||
| current_worktree = nil | ||
| end | ||
| end | ||
| worktree_map |
There was a problem hiding this comment.
Handle detached-current-worktree cases when deciding to show paths.
show_worktrees is keyed off worktree_map.size, which only counts worktrees that have a branch line. If the current worktree is detached and there is only one other worktree branch, paths won’t be shown even though worktrees are in use. Consider tracking the total number of worktrees from git worktree list --porcelain and use that to gate show_worktrees.
🔧 Suggested fix
def build_worktree_to_branch_map(git_cmd)
worktree_map = {}
worktree_output = %x(#{git_cmd} worktree list --porcelain 2>/dev/null)
+ worktree_count = 0
current_worktree = nil
worktree_output.lines.each do |line|
if line.start_with?('worktree ')
+ worktree_count += 1
current_worktree = line[9..-1].strip
elsif line.start_with?('branch refs/heads/') && current_worktree
branch_name = line[18..-1].strip
worktree_map[branch_name] = current_worktree
current_worktree = nil
end
end
- worktree_map
+ [worktree_map, worktree_count]
end
@@
- worktree_map = build_worktree_to_branch_map('$_git_cmd')
+ worktree_map, worktree_count = build_worktree_to_branch_map('$_git_cmd')
@@
- show_worktrees = worktree_map.size > 1
+ show_worktrees = worktree_count > 1Also applies to: 91-96
🤖 Prompt for AI Agents
In `@lib/git/branch_shortcuts.sh` around lines 26 - 39, The
build_worktree_to_branch_map function currently only records worktrees that have
a branch line (worktree_map), so detached current worktrees are ignored; update
this routine to also count total worktrees discovered from git worktree list
--porcelain (e.g., increment a total_worktrees counter whenever you see a
"worktree " line) and return that count alongside worktree_map (or expose it via
a renamed return like [worktree_map, total_worktrees]) so callers (where
show_worktrees is decided) can use total_worktrees instead of worktree_map.size
to decide whether to show paths; keep using the existing variables
(worktree_output, current_worktree, worktree_map) and only add a total counter
and the corresponding return change so callers at the other usage sites (lines
~91-96) can be updated to read the new count.
If using git worktrees, appends the path of the branch's checkout to the output of gb. If not using git worktrees, the output is unaffected.
Sample output:
Summary by CodeRabbit
Refactor
✏️ Tip: You can customize this high-level summary in your review settings.