@@ -31,6 +31,7 @@ import type {
3131 CommitsLogParser ,
3232 CommitsWithFilesLogParser ,
3333 ParsedCommit ,
34+ ParsedStash ,
3435} from '../../../../git/parsers/logParser' ;
3536import {
3637 getCommitsLogParser ,
@@ -185,11 +186,7 @@ export class CommitsGitSubProvider implements GitCommitsSubProvider {
185186 f . status as GitFileStatus ,
186187 f . originalPath ,
187188 undefined ,
188- {
189- additions : f . additions ,
190- deletions : f . deletions ,
191- changes : 0 ,
192- } ,
189+ { additions : f . additions , deletions : f . deletions , changes : 0 } ,
193190 ) ,
194191 ) ;
195192
@@ -1255,35 +1252,36 @@ function createCommit(
12551252 ) ;
12561253}
12571254
1258- function createCommitFileset (
1255+ export function createCommitFileset (
12591256 container : Container ,
1260- c : ParsedCommit ,
1257+ c : ParsedCommit | ParsedStash ,
12611258 repoPath : string ,
12621259 pathspec : string | undefined ,
12631260) : GitCommitFileset {
1264- return {
1265- files :
1266- c . files ?. map (
1267- f =>
1268- new GitFileChange (
1269- container ,
1270- repoPath ,
1271- f . path ,
1272- f . status as GitFileStatus ,
1273- f . originalPath ,
1274- undefined ,
1275- {
1276- additions : f . additions ?? 0 ,
1277- deletions : f . deletions ?? 0 ,
1278- changes : 0 ,
1279- } ,
1280- undefined ,
1281- f . range ? { startLine : f . range . startLine , endLine : f . range . endLine } : undefined ,
1282- ) ,
1283- ) ?? [ ] ,
1284- filtered : Boolean ( pathspec ) ,
1285- pathspec : pathspec ,
1286- } ;
1261+ // If the files are missing or it's a merge commit without files or pathspec, then consider the files unloaded
1262+ if ( c . files == null || ( ! c . files . length && pathspec == null && c . parents . includes ( ' ' ) ) ) {
1263+ return {
1264+ files : undefined ,
1265+ filtered : pathspec ? { files : undefined , pathspec : pathspec } : undefined ,
1266+ } ;
1267+ }
1268+
1269+ const files = c . files . map (
1270+ f =>
1271+ new GitFileChange (
1272+ container ,
1273+ repoPath ,
1274+ f . path ,
1275+ f . status as GitFileStatus ,
1276+ f . originalPath ,
1277+ undefined ,
1278+ { additions : f . additions ?? 0 , deletions : f . deletions ?? 0 , changes : 0 } ,
1279+ undefined ,
1280+ f . range ? { startLine : f . range . startLine , endLine : f . range . endLine } : undefined ,
1281+ ) ,
1282+ ) ;
1283+
1284+ return pathspec ? { files : undefined , filtered : { files : files , pathspec : pathspec } } : { files : files } ;
12871285}
12881286
12891287function getGitStartEnd ( range : Range ) : [ number , number ] {
@@ -1326,15 +1324,19 @@ async function parseCommits(
13261324 if ( stash != null ) {
13271325 if ( commits . has ( stash . sha ) ) {
13281326 countStashChildCommits ++ ;
1329- } else {
1327+ } else if ( allowFilteredFiles ) {
13301328 commits . set (
13311329 stash . sha ,
1332- stash . with (
1333- allowFilteredFiles
1334- ? { fileset : createCommitFileset ( container , c , repoPath , pathspec ) }
1335- : { } ,
1336- ) ,
1330+ stash . with ( {
1331+ fileset : {
1332+ ...createCommitFileset ( container , c , repoPath , pathspec ) ,
1333+ // Add the full stash files back into the fileset
1334+ files : stash . fileset ?. files ,
1335+ } ,
1336+ } ) ,
13371337 ) ;
1338+ } else {
1339+ commits . set ( stash . sha , stash ) ;
13381340 }
13391341 continue ;
13401342 }
@@ -1366,15 +1368,19 @@ async function parseCommits(
13661368 if ( stash != null ) {
13671369 if ( commits . has ( stash . sha ) ) {
13681370 countStashChildCommits ++ ;
1369- } else {
1371+ } else if ( allowFilteredFiles ) {
13701372 commits . set (
13711373 stash . sha ,
1372- stash . with (
1373- allowFilteredFiles
1374- ? { fileset : createCommitFileset ( container , c , repoPath , pathspec ) }
1375- : { } ,
1376- ) ,
1374+ stash . with ( {
1375+ fileset : {
1376+ ...createCommitFileset ( container , c , repoPath , pathspec ) ,
1377+ // Add the full stash files back into the fileset
1378+ files : stash . fileset ?. files ,
1379+ } ,
1380+ } ) ,
13771381 ) ;
1382+ } else {
1383+ commits . set ( stash . sha , stash ) ;
13781384 }
13791385 continue ;
13801386 }
0 commit comments