22import { commands , Range , TextDocumentShowOptions , TextEditor , Uri , window } from 'vscode' ;
33import { ActiveEditorCommand , Commands } from './common' ;
44import { BuiltInCommands , GlyphChars } from '../constants' ;
5- import { GitCommit , GitService } from '../gitService' ;
5+ import { GitCommit , GitService , GitUri } from '../gitService' ;
66import { Logger } from '../logger' ;
77import * as path from 'path' ;
88
@@ -90,6 +90,15 @@ export class DiffWithCommand extends ActiveEditorCommand {
9090 if ( args . repoPath === undefined || args . lhs === undefined || args . rhs === undefined ) return undefined ;
9191
9292 try {
93+ // If the shas aren't resolved (e.g. a2d24f^), resolve them
94+ if ( GitService . isResolveRequired ( args . lhs . sha ) ) {
95+ args . lhs . sha = await this . git . resolveReference ( args . repoPath , args . lhs . sha , args . lhs . uri ) ;
96+ }
97+
98+ if ( GitService . isResolveRequired ( args . rhs . sha ) ) {
99+ args . rhs . sha = await this . git . resolveReference ( args . repoPath , args . rhs . sha , args . rhs . uri ) ;
100+ }
101+
93102 const [ lhs , rhs ] = await Promise . all ( [
94103 this . git . getVersionedFile ( args . repoPath , args . lhs . uri . fsPath , args . lhs . sha ) ,
95104 this . git . getVersionedFile ( args . repoPath , args . rhs . uri . fsPath , args . rhs . sha )
@@ -104,19 +113,26 @@ export class DiffWithCommand extends ActiveEditorCommand {
104113
105114 let rhsPrefix = '' ;
106115 if ( rhs === undefined ) {
107- rhsPrefix = 'deleted in ' ;
116+ rhsPrefix = GitService . isUncommitted ( args . rhs . sha )
117+ ? ' (deleted)'
118+ : 'deleted in ' ;
108119 }
109120 else if ( lhs === undefined || args . lhs . sha === GitService . deletedSha ) {
110121 rhsPrefix = 'added in ' ;
111122 }
112123
113- if ( args . lhs . title === undefined && lhs !== undefined && args . lhs . sha !== GitService . deletedSha ) {
124+ let lhsPrefix = '' ;
125+ if ( lhs === undefined && args . rhs . sha === '' ) {
126+ lhsPrefix = 'deleted in ' ;
127+ }
128+
129+ if ( args . lhs . title === undefined && args . lhs . sha !== GitService . deletedSha && ( lhs !== undefined || lhsPrefix !== '' ) ) {
114130 const suffix = GitService . shortenSha ( args . lhs . sha ) || '' ;
115- args . lhs . title = `${ path . basename ( args . lhs . uri . fsPath ) } ${ suffix !== '' ? ` (${ suffix } )` : '' } ` ;
131+ args . lhs . title = `${ path . basename ( args . lhs . uri . fsPath ) } ${ suffix !== '' ? ` (${ lhsPrefix } ${ suffix } )` : '' } ` ;
116132 }
117133 if ( args . rhs . title === undefined && args . rhs . sha !== GitService . deletedSha ) {
118134 const suffix = GitService . shortenSha ( args . rhs . sha ) || '' ;
119- args . rhs . title = `${ path . basename ( args . rhs . uri . fsPath ) } ${ suffix !== '' ? ` (${ rhsPrefix } ${ suffix } )` : '' } ` ;
135+ args . rhs . title = `${ path . basename ( args . rhs . uri . fsPath ) } ${ suffix !== '' ? ` (${ rhsPrefix } ${ suffix } )` : rhsPrefix } ` ;
120136 }
121137
122138 const title = ( args . lhs . title !== undefined && args . rhs . title !== undefined )
@@ -125,10 +141,10 @@ export class DiffWithCommand extends ActiveEditorCommand {
125141
126142 return await commands . executeCommand ( BuiltInCommands . Diff ,
127143 lhs === undefined
128- ? GitService . toGitContentUri ( GitService . deletedSha , args . lhs . uri . fsPath , args . repoPath )
144+ ? GitUri . toRevisionUri ( GitService . deletedSha , args . lhs . uri . fsPath , args . repoPath )
129145 : Uri . file ( lhs ) ,
130146 rhs === undefined
131- ? GitService . toGitContentUri ( GitService . deletedSha , args . rhs . uri . fsPath , args . repoPath )
147+ ? GitUri . toRevisionUri ( GitService . deletedSha , args . rhs . uri . fsPath , args . repoPath )
132148 : Uri . file ( rhs ) ,
133149 title ,
134150 args . showOptions ) ;
0 commit comments