feat(tui): show current git branch in status bar#23
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
🚧 Files skipped from review as they are similar to previous changes (3)
📝 WalkthroughWalkthroughAdds filesystem-based git branch detection and polling to the TUI, reads/parses ChangesGit Branch Detection and Display
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. 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.
Pull request overview
Adds lightweight Git branch detection to the TUI so the current repo branch (or detached SHA) is shown in the status bar without invoking git, polling .git/HEAD every ~2s and supporting worktrees and nested config roots.
Changes:
- Adds
branchstate toTUIand refreshes it on the main loop’s periodic housekeeping tick. - Renders
git:<branch>on the right side of the status bar when available. - Introduces
readBranch/findGitDirimplementation plus unit tests covering normal repos, nested dirs, detached HEAD, and worktrees.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| internal/tui/tui.go | Stores branch state on TUI and polls it during the periodic housekeeping tick. |
| internal/tui/render.go | Renders git:<branch> on the right side of the status bar when non-empty. |
| internal/tui/branch.go | Implements repo discovery + HEAD parsing (including worktree indirection) and polling throttling. |
| internal/tui/branch_test.go | Adds unit tests validating branch resolution across repo/worktree scenarios. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Reads HEAD directly from .git (handling worktree indirection) on a 2s poll, displayed as "git:<name>" between battery and keyboard shortcuts. Walks upward from projectRoot so a config root inside a subdirectory still resolves the enclosing repo. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
d648d33 to
b798cb1
Compare
b798cb1 to
1b743a0
Compare
1b743a0 to
123330d
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@internal/tui/render_test.go`:
- Around line 486-504: The test TestRenderHints_BranchTruncated should also
assert the clock remains visible: after building `line` (the rendered bottom row
produced by TUI.renderHints with `branch` set to `long`), compute the current
clock string with `time.Now().Format("15:04")` and assert that `line` contains
that clock string (similar to the existing branch truncation check) so the test
verifies both truncation and clock visibility.
🪄 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: defaults
Review profile: CHILL
Plan: Pro
Run ID: 8708beaa-48c7-4ec1-9054-a6dddb4bec31
📒 Files selected for processing (5)
internal/tui/branch.gointernal/tui/branch_test.gointernal/tui/render.gointernal/tui/render_test.gointernal/tui/tui.go
🚧 Files skipped from review as they are similar to previous changes (3)
- internal/tui/render.go
- internal/tui/tui.go
- internal/tui/branch.go
123330d to
f464076
Compare
readBranch previously fell back to "first 7 chars of HEAD" whenever the file didn't start with "ref: refs/heads/". That meant non-branch refs (tags, remotes) and malformed HEADs leaked partial text like "ref: re" into the status bar. We only ever wanted to show *branch* names, so drop the SHA fallback entirely and return empty for anything that isn't on a branch. Also cap the rendered branch at 25 runes with an ellipsis so a long branch name can't push the rightmost status-bar items (clock) off screen. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
f464076 to
ef13531
Compare
| if t.welcome.active && time.Now().After(t.welcome.expiresAt) { | ||
| t.welcome.active = false | ||
| } | ||
| t.rotateTip() | ||
| t.pollBranch() | ||
| t.fireTimers() |
| branch string | ||
| branchPollAt time.Time | ||
|
|
||
|
|
| // Core reason for truncating: the clock (rightmost item) must stay | ||
| // visible even when the branch is long. | ||
| now := time.Now().Format("15:04") | ||
| if !containsStr(line, now) { | ||
| t.Errorf("clock %q should remain visible alongside long branch, got: %q", now, line) | ||
| } |
|
Superseded by #25, which was merged with the same branch detection plus the status bar cleanup. Thanks for the PR — the rebased-stacked version is what ultimately landed. |
Summary
Adds the current git branch to the right side of the TUI status bar (e.g.
git:main).Design notes
Why parse
.git/HEADdirectly instead of shelling out togit?The obvious alternative is
exec.Command("git", "branch", "--show-current"). We didn't go that route:gitsubprocess that often is wasteful on a hot path, and it'd pull ingitas a runtime dependency for what is, fundamentally, reading a small text file.os.WriteFilefixtures — nogit init, no temp repos, nogitbinary needed in CI. The test file covers worktree indirection (absolute + relativegitdir:), detached HEAD, non-branch refs, subdirs, malformed inputs, and missing HEAD with zero subprocess overhead.Behavior
.git/HEADon a 2s poll..gitas a file containinggitdir: <path>, relative paths resolved from the directory containing the.gitfile).projectRootso a config root inside a subdirectory still resolves the enclosing repo.Test plan
initech upfrom a normal repo showsgit:<branch>initech upfrom a git worktree shows the worktree's branchgit:<first-24-chars>…, clock still visible🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
git:<branch>.Tests