Match git fsck error lines by prefix in --check · Entire

Match git fsck error lines by prefix in --check

1c8caf7→main·

nodo·1mo ago·1 file·+22 added/-1 removed

Substring-matching "error" against the full fsck output could false-positive on benign dangling/warning lines that happened to contain that word (e.g. a branch or path with "error" in it). Scan line-by-line for "error:" / "fatal:" / "missing " / "broken link" / "bad " prefixes, which is what git itself uses to signal real problems.

Sessions

Transcript data is unavailable for this checkpoint.

Changes

1

557 unmodified lines

560
561
562
563
564
565
566
567
568
569
570
1 unmodified line

573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592

557 unmodified lines

switch {
    case err != nil:
        checks = append(checks, Check{Name: "git fsck --full", OK: false, Detail: fmt.Sprintf("%v\n%s", err, fsckOut)})
    case bytes.Contains(fsckOut, []byte("error")) || bytes.Contains(fsckOut, []byte("bad sha")):
    case fsckHasError(fsckOut):
        // Belt-and-braces against a hypothetical git version that prints
        // "error:" / "fatal:" lines but exits zero. Match line prefixes
        // rather than a substring so a branch or path containing "error"
        // in a benign dangling/warning line doesn't trip the check.
        checks = append(checks, Check{Name: "git fsck --full", OK: false, Detail: strings.TrimSpace(string(fsckOut))})
    default:
        checks = append(checks, Check{Name: "git fsck --full", OK: true, Detail: "clean"})
    1 unmodified line

return checks
}

// fsckHasError reports whether git-fsck output contains a line that signals
// a real problem (an "error:" or "fatal:" prefix, or a "missing"/"bad"
// object report). Dangling and warning lines are ignored.
func fsckHasError(out []byte) bool {
    scanner := bufio.NewScanner(bytes.NewReader(out))
    for scanner.Scan() {
        line := strings.TrimSpace(scanner.Text())
        if strings.HasPrefix(line, "error:") || strings.HasPrefix(line, "fatal:") {
            return true
        }
        if strings.HasPrefix(line, "missing ") || strings.HasPrefix(line, "broken link") || strings.HasPrefix(line, "bad ") {
            return true
        }
    }
    return false
}

const (
    originNotesRef       = "refs/notes/sha1-origin"
    attestationTagPrefix = "refs/tags/converted/"