doctor: simplify mirror check after review · Entire

doctor: simplify mirror check after review

ed38787→main·

computermode·1mo ago·5 files·+70 added/-56 removed

Co-Authored-By: Claude Opus 4.8 (1M context) noreply@anthropic.com

Sessions

dbe157735b54View transcript

Changes

5

368 unmodified lines

... (stack traces and output summaries)

confirmDoctorFix

confirmDoctorFix asks a yes/no fix confirmation shared by doctor checks. Returns false with no error when the user declines (prints "-> Skipped") or aborts the prompt.

func confirmDoctorFix(w io.Writer, title string) (bool, error) {
    var confirmed bool
    form := NewAccessibleForm(
        huh.NewGroup(
            huh.NewConfirm().
                Title(title).
                Value(&confirmed),
        ),
    )
    if err := form.Run(); err != nil {
        if errors.Is(err, huh.ErrUserAborted) {
            return false, nil
        }
        return false, fmt.Errorf("prompt failed: %w", err)
    }
    if !confirmed {
        fmt.Fprintln(w, "  -> Skipped")
    }
    return confirmed, nil
}

// shortMirrorHash abbreviates a hash for mirror-check output; "none" when zero. func shortMirrorHash(h plumbing.Hash) string { if h.IsZero() { return "none" } return h.String()[:8] }

Status Constants

const ( MirrorNotConfigured MirrorStatus = iota // topology has no mirror (v1 mode) MirrorOK // mirror == primary tip MirrorNoMetadata // neither primary nor mirror exists yet (fresh repo) MirrorMissing // primary exists, mirror ref absent MirrorBehind // mirror is an ancestor of the primary tip MirrorDiverged // mirror is not an ancestor of the primary tip MirrorPrimaryMissing // primary metadata ref absent )

// String returns the status name used in doctor and bundle output.
func (s MirrorStatus) String() string {
    switch s {
    case MirrorNotConfigured:
        return "NOT CONFIGURED"
    case MirrorOK:
        return "OK"
    case MirrorNoMetadata:
        return "NO METADATA"
    case MirrorMissing:
        return "MISSING"
    case MirrorBehind:
        return "BEHIND"
    case MirrorDiverged:
        return "DIVERGED"
    case MirrorPrimaryMissing:
        return "V1 MISSING"
    default:
        return fmt.Sprintf("UNKNOWN(%d)", int(s))
    }
}