-
Notifications
You must be signed in to change notification settings - Fork 186
Open
Description
Bug Description
GetWorktreeID in cmd/entire/cli/paths/worktree.go fails when the git repository uses the bare repo + worktree layout pattern (.bare directory instead of .git directory).
Error
failed to save changes: failed to initialize session: failed to get worktree ID: unexpected
gitdir format (no worktrees): /Users/user/repos/project/.bare/worktrees/main
Root Cause
The function hardcodes .git/worktrees/ as the only valid path marker:
const marker = ".git/worktrees/"
_, worktreeID, found := strings.Cut(gitdir, marker)
if !found {
return "", fmt.Errorf("unexpected gitdir format (no worktrees): %s", gitdir)
}The widely-used "bare worktree" pattern structures repos as:
project/
.git → file containing: "gitdir: ./.bare"
.bare/ → actual bare git repository
worktrees/
main/
gitdir → /path/to/project/main/.git
main/ → worktree checkout
.git → file containing: "gitdir: /path/to/.bare/worktrees/main"
The gitdir path is .bare/worktrees/main — no .git/worktrees/ substring exists, so strings.Cut fails.
Suggested Fix
const standardMarker = ".git/worktrees/"
_, worktreeID, found := strings.Cut(gitdir, standardMarker)
if !found {
const bareMarker = ".bare/worktrees/"
_, worktreeID, found = strings.Cut(gitdir, bareMarker)
}
if !found {
return "", fmt.Errorf("unexpected gitdir format (no worktrees): %s", gitdir)
}Or more robustly, just split on /worktrees/ and take the last component.
Environment
- entire CLI v0.4.5
- macOS (Darwin 25.2.0)
- Git worktree layout created via
git clone --bare+git worktree add
Related
Possibly related to #354 (also a worktree issue).
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels