fix: bd sync fails in bare repo worktrees (#785)
The bug: In a bare repo + worktrees setup, jsonlRelPath was calculated relative to the project root (which contains all worktrees), resulting in paths like "main/.beads/issues.jsonl". But the sync branch worktree uses sparse checkout for .beads/*, so files are at ".beads/issues.jsonl". This caused copyJSONLToMainRepo to look in the wrong location, silently returning when the file was not found. Fix: Add normalizeBeadsRelPath() to strip leading path components before ".beads", ensuring correct path resolution in both directions: - copyJSONLToMainRepo (worktree -> local) - SyncJSONLToWorktreeWithOptions (local -> worktree) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -179,3 +179,56 @@ func runGitCmd(t *testing.T, dir string, args ...string) {
|
||||
t.Fatalf("git %v failed: %v\n%s", args, err, output)
|
||||
}
|
||||
}
|
||||
|
||||
// TestNormalizeBeadsRelPath tests path normalization for bare repo worktrees.
|
||||
// This is the regression test for GH#785.
|
||||
func TestNormalizeBeadsRelPath(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
input string
|
||||
expected string
|
||||
}{
|
||||
{
|
||||
name: "normal repo path unchanged",
|
||||
input: ".beads/issues.jsonl",
|
||||
expected: ".beads/issues.jsonl",
|
||||
},
|
||||
{
|
||||
name: "bare repo worktree strips leading component",
|
||||
input: "main/.beads/issues.jsonl",
|
||||
expected: ".beads/issues.jsonl",
|
||||
},
|
||||
{
|
||||
name: "bare repo worktree with deeper path",
|
||||
input: "worktrees/feature-branch/.beads/issues.jsonl",
|
||||
expected: ".beads/issues.jsonl",
|
||||
},
|
||||
{
|
||||
name: "metadata file also works",
|
||||
input: "main/.beads/metadata.json",
|
||||
expected: ".beads/metadata.json",
|
||||
},
|
||||
{
|
||||
name: "path with no .beads unchanged",
|
||||
input: "some/other/path.txt",
|
||||
expected: "some/other/path.txt",
|
||||
},
|
||||
{
|
||||
name: ".beads at start unchanged",
|
||||
input: ".beads/subdir/file.jsonl",
|
||||
expected: ".beads/subdir/file.jsonl",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
// Normalize to forward slashes for comparison
|
||||
result := normalizeBeadsRelPath(tt.input)
|
||||
// Convert expected to platform path for comparison
|
||||
expectedPlatform := filepath.FromSlash(tt.expected)
|
||||
if result != expectedPlatform {
|
||||
t.Errorf("normalizeBeadsRelPath(%q) = %q, want %q", tt.input, result, expectedPlatform)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user