@@ -43,17 +43,28 @@ export class DiffGitSubProvider implements GitDiffSubProvider {
4343 ) { }
4444
4545 @log ( )
46- async getChangedFilesCount ( repoPath : string , ref ?: string ) : Promise < GitDiffShortStat | undefined > {
46+ async getChangedFilesCount (
47+ repoPath : string ,
48+ to ?: string ,
49+ from ?: string ,
50+ options ?: { uris ?: Uri [ ] } ,
51+ ) : Promise < GitDiffShortStat | undefined > {
4752 const scope = getLogScope ( ) ;
4853
54+ const args : string [ ] = [ ] ;
55+ if ( to != null ) {
56+ prepareToFromDiffArgs ( to , from , args ) ;
57+ }
58+
4959 try {
5060 const data = await this . git . exec (
5161 { cwd : repoPath , configs : gitDiffDefaultConfigs } ,
5262 'diff' ,
5363 '--shortstat' ,
5464 '--no-ext-diff' ,
55- ref ? ref : undefined ,
65+ ... args ,
5666 '--' ,
67+ options ?. uris ?. map ( u => this . provider . getRelativePath ( u , repoPath ) ) ?? undefined ,
5768 ) ;
5869 if ( ! data ) return undefined ;
5970 return parseGitDiffShortStat ( data ) ;
@@ -78,34 +89,7 @@ export class DiffGitSubProvider implements GitDiffSubProvider {
7889 const scope = getLogScope ( ) ;
7990 const args = [ `-U${ options ?. context ?? 3 } ` ] ;
8091
81- if ( to === uncommitted ) {
82- if ( from != null ) {
83- args . push ( from ) ;
84- } else {
85- // Get only unstaged changes
86- from = 'HEAD' ;
87- }
88- } else if ( to === uncommittedStaged ) {
89- args . push ( '--staged' ) ;
90- if ( from != null ) {
91- args . push ( from ) ;
92- } else {
93- // Get only staged changes
94- from = 'HEAD' ;
95- }
96- } else if ( from == null ) {
97- if ( to === '' || to . toUpperCase ( ) === 'HEAD' ) {
98- from = 'HEAD' ;
99- args . push ( from ) ;
100- } else {
101- from = `${ to } ^` ;
102- args . push ( from , to ) ;
103- }
104- } else if ( to === '' ) {
105- args . push ( from ) ;
106- } else {
107- args . push ( from , to ) ;
108- }
92+ from = prepareToFromDiffArgs ( to , from , args ) ;
10993
11094 let paths : Set < string > | undefined ;
11195 let untrackedPaths : string [ ] | undefined ;
@@ -641,3 +625,34 @@ export class DiffGitSubProvider implements GitDiffSubProvider {
641625 }
642626 }
643627}
628+ function prepareToFromDiffArgs ( to : string , from : string | undefined , args : string [ ] ) {
629+ if ( to === uncommitted ) {
630+ if ( from != null ) {
631+ args . push ( from ) ;
632+ } else {
633+ // Get only unstaged changes
634+ from = 'HEAD' ;
635+ }
636+ } else if ( to === uncommittedStaged ) {
637+ args . push ( '--staged' ) ;
638+ if ( from != null ) {
639+ args . push ( from ) ;
640+ } else {
641+ // Get only staged changes
642+ from = 'HEAD' ;
643+ }
644+ } else if ( from == null ) {
645+ if ( to === '' || to . toUpperCase ( ) === 'HEAD' ) {
646+ from = 'HEAD' ;
647+ args . push ( from ) ;
648+ } else {
649+ from = `${ to } ^` ;
650+ args . push ( from , to ) ;
651+ }
652+ } else if ( to === '' ) {
653+ args . push ( from ) ;
654+ } else {
655+ args . push ( from , to ) ;
656+ }
657+ return from ;
658+ }
0 commit comments