| 530 | } |
| 531 | |
| 532 | func (p *Provider) workspaceTrackedDiff(ctx context.Context) (string, error) { |
| 533 | 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", "--") |
| 534 | if err == nil && out != "" { |
| 535 | return out, nil |
| 536 | } |
| 537 | if ctx.Err() != nil { |
| 538 | return "", ctx.Err() |
| 539 | } |
| 540 | // Fall back to the staged diff when `git diff HEAD` errored or was empty. This is |
| 541 | // not redundant with the call above: in a repository with no commits yet there is no |
| 542 | // HEAD, so `git diff HEAD` fails with "bad revision 'HEAD'", but `git diff --staged` |
| 543 | // still surfaces staged changes by diffing the index against the empty tree — the only |
| 544 | // way to review a workspace before its first commit. |
| 545 | 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", "--") |
| 546 | } |
| 547 | |
| 548 | func (p *Provider) untrackedFileDiffs(ctx context.Context) ([]string, error) { |
| 549 | files, err := p.untrackedFilesList(ctx) |