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

Method runGitSplit

internal/diff/git.go:760–781  ·  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

758// included: a killed process reports the signal rather than the reason, and
759// the reason is what the caller needs.
760func (p *Provider) runGitSplit(ctx context.Context, args ...string) (string, string, error) {
761 if p.runner != nil {
762 stdout, stderr, err := p.runner.RunSplit(ctx, p.repoDir, args...)
763 if ctx.Err() != nil && err != nil {
764 return "", "", ctx.Err()
765 }
766 return stdout, stderr, err
767 }
768
769 cmd := exec.CommandContext(ctx, "git", args...)
770 cmd.Dir = p.repoDir
771
772 var stdout, stderr bytes.Buffer
773 cmd.Stdout = &stdout
774 cmd.Stderr = &stderr
775
776 err := cmd.Run()
777 if ctx.Err() != nil && err != nil && cmd.ProcessState != nil && cmd.ProcessState.ExitCode() == -1 {
778 return "", "", ctx.Err()
779 }
780 return stdout.String(), stderr.String(), err
781}
782
783// gitDiagLimit bounds how much of git's stderr is quoted back in an error.
784// Git's own diagnosis is a line or two, so the ceiling is a backstop for the

Callers 4

GetDiffSetMethod · 0.95
workspaceTrackedDiffMethod · 0.95
untrackedFilesListMethod · 0.95

Calls 4

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

Tested by

no test coverage detected