* Fix #274: Add automatic .beads/.gitignore upgrade Implements three mechanisms to ensure users get updated gitignore: 1. bd doctor --fix: Manually upgrade gitignore 2. Daemon auto-upgrade: Upgrades on startup if outdated 3. bd init idempotent: Safe to re-run, always updates gitignore The gitignore template now lives in cmd/bd/doctor/gitignore.go for consistent updates across all three mechanisms. Fixes: #274 * Remove test binary Amp-Thread-ID: https://ampcode.com/threads/T-7042cfcc-ac97-43d7-a40f-3fa1bb4e1c2b Co-authored-by: Amp <amp@ampcode.com> * Fix critical issues: remove merge artifact and apply gitignore template - Remove .beads/beads.left.jsonl (merge artifact that shouldn't be committed) - Apply new gitignore template to .beads/.gitignore (was missing patterns) Amp-Thread-ID: https://ampcode.com/threads/T-7042cfcc-ac97-43d7-a40f-3fa1bb4e1c2b Co-authored-by: Amp <amp@ampcode.com> * bd sync: 2025-11-12 11:09:30 * Retrigger CI Amp-Thread-ID: https://ampcode.com/threads/T-8d532264-6d5e-4b68-88e9-e4511851b64a Co-authored-by: Amp <amp@ampcode.com> * Fix duplicate DoctorCheck type definition * Trigger CI after fixing type conflict Amp-Thread-ID: https://ampcode.com/threads/T-8d532264-6d5e-4b68-88e9-e4511851b64a Co-authored-by: Amp <amp@ampcode.com> --------- Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
@@ -44,6 +44,10 @@ type doctorResult struct {
|
||||
CLIVersion string `json:"cli_version"`
|
||||
}
|
||||
|
||||
var (
|
||||
doctorFix bool
|
||||
)
|
||||
|
||||
var doctorCmd = &cobra.Command{
|
||||
Use: "doctor [path]",
|
||||
Short: "Check beads installation health",
|
||||
@@ -62,11 +66,13 @@ This command checks:
|
||||
- File permissions
|
||||
- Circular dependencies
|
||||
- Git hooks (pre-commit, post-merge, pre-push)
|
||||
- .beads/.gitignore up to date
|
||||
|
||||
Examples:
|
||||
bd doctor # Check current directory
|
||||
bd doctor /path/to/repo # Check specific repository
|
||||
bd doctor --json # Machine-readable output`,
|
||||
bd doctor --json # Machine-readable output
|
||||
bd doctor --fix # Automatically fix issues`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
// Use global jsonOutput set by PersistentPreRun
|
||||
|
||||
@@ -86,6 +92,13 @@ Examples:
|
||||
// Run diagnostics
|
||||
result := runDiagnostics(absPath)
|
||||
|
||||
// Apply fixes if requested
|
||||
if doctorFix {
|
||||
applyFixes(result)
|
||||
// Re-run diagnostics to show results
|
||||
result = runDiagnostics(absPath)
|
||||
}
|
||||
|
||||
// Output results
|
||||
if jsonOutput {
|
||||
outputJSON(result)
|
||||
@@ -100,7 +113,27 @@ Examples:
|
||||
},
|
||||
}
|
||||
|
||||
func runDiagnostics(path string) doctorResult {
|
||||
func init() {
|
||||
doctorCmd.Flags().BoolVar(&doctorFix, "fix", false, "Automatically fix issues where possible")
|
||||
}
|
||||
|
||||
func applyFixes(result doctorResult) {
|
||||
for _, check := range result.Checks {
|
||||
if check.Status == statusWarning || check.Status == statusError {
|
||||
switch check.Name {
|
||||
case "Gitignore":
|
||||
fmt.Println("Fixing .beads/.gitignore...")
|
||||
if err := doctor.FixGitignore(); err != nil {
|
||||
fmt.Fprintf(os.Stderr, " Error: %v\n", err)
|
||||
} else {
|
||||
fmt.Println(" ✓ Updated .beads/.gitignore")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func runDiagnostics(path string) doctorResult{
|
||||
result := doctorResult{
|
||||
Path: path,
|
||||
CLIVersion: Version,
|
||||
@@ -202,6 +235,11 @@ func runDiagnostics(path string) doctorResult {
|
||||
result.Checks = append(result.Checks, legacyDocsCheck)
|
||||
// Don't fail overall check for legacy docs, just warn
|
||||
|
||||
// Check 13: Gitignore up to date
|
||||
gitignoreCheck := convertDoctorCheck(doctor.CheckGitignore())
|
||||
result.Checks = append(result.Checks, gitignoreCheck)
|
||||
// Don't fail overall check for gitignore, just warn
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user