Summary
All git-wt operations (list, add/switch, delete) fail inside bare repositories.
PR #136 introduced RepoContext detection and clear error messages.
This issue tracks incremental bare repository support, one operation at a time.
Progress
Root Causes
| # |
Cause |
Affected ops |
Status |
| 1 |
CurrentWorktree()/RepoRoot() fail in bare root (--show-toplevel exit 128) |
list, delete |
Open |
| 2 |
MainRepoRoot() returns parent directory for bare repos |
add, delete |
Open |
| 3 |
MainRepoRoot() returns wrong path from worktrees linked to bare repos |
add, delete |
Open |
| 4 |
CopyFilesToWorktree() fails in bare repos (git ls-files requires working tree) |
add |
Open |
| 5 |
ListWorktrees() returns empty Branch/Head for bare entries |
list |
Open |
| 6 |
FindWorktreeByBranchOrDir() matches bare entries |
add, delete |
Open |
| 7 |
Bare entries not labeled in list display |
list |
Open |
Implementation Plan
Phase 1: Foundation + list (single PR, separate commits)
Commit 1 — Refactoring: Move ShowPrefix(), RepoRoot(), MainRepoRoot(), RepoName() from config.go to repo_context.go (same package, no behavior change)
Commit 2 — Fix MainRepoRoot() + unify bare detection (root causes #2, #3):
- Use
git-common-dir with filepath.Base == ".git" check as the single bare detection method
DetectRepoContext() also uses this method instead of ListWorktrees porcelain output (ListWorktrees is only used for non-bare worktree path comparison)
Commit 3 — list support (root causes #1, #5, #7): Make CurrentWorktree() error non-fatal in listWorktrees(), show (bare) for bare entries, remove list guard
Phase 2: add/switch support (root causes #4, #6)
Skip CopyFilesToWorktree() for bare repos, skip bare entries in FindWorktreeByBranchOrDir()
Phase 3: delete support (root cause #1 remainder)
Add bare entry deletion guard, remove delete guard
Reproduction
git clone --bare https://github.com/k1LoW/git-wt.git /tmp/bare-test
cd /tmp/bare-test
git-wt # Error: bare repositories are not currently supported
Original issue body
git-wt fails with Error: failed to get current worktree: exit status 128 when run inside a bare repository (git clone --bare).
Bare repositories are a common use case for git worktree, but git-wt cannot function at all in this context. Listing, creating, and deleting worktrees all fail immediately.
For the original detailed root cause analysis, see the git history of this issue.
Summary
All git-wt operations (list, add/switch, delete) fail inside bare repositories.
PR #136 introduced
RepoContextdetection and clear error messages.This issue tracks incremental bare repository support, one operation at a time.
Progress
MainRepoRoot()for bare repos + unify bare detectionRoot Causes
CurrentWorktree()/RepoRoot()fail in bare root (--show-toplevelexit 128)MainRepoRoot()returns parent directory for bare reposMainRepoRoot()returns wrong path from worktrees linked to bare reposCopyFilesToWorktree()fails in bare repos (git ls-filesrequires working tree)ListWorktrees()returns empty Branch/Head for bare entriesFindWorktreeByBranchOrDir()matches bare entriesImplementation Plan
Phase 1: Foundation + list (single PR, separate commits)
Commit 1 — Refactoring: Move
ShowPrefix(),RepoRoot(),MainRepoRoot(),RepoName()fromconfig.gotorepo_context.go(same package, no behavior change)Commit 2 — Fix
MainRepoRoot()+ unify bare detection (root causes #2, #3):git-common-dirwithfilepath.Base == ".git"check as the single bare detection methodDetectRepoContext()also uses this method instead ofListWorktreesporcelain output (ListWorktrees is only used for non-bare worktree path comparison)Commit 3 — list support (root causes #1, #5, #7): Make
CurrentWorktree()error non-fatal inlistWorktrees(), show(bare)for bare entries, remove list guardPhase 2: add/switch support (root causes #4, #6)
Skip
CopyFilesToWorktree()for bare repos, skip bare entries inFindWorktreeByBranchOrDir()Phase 3: delete support (root cause #1 remainder)
Add bare entry deletion guard, remove delete guard
Reproduction
Original issue body
git-wtfails withError: failed to get current worktree: exit status 128when run inside a bare repository (git clone --bare).Bare repositories are a common use case for
git worktree, but git-wt cannot function at all in this context. Listing, creating, and deleting worktrees all fail immediately.For the original detailed root cause analysis, see the git history of this issue.