fix(doctor): detect missing git repo and improve daemon startup message (#890)
When not in a git repository: - Daemon startup now shows clear message immediately instead of waiting 5 seconds: "Note: No git repository initialized — running without background sync" - Added new doctor check "Git Sync Setup" that explains the situation Doctor check now shows three states: 1. No git repo → Warning with fix: "Run 'git init' to enable background sync" 2. Git repo, no sync-branch → OK with hint about team collaboration benefits 3. Git repo + sync-branch → OK, fully configured 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -2,8 +2,11 @@ package doctor
|
||||
|
||||
import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/steveyegge/beads/internal/git"
|
||||
)
|
||||
|
||||
func TestCheckDaemonStatus(t *testing.T) {
|
||||
@@ -33,3 +36,71 @@ func TestCheckDaemonStatus(t *testing.T) {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestCheckGitSyncSetup(t *testing.T) {
|
||||
t.Run("not in git repository", func(t *testing.T) {
|
||||
tmpDir := t.TempDir()
|
||||
oldDir, err := os.Getwd()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer func() {
|
||||
_ = os.Chdir(oldDir)
|
||||
git.ResetCaches()
|
||||
}()
|
||||
|
||||
if err := os.Chdir(tmpDir); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
git.ResetCaches()
|
||||
|
||||
check := CheckGitSyncSetup(tmpDir)
|
||||
|
||||
if check.Status != StatusWarning {
|
||||
t.Errorf("Status = %q, want %q", check.Status, StatusWarning)
|
||||
}
|
||||
if check.Name != "Git Sync Setup" {
|
||||
t.Errorf("Name = %q, want %q", check.Name, "Git Sync Setup")
|
||||
}
|
||||
if check.Fix == "" {
|
||||
t.Error("Expected Fix to contain instructions")
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("in git repository without sync-branch", func(t *testing.T) {
|
||||
tmpDir := t.TempDir()
|
||||
oldDir, err := os.Getwd()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer func() {
|
||||
_ = os.Chdir(oldDir)
|
||||
git.ResetCaches()
|
||||
}()
|
||||
|
||||
// Initialize git repo
|
||||
cmd := exec.Command("git", "init")
|
||||
cmd.Dir = tmpDir
|
||||
if err := cmd.Run(); err != nil {
|
||||
t.Fatalf("Failed to init git repo: %v", err)
|
||||
}
|
||||
|
||||
if err := os.Chdir(tmpDir); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
git.ResetCaches()
|
||||
|
||||
check := CheckGitSyncSetup(tmpDir)
|
||||
|
||||
if check.Status != StatusOK {
|
||||
t.Errorf("Status = %q, want %q", check.Status, StatusOK)
|
||||
}
|
||||
if check.Name != "Git Sync Setup" {
|
||||
t.Errorf("Name = %q, want %q", check.Name, "Git Sync Setup")
|
||||
}
|
||||
// Should mention sync-branch not configured
|
||||
if check.Detail == "" {
|
||||
t.Error("Expected Detail to contain sync-branch hint")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user