fix: clear error when adding worktree on unborn repo - #45
Merged
Conversation
`git worktree add -b <branch> <path> main` aborts with `fatal: invalid reference: main` when the repo has no commits yet, leaving the user with the cryptic raw-git error and no path forward beyond Cancel. Detect the unborn HEAD up front and bail with an actionable message instead. Closes #44 Co-Authored-By: Claude <noreply@anthropic.com>
The error row was a single, unwrapped `Paragraph`, so the unborn-HEAD
message added in the previous commit (and any future error longer than
the modal's inner width) spilled past the right border. Allocate two
rows for the error, render with `Wrap { trim: false }`, and shorten the
unborn-HEAD message so it fits on one line in the common case.
Adds a snapshot test that renders an intentionally over-wide error to
lock the wrapped layout in. Documents the verification step in agents.md
so future TUI changes don't reintroduce the overflow.
Co-Authored-By: Claude <noreply@anthropic.com>
libgit2's `is_empty` / `head` returned `false` on Linux CI for repos that had just been `git init`'d with no commits, so the unit test asserting `is_unborn_head` is `true` for a freshly-initialised repo failed there. macOS libgit2 reported them correctly. Shelling out to `git rev-parse --verify HEAD` sidesteps the platform difference and matches how the rest of git.rs talks to git. Co-Authored-By: Claude <noreply@anthropic.com>
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
git init'd repo with no commits) before invokinggit worktree add, and bails with"repo has no commits yet — make an initial commit before adding worktrees"instead of letting git fail withfatal: invalid reference: main.git::is_unborn_headhelper plus three unit tests covering: unborn repo, repo after first commit, non-repo path.Why
Reported in #44: on a brand-new project (
mkdir x && cd x && git init . && grove .), pressingwto create a worktree fails with a cryptic! git worktree add -b ...error and the only option is Cancel.Root cause:
detect_default_branchreturnsNonewhen there's noorigin/HEAD, sobase_branchfalls back to the configured default ("main"). On an unborn repo,mainhas no commit, sogit worktree add -b <branch> <path> mainaborts withfatal: invalid reference: main. The fix surfaces this as an actionable in-modal error so the user knows what to do (make the first commit) rather than staring at raw git output.Closes #44
Test plan
cargo test --bin grove— 144 tests passcargo fmt --check,cargo clippy --all-targets -- -D warningscleanmkdir /tmp/grove-test && cd /tmp/grove-test && git init . && grove ., pressw, type a branch name, hit Enter — confirm the new error message appears in the modal🤖 Generated with Claude Code