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