feat: support list command in bare repositories#140
Merged
k1LoW merged 4 commits intok1LoW:mainfrom Feb 15, 2026
Merged
Conversation
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]>
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.
Summary
#130 (Phase 1: list operation)
git wt(list mode) in bare repositories and worktrees created from bare reposRepoContextto unexported fields with 4-state query functions (IsBareRoot,IsBareWorktree,IsNormalMain,IsNormalWorktree)MainRepoRoot()to return the correct path for bare repos wheregit-common-dirends with.git(e.g.,core.bare=truelayout)--is-bare-repositoryflag withfilepath.Base(gitCommonDir) != ".git"heuristic to cover bothrepo.gitandcore.bare=truelayoutsDisplay behavior
Table output (
git wt)When running from bare root:
When running from a worktree created from a bare repo:
(bare)in the BRANCH column (following git's convention)*marker indicates the current locationJSON 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 } ]barefield (not branch) to identify bare entriesOperations 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
DetectRepoContextcovering all 4 states +core.bare=trueedge caseCurrentLocationcovering all 5 scenarios (normal repo, normal worktree, bare root, core.bare=true root, bare worktree)core.bare=truelayout*current marker in both bare root and worktree contexts🤖 Generated with Claude Code