Repository navigation
fix: guide users who run wt outside repositories - #10
Merged
Merged
Conversation
Previously, running wt outside a git repository leaked git's raw "fatal: not a git repository" stderr through an unrelated internal command (`git worktree list --porcelain -z: ...`). Now runGit detects that failure and returns a sentinel ErrNotAGitRepo, which main.go turns into a clean message that also points the user at `wt init bash|zsh|fish` for shell integration setup.
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.
Intent
Fix wt's error output when run outside a git repository. Previously running the bare wt command (no args) outside of any git repo let git's raw internal stderr leak through unchanged: 'wt: git worktree list --porcelain -z: fatal: not a git repository (or any of the parent directories): .git'. That's confusing because it exposes an internal git subcommand the user never invoked, and it gives no hint that wt provides a setup path via 'wt init bash|zsh|fish' for shell integration. The user's specific complaint was that this situation should surface/point to the init command rather than just leak an error. Fix: internal/gitdata/gitdata.go's runGit now detects git's 'not a git repository' failure message and returns a sentinel ErrNotAGitRepo instead of the raw wrapped git error; cmd/wt/main.go's run() checks for that sentinel via errors.Is and returns a clean message: 'not a git repository (or any of the parent directories); run
wt init bash|zsh|fishto install shell integration, then cd into a repository'. wt init itself (the os.Args[1]=="init" branch in main.go) was already correct and unaffected - it runs before any git calls regardless of repo status. Verified: go build ./... and go test ./... pass, and manually exercised both the not-a-repo case and 'wt init bash'/'wt init fish' output.What Changed
wt init bash|zsh|fishand enter a repository.Risk Assessment
✅ Low: The change is narrowly scoped, satisfies the required error behavior, and now stabilizes Git’s locale so sentinel detection is reliable across localized environments.
Testing
Diff inspection, the focused locale regression, full Go test suite, production build, and end-to-end execution from a real non-repository directory all succeeded; captured evidence shows the exact guided error and confirms bash, zsh, and fish initialization still works, with the worktree left clean.
Evidence: Outside-repository CLI transcript
$ LC_ALL=de_DE.UTF-8 wt wt: not a git repository (or any of the parent directories); runwt init bash|zsh|fishto install shell integration, then cd into a repository exit status: 1Evidence: Bash shell-integration output
Evidence: Zsh shell-integration output
Evidence: Fish shell-integration output
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
🔧 **Review** - 1 issue found → auto-fixed ✅
internal/gitdata/gitdata.go:72- Detection depends on Git’s English stderr text. Git localizes fatal messages, so under a non-English locale this check can miss the condition and leak the internalgit worktree listerror again. Force a stable locale (for exampleLC_ALL=C) for the subprocess or classify the failure without matching localized text.🔧 Fix: Stabilize Git locale for repository error detection
✅ Re-checked - no issues remain.
✅ **Test** - passed
✅ No issues found.
Inspectedgit diff eec146cadcfb4988b9bd01c6400f160b3b0c9f1e..6da284d2342bc49daf1e919cd0542a78624ade3fgo test ./internal/gitdata -run '^TestRunGitUsesStableLocale$' -count=1go test ./...go build -o /var/folders/6y/60sv_t9162q36tw66s1fnynm0000gn/T/no-mistakes-evidence/01KXXC2KNE6M025971ZT4S7M83/wt ./cmd/wtFrom the non-repository evidence directory, ranLC_ALL=de_DE.UTF-8 wtand asserted the exact stderr message and exit status 1From the non-repository evidence directory, ranwt init bash,wt init zsh, andwt init fish; verified each produced non-empty shell integration containingwt --path-onlyRangit status --shortafter testing; no transient working-tree artifacts were created✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.