MCPcopy Create free account
hub / github.com/alibaba/open-code-review / gitFailure

Function gitFailure

internal/diff/git.go:709–728  ·  view source on GitHub ↗

gitFailure builds an error that carries git's own message. Every diff-producing caller used to drop git's output on the floor, so a failure surfaced as a bare "git show failed: exit status 129" — true, and useless. Diagnosing one then meant asking the reporter to re-run the command by hand to see w

(op, stderr string, err error)

Source from the content-addressed store, hash-verified

707//
708// Callers pass stderr, never runGit's combined output; see runGitSplit for why.
709func gitFailure(op, stderr string, err error) error {
710 diag := strings.TrimSpace(stderr)
711 if diag == "" {
712 return fmt.Errorf("%s failed: %w", op, err)
713 }
714 if len(diag) > gitDiagLimit {
715 // Keep the tail: die() exits the process, so the fatal git ends on is
716 // the last thing it writes, behind any warnings that preceded it.
717 diag = diag[len(diag)-gitDiagLimit:]
718 // Cutting by bytes can land mid-rune. Git speaks the user's locale,
719 // so this is not hypothetical — #972 came from a Japanese-language
720 // Windows install. Drop the partial leading rune rather than emit
721 // invalid UTF-8.
722 for len(diag) > 0 && !utf8.RuneStart(diag[0]) {
723 diag = diag[1:]
724 }
725 diag = "..." + diag
726 }
727 return fmt.Errorf("%s failed: %w: %s", op, err, diag)
728}

Callers 3

GetDiffMethod · 0.85
untrackedFilesListMethod · 0.85
TestGitFailureFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestGitFailureFunction · 0.68