| 319 | } |
| 320 | |
| 321 | func (p *Provider) workspaceTrackedDiff(ctx context.Context) (string, error) { |
| 322 | 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", "--") |
| 323 | if err == nil && out != "" { |
| 324 | return out, nil |
| 325 | } |
| 326 | if ctx.Err() != nil { |
| 327 | return "", ctx.Err() |
| 328 | } |
| 329 | // Fall back to the staged diff when `git diff HEAD` errored or was empty. This is |
| 330 | // not redundant with the call above: in a repository with no commits yet there is no |
| 331 | // HEAD, so `git diff HEAD` fails with "bad revision 'HEAD'", but `git diff --staged` |
| 332 | // still surfaces staged changes by diffing the index against the empty tree — the only |
| 333 | // way to review a workspace before its first commit. |
| 334 | 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", "--") |
| 335 | } |
| 336 | |
| 337 | func (p *Provider) untrackedFileDiffs(ctx context.Context) ([]string, error) { |
| 338 | files, err := p.untrackedFilesList(ctx) |