GetDiffSet returns both reviewable diffs and those excluded by the provider's built-in directory rules. It preserves GetDiff's filtering behavior while allowing callers that report the whole Git changeset to show those exclusions.
(ctx context.Context)
| 216 | // built-in directory rules. It preserves GetDiff's filtering behavior while |
| 217 | // allowing callers that report the whole Git changeset to show those exclusions. |
| 218 | func (p *Provider) GetDiffSet(ctx context.Context) (DiffSet, error) { |
| 219 | var combined strings.Builder |
| 220 | |
| 221 | switch p.mode { |
| 222 | case ModeRange: |
| 223 | base := p.MergeBase(ctx) |
| 224 | if base == "" { |
| 225 | return DiffSet{}, fmt.Errorf("cannot find merge-base between %s and %s", p.from, p.to) |
| 226 | } |
| 227 | out, stderr, 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", base, p.to, "--") |
| 228 | if err != nil { |
| 229 | return DiffSet{}, gitFailure("git diff", stderr, err) |
| 230 | } |
| 231 | combined.WriteString(out) |
| 232 | |
| 233 | case ModeCommit: |
| 234 | // --diff-merges=first-parent: for merge commits, plain `git show` |
| 235 | // emits a combined diff ("diff --cc"), which ParseDiffText cannot |
| 236 | // parse — the commit would silently yield zero reviewable diffs. |
| 237 | // Diffs against the first parent instead, in regular unified format. |
| 238 | out, stderr, err := p.runGitSplit(ctx, "-c", "core.quotepath=false", "show", "--no-ext-diff", "--no-textconv", "--find-renames", "--src-prefix=a/", "--dst-prefix=b/", "--no-color", "--diff-merges=first-parent", "-U"+fmt.Sprint(DiffContextLines), "--end-of-options", p.commit) |
| 239 | if err != nil { |
| 240 | return DiffSet{}, gitFailure("git show", stderr, err) |
| 241 | } |
| 242 | combined.WriteString(out) |
| 243 | |
| 244 | case ModeWorkspace: |
| 245 | tracked, stderr, err := p.workspaceTrackedDiff(ctx) |
| 246 | if err != nil { |
| 247 | return DiffSet{}, gitFailure("workspace tracked diff", stderr, err) |
| 248 | } |
| 249 | combined.WriteString(tracked) |
| 250 | |
| 251 | untracked, err := p.untrackedFileDiffs(ctx) |
| 252 | if err != nil { |
| 253 | return DiffSet{}, fmt.Errorf("untracked file diff failed: %w", err) |
| 254 | } |
| 255 | for _, ud := range untracked { |
| 256 | combined.WriteString(ud) |
| 257 | combined.WriteString("\n\n") |
| 258 | } |
| 259 | } |
| 260 | |
| 261 | var ref string |
| 262 | switch p.mode { |
| 263 | case ModeRange: |
| 264 | ref = p.to |
| 265 | case ModeCommit: |
| 266 | ref = p.commit |
| 267 | } |
| 268 | |
| 269 | diffs, err := ParseDiffText(ctx, combined.String(), p.repoDir, ref, p.runner) |
| 270 | if err != nil { |
| 271 | return DiffSet{}, err |
| 272 | } |
| 273 | return p.partitionDiffs(diffs), nil |
| 274 | } |
| 275 |