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

Method runGitSplit

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

764// included: a killed process reports the signal rather than the reason, and
765// the reason is what the caller needs.
766func (p *Provider) runGitSplit(ctx context.Context, args ...string) (string, string, error) {
767 if p.runner != nil {
768 stdout, stderr, err := p.runner.RunSplit(ctx, p.repoDir, args...)
769 if ctx.Err() != nil && err != nil {
770 return "", "", ctx.Err()
771 }
772 return stdout, stderr, err
773 }
774
775 cmd := exec.CommandContext(ctx, "git", args...)
776 cmd.Dir = p.repoDir
777
778 var stdout, stderr bytes.Buffer
779 cmd.Stdout = &stdout
780 cmd.Stderr = &stderr
781
782 err := cmd.Run()
783 if ctx.Err() != nil && err != nil && cmd.ProcessState != nil && cmd.ProcessState.ExitCode() == -1 {
784 return "", "", ctx.Err()
785 }
786 return stdout.String(), stderr.String(), err
787}
788
789// gitDiagLimit bounds how much of git's stderr is quoted back in an error.
790// 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