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

Method workspaceTrackedDiff

internal/diff/git.go:267–281  ·  view source on GitHub ↗
(ctx context.Context)

Source from the content-addressed store, hash-verified

265}
266
267func (p *Provider) workspaceTrackedDiff(ctx context.Context) (string, error) {
268 out, err := p.runGit(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", "--")
269 if err == nil && out != "" {
270 return out, nil
271 }
272 if ctx.Err() != nil {
273 return "", ctx.Err()
274 }
275 // Fall back to the staged diff when `git diff HEAD` errored or was empty. This is
276 // not redundant with the call above: in a repository with no commits yet there is no
277 // HEAD, so `git diff HEAD` fails with "bad revision 'HEAD'", but `git diff --staged`
278 // still surfaces staged changes by diffing the index against the empty tree — the only
279 // way to review a workspace before its first commit.
280 return p.runGit(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", "--")
281}
282
283func (p *Provider) untrackedFileDiffs(ctx context.Context) ([]string, error) {
284 files, err := p.untrackedFilesList(ctx)

Callers 1

GetDiffMethod · 0.95

Calls 1

runGitMethod · 0.95

Tested by

no test coverage detected