@@ -8,13 +8,14 @@ import { formatDate, fromNow } from '../../system/date';
88import { gate } from '../../system/decorators/gate' ;
99import { memoize } from '../../system/decorators/memoize' ;
1010import { getLoggableName } from '../../system/logger' ;
11+ import { getSettledValue } from '../../system/promise' ;
1112import { pluralize } from '../../system/string' ;
1213import type { PreviousLineComparisonUrisResult } from '../gitProvider' ;
1314import { GitUri } from '../gitUri' ;
1415import type { RemoteProvider } from '../remotes/remoteProvider' ;
1516import { uncommitted , uncommittedStaged } from './constants' ;
1617import type { GitFile } from './file' ;
17- import { GitFileChange , GitFileWorkingTreeStatus } from './file' ;
18+ import { GitFileChange , mapFilesWithStats } from './file' ;
1819import type { PullRequest } from './pullRequest' ;
1920import type { GitReference , GitRevisionReference , GitStashReference } from './reference' ;
2021import { isSha , isUncommitted , isUncommittedParent , isUncommittedStaged } from './reference' ;
@@ -226,77 +227,49 @@ export class GitCommit implements GitRevisionReference {
226227 return ;
227228 }
228229
229- const [ commitResult , untrackedResult , commitFilesStatsResult ] = await Promise . allSettled ( [
230- this . container . git . getCommit ( this . repoPath , this . refType === 'stash' ? `${ this . stashName } ^2` : this . sha ) ,
231- // Check for any untracked files -- since git doesn't return them via `git stash list` :(
232- // See https://stackoverflow.com/questions/12681529/
233- this . refType === 'stash' && ! this . _stashUntrackedFilesLoaded
234- ? this . container . git . getCommit ( this . repoPath , `${ this . stashName } ^3` )
235- : undefined ,
236- options ?. include ?. stats
237- ? this . container . git . getCommitFileStats (
238- this . repoPath ,
239- this . refType === 'stash' ? `${ this . stashName } ^2` : this . sha ,
240- )
241- : undefined ,
242- this . getPreviousSha ( ) ,
243- ] ) ;
244-
245- let commit ;
246-
247- if ( commitResult . status === 'fulfilled' && commitResult . value != null ) {
248- commit = commitResult . value ;
249- this . parents . push ( ...( commit . parents ?? [ ] ) ) ;
250- this . _summary = commit . summary ;
251- this . _message = commit . message ;
252- this . _files = commit . files as GitFileChange [ ] ;
253-
254- if ( commitFilesStatsResult . status === 'fulfilled' && commitFilesStatsResult . value != null ) {
255- this . _files = this . _files . map ( file => {
256- const fileWithStats = commitFilesStatsResult . value ! . find ( f => f . path === file . path ) ;
257- return fileWithStats != null
258- ? new GitFileChange (
259- file . repoPath ,
260- file . path ,
261- file . status ,
262- file . originalPath ,
263- file . previousSha ,
264- fileWithStats . stats ,
265- )
266- : file ;
267- } ) ;
230+ if ( this . refType === 'stash' ) {
231+ const [ stashFilesResult ] = await Promise . allSettled ( [
232+ this . container . git . getStashCommitFiles ( this . repoPath , this . sha , options ) ,
233+ this . getPreviousSha ( ) ,
234+ ] ) ;
235+
236+ const stashFiles = getSettledValue ( stashFilesResult ) ;
237+ if ( stashFiles ?. length ) {
238+ this . _files = stashFiles ;
239+ }
240+ this . _stashUntrackedFilesLoaded = true ;
241+ } else {
242+ const [ commitResult , commitFilesStatsResult ] = await Promise . allSettled ( [
243+ this . container . git . getCommit ( this . repoPath , this . sha ) ,
244+ options ?. include ?. stats ? this . container . git . getCommitFileStats ( this . repoPath , this . sha ) : undefined ,
245+ this . getPreviousSha ( ) ,
246+ ] ) ;
247+
248+ const commit = getSettledValue ( commitResult ) ;
249+ if ( commit != null ) {
250+ this . parents . push ( ...( commit . parents ?? [ ] ) ) ;
251+ this . _summary = commit . summary ;
252+ this . _message = commit . message ;
253+ this . _files = ( commit . files ?? [ ] ) as Mutable < typeof commit . files > ;
268254 }
269255
270- if ( this . _file != null ) {
271- const file = this . _files . find ( f => f . path === this . _file ! . path ) ;
272- if ( file != null ) {
273- this . _file = new GitFileChange (
274- file . repoPath ,
275- file . path ,
276- file . status ,
277- file . originalPath ?? this . _file . originalPath ,
278- file . previousSha ?? this . _file . previousSha ,
279- file . stats ?? this . _file . stats ,
280- ) ;
281- }
256+ const commitFilesStats = getSettledValue ( commitFilesStatsResult ) ;
257+ if ( commitFilesStats ?. length && this . _files ?. length ) {
258+ this . _files = mapFilesWithStats ( this . _files , commitFilesStats ) ;
282259 }
283260 }
284261
285- if ( untrackedResult . status === 'fulfilled' && untrackedResult . value != null ) {
286- this . _stashUntrackedFilesLoaded = true ;
287-
288- commit = untrackedResult . value ;
289- if ( commit ?. files != null && commit . files . length !== 0 ) {
290- // Since these files are untracked -- make them look that way
291- const files = commit . files . map (
292- f => new GitFileChange ( this . repoPath , f . path , GitFileWorkingTreeStatus . Untracked , f . originalPath ) ,
262+ if ( this . _files != null && this . _file != null ) {
263+ const file = this . _files . find ( f => f . path === this . _file ! . path ) ;
264+ if ( file != null ) {
265+ this . _file = new GitFileChange (
266+ file . repoPath ,
267+ file . path ,
268+ file . status ,
269+ file . originalPath ?? this . _file . originalPath ,
270+ file . previousSha ?? this . _file . previousSha ,
271+ file . stats ?? this . _file . stats ,
293272 ) ;
294-
295- if ( this . _files == null ) {
296- this . _files = files ;
297- } else {
298- this . _files . push ( ...files ) ;
299- }
300273 }
301274 }
302275
@@ -627,13 +600,13 @@ export class GitCommit implements GitRevisionReference {
627600 return this . container . git . hasCommitBeenPushed ( this . repoPath , this . ref ) ;
628601 }
629602
630- with ( changes : {
603+ with < T extends GitCommit > ( changes : {
631604 sha ?: string ;
632605 parents ?: string [ ] ;
633606 files ?: { file ?: GitFileChange | null ; files ?: GitFileChange [ ] | null } | null ;
634607 lines ?: GitCommitLine [ ] ;
635608 stats ?: GitCommitStats ;
636- } ) : GitCommit {
609+ } ) : T {
637610 let files ;
638611 if ( changes . files != null ) {
639612 files = { file : this . _file , files : this . _files } ;
@@ -668,7 +641,7 @@ export class GitCommit implements GitRevisionReference {
668641 this . tips ,
669642 this . stashName ,
670643 this . stashOnRef ,
671- ) ;
644+ ) as T ;
672645 }
673646
674647 protected getChangedValue < T > ( change : T | null | undefined , original : T | undefined ) : T | undefined {
0 commit comments