Skip to content

Comments

feat: support list command in bare repositories#140

Merged
k1LoW merged 4 commits intok1LoW:mainfrom
usadamasa:support-list-in-bare
Feb 15, 2026
Merged

feat: support list command in bare repositories#140
k1LoW merged 4 commits intok1LoW:mainfrom
usadamasa:support-list-in-bare

Conversation

@usadamasa
Copy link
Contributor

@usadamasa usadamasa commented Feb 15, 2026

Summary

#130 (Phase 1: list operation)

  • Enable git wt (list mode) in bare repositories and worktrees created from bare repos
  • Refactor RepoContext to unexported fields with 4-state query functions (IsBareRoot, IsBareWorktree, IsNormalMain, IsNormalWorktree)
  • Fix MainRepoRoot() to return the correct path for bare repos where git-common-dir ends with .git (e.g., core.bare=true layout)
    • This is the main point of this PR.
  • Unify bare detection: combine --is-bare-repository flag with filepath.Base(gitCommonDir) != ".git" heuristic to cover both repo.git and core.bare=true layouts

Display behavior

Table output (git wt)

When running from bare root:

  PATH              BRANCH       HEAD
* /tmp/repo.git     (bare)
  /tmp/wt/main      main         abc1234

When running from a worktree created from a bare repo:

  PATH              BRANCH       HEAD
  /tmp/repo.git     (bare)
* /tmp/wt/main      main         abc1234
  • The bare entry shows (bare) in the BRANCH column (following git's convention)
  • HEAD column is empty for the bare entry
  • * marker indicates the current location

JSON output (git wt --json)

[
  {
    "path": "/tmp/repo.git",
    "branch": "",
    "head": "",
    "bare": true,
    "current": true
  },
  {
    "path": "/tmp/wt/main",
    "branch": "main",
    "head": "abc1234",
    "bare": false,
    "current": false
  }
]
  • JSON consumers should use the bare field (not branch) to identify bare entries

Operations NOT yet supported in bare repos

  • git wt <branch> (add/switch) — returns error mentioning "bare"
  • git wt -d <branch> (delete) — returns error mentioning "bare"

These will be addressed in subsequent phases.

Test plan

  • Unit tests for DetectRepoContext covering all 4 states + core.bare=true edge case
  • Unit tests for CurrentLocation covering all 5 scenarios (normal repo, normal worktree, bare root, core.bare=true root, bare worktree)
  • E2E tests for list in bare root, bare worktree, and core.bare=true layout
  • E2E tests for JSON output with bare field validation
  • E2E tests for * current marker in both bare root and worktree contexts
  • E2E tests confirming add/delete still return errors for bare repos

🤖 Generated with Claude Code

usadamasa and others added 4 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 <[email protected]>
…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 <[email protected]>
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 <[email protected]>
Cover all 5 scenarios: normal repo, normal worktree, bare root,
core.bare=true root, and bare worktree.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@usadamasa usadamasa marked this pull request as ready for review February 15, 2026 06:40
@k1LoW k1LoW added the enhancement New feature or request label Feb 15, 2026
Copy link
Owner

@k1LoW k1LoW left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

L Great TM 🚀

@k1LoW k1LoW merged commit 325aac1 into k1LoW:main Feb 15, 2026
3 checks passed
@github-actions github-actions bot mentioned this pull request Feb 15, 2026
@usadamasa usadamasa deleted the support-list-in-bare branch February 16, 2026 00:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants