fix: Windows infinite loop in findLocalBeadsDir and findOriginalBeadsDir (GH#996)

Same fix as PR #991 for FindBeadsDir() - the loop condition
dir != "/" && dir != "." doesn't handle Windows drive roots.
On Windows, filepath.Dir("C:\\") returns "C:\\", not "/" or ".".

Changed both functions to check parent == dir to detect filesystem root,
which works correctly on both Unix and Windows.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
giles
2026-01-10 13:34:53 -08:00
committed by Steve Yegge
parent bfae0e554c
commit b844a3b656
2 changed files with 23 additions and 2 deletions

View File

@@ -118,7 +118,7 @@ func findOriginalBeadsDir() string {
}
// Walk up directory tree looking for .beads with redirect
for dir := cwd; dir != "/" && dir != "."; dir = filepath.Dir(dir) {
for dir := cwd; dir != "/" && dir != "."; {
beadsDir := filepath.Join(dir, ".beads")
if info, err := os.Stat(beadsDir); err == nil && info.IsDir() {
redirectFile := filepath.Join(beadsDir, beads.RedirectFileName)
@@ -128,6 +128,16 @@ func findOriginalBeadsDir() string {
// Found .beads without redirect - this is the actual location
return ""
}
// Move up one directory
parent := filepath.Dir(dir)
if parent == dir {
// Reached filesystem root (works on both Unix and Windows)
// On Unix: filepath.Dir("/") returns "/"
// On Windows: filepath.Dir("C:\\") returns "C:\\"
break
}
dir = parent
}
return ""

View File

@@ -144,6 +144,7 @@ func findLocalBeadsDir() string {
}
// Check for worktree - use main repo's .beads
// Note: GetMainRepoRoot() is safe to call outside a git repo - it returns an error
mainRepoRoot, err := git.GetMainRepoRoot()
if err == nil && mainRepoRoot != "" {
beadsDir := filepath.Join(mainRepoRoot, ".beads")
@@ -158,11 +159,21 @@ func findLocalBeadsDir() string {
return ""
}
for dir := cwd; dir != "/" && dir != "."; dir = filepath.Dir(dir) {
for dir := cwd; dir != "/" && dir != "."; {
beadsDir := filepath.Join(dir, ".beads")
if info, err := os.Stat(beadsDir); err == nil && info.IsDir() {
return beadsDir
}
// Move up one directory
parent := filepath.Dir(dir)
if parent == dir {
// Reached filesystem root (works on both Unix and Windows)
// On Unix: filepath.Dir("/") returns "/"
// On Windows: filepath.Dir("C:\\") returns "C:\\"
break
}
dir = parent
}
return ""