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

Method runGitSplit

internal/diff/git.go:668–689  ·  view source on GitHub ↗

runGitSplit runs git with stdout and stderr kept apart, for the callers that quote the failure back to the user. runGit's combined output cannot be quoted safely. Git writes the diff to stdout and its diagnosis to stderr, so a command killed mid-write leaves a tail made entirely of diff content — r

(ctx context.Context, args ...string)

Source from the content-addressed store, hash-verified

666// included: a killed process reports the signal rather than the reason, and
667// the reason is what the caller needs.
668func (p *Provider) runGitSplit(ctx context.Context, args ...string) (string, string, error) {
669 if p.runner != nil {
670 stdout, stderr, err := p.runner.RunSplit(ctx, p.repoDir, args...)
671 if ctx.Err() != nil && err != nil {
672 return "", "", ctx.Err()
673 }
674 return stdout, stderr, err
675 }
676
677 cmd := exec.CommandContext(ctx, "git", args...)
678 cmd.Dir = p.repoDir
679
680 var stdout, stderr bytes.Buffer
681 cmd.Stdout = &stdout
682 cmd.Stderr = &stderr
683
684 err := cmd.Run()
685 if ctx.Err() != nil && err != nil && cmd.ProcessState != nil && cmd.ProcessState.ExitCode() == -1 {
686 return "", "", ctx.Err()
687 }
688 return stdout.String(), stderr.String(), err
689}
690
691// gitDiagLimit bounds how much of git's stderr is quoted back in an error.
692// Git's own diagnosis is a line or two, so the ceiling is a backstop for the

Callers 2

GetDiffMethod · 0.95
workspaceTrackedDiffMethod · 0.95

Calls 4

RunSplitMethod · 0.80
ErrMethod · 0.80
RunMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected