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

Method runGitSplit

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

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

Callers 3

GetDiffMethod · 0.95
workspaceTrackedDiffMethod · 0.95
untrackedFilesListMethod · 0.95

Calls 4

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

Tested by

no test coverage detected