Skip to content

feat(tui): display git branch in sidebar and landing page#2997

Open
processtrader wants to merge 1 commit into
charmbracelet:mainfrom
processtrader:display-git-branch
Open

feat(tui): display git branch in sidebar and landing page#2997
processtrader wants to merge 1 commit into
charmbracelet:mainfrom
processtrader:display-git-branch

Conversation

@processtrader

Copy link
Copy Markdown

Summary

  • Display the current git branch name in the sidebar (below working directory) and on the landing page
  • Live refresh via fsnotify watcher on .git/HEAD and refs/heads/ — branch updates instantly on git checkout, git switch, rebase, merge, etc.
  • Supports worktrees by resolving .git file to the actual git directory
  • Gracefully hides when not in a git repo or in detached HEAD state

Implementation details

  • Async tea.Cmd pattern — never blocks render
  • Cached in UI.gitBranch, only re-runs git branch --show-current when .git/HEAD or refs/heads/ changes on disk
  • New GitBranchIcon constant and Sidebar.GitBranch style following existing conventions
  • MaxHeight(1) prevents long branch names from wrapping in the narrow sidebar

Test plan

  • TestLoadGitBranch/returns_empty_for_non_git_dir — no crash, empty result, no watcher
  • TestLoadGitBranch/returns_branch_for_git_repo_and_starts_watcher — correct branch, watcher started
  • TestLoadGitBranch/returns_empty_for_detached_head — graceful fallback
  • TestLoadGitBranch/watchGitBranch_returns_nil_when_no_watcher — nil safety
  • Full model test suite passes
  • Manual: run go run . in a git repo, verify branch shows in sidebar
  • Manual: run git checkout -b test-branch in another terminal, verify sidebar updates live
  • Manual: verify no branch shown in a non-git directory

💘 Generated with Crush

@processtrader processtrader force-pushed the display-git-branch branch 3 times, most recently from 670a139 to ab9b06a Compare June 6, 2026 08:00
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