@@ -21,8 +21,9 @@ import { PromiseDelegate } from '@lumino/coreutils';
21
21
import { Message } from '@lumino/messaging' ;
22
22
import { ContextMenu , Menu , Panel } from '@lumino/widgets' ;
23
23
import * as React from 'react' ;
24
- import { DiffModel } from './components/diff/model' ;
24
+ import { DiffModel , MergeDiffModel } from './components/diff/model' ;
25
25
import { createPlainTextDiff } from './components/diff/PlainTextDiff' ;
26
+ import { createPlainTextMergeDiff } from './components/diff/PlainTextMergeDiff' ;
26
27
import { CONTEXT_COMMANDS } from './components/FileList' ;
27
28
import { AUTH_ERROR_MESSAGES , requestAPI } from './git' ;
28
29
import { logger } from './logger' ;
@@ -421,6 +422,7 @@ export function addCommands(
421
422
*
422
423
* @params model {Git.Diff.IModel<string>}: The diff model to display
423
424
* @params isText {boolean}: Optional, whether the content is a plain text
425
+ * @params isMerge {boolean}: Optional, whether the diff is a merge conflict
424
426
* @returns the main area widget or null
425
427
*/
426
428
commands . addCommand ( CommandIDs . gitShowDiff , {
@@ -433,7 +435,8 @@ export function addCommands(
433
435
} ;
434
436
435
437
const buildDiffWidget =
436
- getDiffProvider ( model . filename ) ?? ( isText && createPlainTextDiff ) ;
438
+ getDiffProvider ( model . filename ) ??
439
+ ( isText && model . base ? createPlainTextMergeDiff : createPlainTextDiff ) ;
437
440
438
441
if ( buildDiffWidget ) {
439
442
const id = `diff-${ model . filename } -${ model . reference . label } -${ model . challenger . label } ` ;
@@ -569,33 +572,29 @@ export function addCommands(
569
572
570
573
const repositoryPath = gitModel . getRelativeFilePath ( ) ;
571
574
const filename = PathExt . join ( repositoryPath , filePath ) ;
572
-
573
- // Merge conflict
574
- if ( status === 'unmerged' ) {
575
- const t = await gitModel . getMergeDiff ( filename ) ;
576
- // TODO: handle
577
- console . log ( t ) ;
578
- continue ;
579
- }
580
-
581
- let diffContext = context ;
582
- if ( ! diffContext ) {
583
- const specialRef =
584
- status === 'staged'
585
- ? Git . Diff . SpecialRef . INDEX
586
- : Git . Diff . SpecialRef . WORKING ;
587
- diffContext = {
588
- currentRef : specialRef ,
589
- previousRef : 'HEAD'
590
- } ;
591
- }
575
+ const specialRef =
576
+ status === 'staged'
577
+ ? Git . Diff . SpecialRef . INDEX
578
+ : Git . Diff . SpecialRef . WORKING ;
579
+
580
+ const diffContext : Git . Diff . IContext =
581
+ status === 'unmerged'
582
+ ? {
583
+ currentRef : 'MERGE_HEAD' ,
584
+ previousRef : 'HEAD' ,
585
+ baseRef : 'ORIG_HEAD'
586
+ }
587
+ : context ?? {
588
+ currentRef : specialRef ,
589
+ previousRef : 'HEAD'
590
+ } ;
592
591
593
592
const challengerRef = Git . Diff . SpecialRef [ diffContext . currentRef as any ]
594
593
? { special : Git . Diff . SpecialRef [ diffContext . currentRef as any ] }
595
594
: { git : diffContext . currentRef } ;
596
595
597
- // Create the diff widget
598
- const model = new DiffModel < string > ( {
596
+ // Base props used for Diff Model
597
+ const props = {
599
598
challenger : {
600
599
content : async ( ) => {
601
600
return requestAPI < Git . IDiffContent > (
@@ -630,8 +629,32 @@ export function addCommands(
630
629
diffContext . previousRef ,
631
630
source : diffContext . previousRef ,
632
631
updateAt : Date . now ( )
632
+ } ,
633
+ // Only add base when diff-ing merge conflicts
634
+ base : diffContext . baseRef && {
635
+ content : async ( ) => {
636
+ return requestAPI < Git . IDiffContent > (
637
+ URLExt . join ( repositoryPath , 'content' ) ,
638
+ 'POST' ,
639
+ {
640
+ filename : filePath ,
641
+ reference : { git : diffContext . baseRef }
642
+ }
643
+ ) . then ( data => data . content ) ;
644
+ } ,
645
+ label :
646
+ ( Git . Diff . SpecialRef [ diffContext . baseRef as any ] as any ) ||
647
+ diffContext . baseRef ,
648
+ source : diffContext . baseRef ,
649
+ updateAt : Date . now ( )
633
650
}
634
- } ) ;
651
+ } ;
652
+
653
+ // Create the diff widget
654
+ const model =
655
+ status === 'unmerged'
656
+ ? new MergeDiffModel < string > ( props )
657
+ : new DiffModel < string > ( props ) ;
635
658
636
659
const widget = await commands . execute ( CommandIDs . gitShowDiff , {
637
660
model,
0 commit comments