(
repository: Repository,
filePath: string,
options: { content: string } | { stage: 'ours' | 'theirs' },
hideWhitespaceInDiff: boolean = false
)
| 428 | * Uses `git diff --no-index` with temp files. |
| 429 | */ |
| 430 | export async function getResolutionDiff( |
| 431 | repository: Repository, |
| 432 | filePath: string, |
| 433 | options: { content: string } | { stage: 'ours' | 'theirs' }, |
| 434 | hideWhitespaceInDiff: boolean = false |
| 435 | ): Promise<IDiff> { |
| 436 | const gitStage = |
| 437 | 'stage' in options ? (options.stage === 'ours' ? ':2' : ':3') : undefined |
| 438 | |
| 439 | // Always diff against the working-tree file (which still has conflict |
| 440 | // markers). This gives a consistent baseline for all three resolution |
| 441 | // choices (Copilot, current, incoming) so the user sees exactly what each |
| 442 | // option changes relative to the file's current state on disk. |
| 443 | const baseContent = await readFile( |
| 444 | Path.join(repository.path, filePath), |
| 445 | 'utf8' |
| 446 | ) |
| 447 | let targetContent: string |
| 448 | |
| 449 | if (gitStage === undefined) { |
| 450 | // Direct content mode (e.g. Copilot's resolved text). |
| 451 | if (!('content' in options)) { |
| 452 | return { kind: DiffType.Unrenderable } |
| 453 | } |
| 454 | targetContent = options.content |
| 455 | } else { |
| 456 | // Stage mode — read the chosen side from the merge index. |
| 457 | // If the blob doesn't exist (e.g. file deleted on that side in a |
| 458 | // modify/delete conflict), use empty content to show full deletion. |
| 459 | try { |
| 460 | const buffer = await getBlobContents(repository, gitStage, filePath) |
| 461 | targetContent = buffer.toString('utf-8') |
| 462 | } catch { |
| 463 | targetContent = '' |
| 464 | } |
| 465 | } |
| 466 | |
| 467 | const tempBase = getTempFilePath('resolution-diff-base') |
| 468 | const tempTarget = getTempFilePath('resolution-diff-target') |
| 469 | |
| 470 | try { |
| 471 | await writeFile(tempBase, baseContent, 'utf8') |
| 472 | await writeFile(tempTarget, targetContent, 'utf8') |
| 473 | |
| 474 | const args = [ |
| 475 | 'diff', |
| 476 | ...(hideWhitespaceInDiff ? ['-w'] : []), |
| 477 | '--no-ext-diff', |
| 478 | '--patch-with-raw', |
| 479 | '-z', |
| 480 | '--no-color', |
| 481 | '--no-index', |
| 482 | '--', |
| 483 | tempBase, |
| 484 | tempTarget, |
| 485 | ] |
| 486 | |
| 487 | const { stdout } = await git(args, repository.path, 'getResolutionDiff', { |
no test coverage detected