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

Method workspaceTrackedDiff

internal/diff/git.go:568–582  ·  view source on GitHub ↗

workspaceTrackedDiff returns the tracked-file diff, git's stderr, and the failure if there was one. Stderr is returned separately so the caller can quote it without risking diff content in the error; see runGitSplit.

(ctx context.Context)

Source from the content-addressed store, hash-verified

566// failure if there was one. Stderr is returned separately so the caller can
567// quote it without risking diff content in the error; see runGitSplit.
568func (p *Provider) workspaceTrackedDiff(ctx context.Context) (string, string, error) {
569 out, _, err := p.runGitSplit(ctx, "-c", "core.quotepath=false", "diff", "--no-ext-diff", "--no-textconv", "--find-renames", "--src-prefix=a/", "--dst-prefix=b/", "--no-color", "-U"+fmt.Sprint(DiffContextLines), "--end-of-options", "HEAD", "--")
570 if err == nil && out != "" {
571 return out, "", nil
572 }
573 if ctx.Err() != nil {
574 return "", "", ctx.Err()
575 }
576 // Fall back to the staged diff when `git diff HEAD` errored or was empty. This is
577 // not redundant with the call above: in a repository with no commits yet there is no
578 // HEAD, so `git diff HEAD` fails with "bad revision 'HEAD'", but `git diff --staged`
579 // still surfaces staged changes by diffing the index against the empty tree — the only
580 // way to review a workspace before its first commit.
581 return p.runGitSplit(ctx, "-c", "core.quotepath=false", "diff", "--no-ext-diff", "--no-textconv", "--find-renames", "--src-prefix=a/", "--dst-prefix=b/", "--no-color", "-U"+fmt.Sprint(DiffContextLines), "--staged", "--")
582}
583
584func (p *Provider) untrackedFileDiffs(ctx context.Context) ([]string, error) {
585 files, err := p.untrackedFilesList(ctx)

Callers 1

GetDiffMethod · 0.95

Calls 2

runGitSplitMethod · 0.95
ErrMethod · 0.80

Tested by

no test coverage detected