Skip to content

fix: MainRepoRoot() and unify bare detection with git-dir/git-common-dir#4

Merged
usadamasa merged 4 commits into
mainfrom
support-list-in-bare
Feb 16, 2026
Merged

fix: MainRepoRoot() and unify bare detection with git-dir/git-common-dir#4
usadamasa merged 4 commits into
mainfrom
support-list-in-bare

Conversation

@usadamasa

Copy link
Copy Markdown
Owner

Summary

  • Unify bare/worktree detection using git rev-parse --git-dir --git-common-dir in a single process invocation, replacing the previous ListWorktrees + RepoRoot two-process approach
  • Fix MainRepoRoot() which incorrectly returned the parent directory for bare repos by always applying filepath.Dir()
  • Add gitDirs() helper and 7 new test cases covering all 4 repo states (normal main, normal worktree, bare root, bare worktree)

Test plan

  • TestGitDirs_NormalRepo — gitDir == gitCommonDir, Base == ".git"
  • TestGitDirs_NormalWorktree — gitDir != gitCommonDir, Base == ".git"
  • TestGitDirs_BareRepo — gitDir == gitCommonDir, Base != ".git"
  • TestGitDirs_WorktreeFromBare — gitDir != gitCommonDir, Base != ".git"
  • TestMainRepoRoot_BareRepo — returns bare repo directory itself
  • TestMainRepoRoot_WorktreeFromBare — returns bare repo directory from worktree
  • TestRepoName_BareRepo — returns correct name for bare repo
  • All existing TestDetectRepoContext_* tests pass unchanged
  • golangci-lint — 0 issues
  • gostyle — no project-level errors

Closes k1LoW#130 (Phase 1, Commit 2)

🤖 Generated with Claude Code

usadamasa and others added 2 commits February 15, 2026 13:37
Move ShowPrefix(), RepoRoot(), MainRepoRoot(), RepoName() and their
tests to repo_context.go / repo_context_test.go to consolidate
repository state logic in one file. No behavior change.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…e detection

Unify bare/worktree detection using git-dir + git-common-dir from a single
git rev-parse invocation, replacing the previous ListWorktrees + RepoRoot
approach that required two git processes.

Fix MainRepoRoot() which previously always applied filepath.Dir() to
git-common-dir, causing it to return the parent directory for bare repos
instead of the bare repo directory itself.

Closes k1LoW#130 (Phase 1, Commit 2)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions

This comment has been minimized.

Enable `git wt` (list) to work in bare repositories by:

- Removing the bare repository guard for the list operation
- Adding CurrentLocation() that uses IsBareRoot() to dispatch between
  MainRepoRoot() (bare root) and CurrentWorktree() (normal/worktree)
- Displaying "(bare)" in the BRANCH column for bare entries
- Marking bare entry with "*" when running from bare root

Fix bare detection for repos where git-common-dir ends with ".git"
(e.g., core.bare=true layout) by combining --is-bare-repository flag
with the filepath.Base heuristic using OR logic.

Also unexport RepoContext fields and add four state query functions:
IsNormalMain, IsNormalWorktree, IsBareRoot, IsBareWorktree.

Closes k1LoW#130 (Phase 1 Commit 3)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions

This comment has been minimized.

Cover all 5 scenarios: normal repo, normal worktree, bare root,
core.bare=true root, and bare worktree.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

Code Metrics Report

main (78c7a87) #4 (f549edd) +/-
Coverage 37.3% 35.9% -1.4%
Code to Test Ratio 1:2.0 1:2.1 +0.1
Test Execution Time 16s 15s -1s
Details
  |                     | main (78c7a87) | #4 (f549edd) |  +/-  |
  |---------------------|----------------|--------------|-------|
- | Coverage            |          37.3% |        35.9% | -1.4% |
  |   Files             |             13 |           13 |     0 |
  |   Lines             |            987 |         1039 |   +52 |
+ |   Covered           |            369 |          374 |    +5 |
+ | Code to Test Ratio  |          1:2.0 |        1:2.1 |  +0.1 |
  |   Code              |           2167 |         2260 |   +93 |
+ |   Test              |           4520 |         4941 |  +421 |
+ | Test Execution Time |            16s |          15s |   -1s |

Code coverage of files in pull request scope (28.7% → 27.4%)

Files Coverage +/- Status
cmd/root.go 0.0% 0.0% modified
internal/git/config.go 76.9% 0.0% modified
internal/git/repo_context.go 68.2% -17.9% modified
internal/git/worktree.go 54.5% +0.4% modified
testutil/repo.go 0.0% 0.0% modified

Reported by octocov

@usadamasa usadamasa merged commit 325aac1 into main Feb 16, 2026
3 checks passed
@usadamasa usadamasa deleted the support-list-in-bare branch February 16, 2026 00:42
@github-actions github-actions Bot mentioned this pull request Feb 16, 2026
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.

git-wt fails in bare repositories (exit status 128)

1 participant