Skip to content

fix: guide users who run wt outside repositories - #10

Merged
AgileIndustrialComplex merged 3 commits into
essafrom
claude/wt-init-issue-f80739
Jul 19, 2026
Merged

AgileIndustrialComplex merged 3 commits into
essafrom
claude/wt-init-issue-f80739

Conversation

@AgileIndustrialComplex

Copy link
Copy Markdown
Owner

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|fish to 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

  • Detect Git’s locale-stabilized “not a repository” failure and expose it as a sentinel error.
  • Replace leaked internal Git output with guidance to install shell integration via wt init bash|zsh|fish and enter a repository.
  • Document the outside-repository behavior and add coverage for detection under a non-English locale.

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); run wt init bash|zsh|fish to install shell integration, then cd into a repository exit status: 1

$ LC_ALL=de_DE.UTF-8 wt
wt: not a git repository (or any of the parent directories); run `wt init bash|zsh|fish` to install shell integration, then cd into a repository
exit status: 1
Evidence: Bash shell-integration output
wt() {
  local arg
  for arg in "$@"; do
    case "$arg" in
      --path-only|--path-only=*|--version|--version=*|--help|-h)
        command wt "$@"
        return
        ;;
    esac
  done
  if [ "$1" = "init" ]; then
    command wt "$@"
    return
  fi
  local dest
  dest=$(command wt --path-only "$@") || return
  [ -n "$dest" ] && cd -- "$dest"
}
Evidence: Zsh shell-integration output
wt() {
  local arg
  for arg in "$@"; do
    case "$arg" in
      --path-only|--path-only=*|--version|--version=*|--help|-h)
        command wt "$@"
        return
        ;;
    esac
  done
  if [ "$1" = "init" ]; then
    command wt "$@"
    return
  fi
  local dest
  dest=$(command wt --path-only "$@") || return
  [ -n "$dest" ] && cd -- "$dest"
}
Evidence: Fish shell-integration output
function wt
    for arg in $argv
        switch $arg
            case --path-only '--path-only=*' --version '--version=*' --help -h
                command wt $argv
                return
        end
    end
    if test "$argv[1]" = init
        command wt $argv
        return
    end
    set -l dest (command wt --path-only $argv)
    test -n "$dest"; and cd $dest
end

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 internal git worktree list error again. Force a stable locale (for example LC_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.

  • Inspected git diff eec146cadcfb4988b9bd01c6400f160b3b0c9f1e..6da284d2342bc49daf1e919cd0542a78624ade3f
  • go test ./internal/gitdata -run '^TestRunGitUsesStableLocale$' -count=1
  • go test ./...
  • go build -o /var/folders/6y/60sv_t9162q36tw66s1fnynm0000gn/T/no-mistakes-evidence/01KXXC2KNE6M025971ZT4S7M83/wt ./cmd/wt
  • From the non-repository evidence directory, ran LC_ALL=de_DE.UTF-8 wt and asserted the exact stderr message and exit status 1
  • From the non-repository evidence directory, ran wt init bash, wt init zsh, and wt init fish; verified each produced non-empty shell integration containing wt --path-only
  • Ran git status --short after testing; no transient working-tree artifacts were created
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

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.
@AgileIndustrialComplex
AgileIndustrialComplex merged commit 4ecc34e into essa Jul 19, 2026
5 of 6 checks passed
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