@@ -49,7 +49,7 @@ import type {
49
49
RevisionUriData ,
50
50
ScmRepository ,
51
51
} from '../../../git/gitProvider' ;
52
- import { encodeGitLensRevisionUriAuthority , GitUri } from '../../../git/gitUri' ;
52
+ import { encodeGitLensRevisionUriAuthority , GitUri , isGitUri } from '../../../git/gitUri' ;
53
53
import type { GitBlame , GitBlameAuthor , GitBlameLine , GitBlameLines } from '../../../git/models/blame' ;
54
54
import type { BranchSortOptions } from '../../../git/models/branch' ;
55
55
import {
@@ -4744,31 +4744,28 @@ export class LocalGitProvider implements GitProvider, Disposable {
4744
4744
}
4745
4745
4746
4746
@log ( )
4747
- async getStatusForFile ( repoPath : string , uri : Uri ) : Promise < GitStatusFile | undefined > {
4748
- const porcelainVersion = ( await this . git . isAtLeastVersion ( '2.11' ) ) ? 2 : 1 ;
4749
-
4750
- const [ relativePath , root ] = splitPath ( uri , repoPath ) ;
4751
-
4752
- const data = await this . git . status__file ( root , relativePath , porcelainVersion , {
4753
- similarityThreshold : configuration . get ( 'advanced.similarityThreshold' ) ,
4754
- } ) ;
4747
+ async getStatusForFile ( repoPath : string , pathOrUri : string | Uri ) : Promise < GitStatusFile | undefined > {
4748
+ const status = await this . getStatusForRepo ( repoPath ) ;
4749
+ if ( ! status ?. files . length ) return undefined ;
4755
4750
4756
- const status = parseGitStatus ( data , root , porcelainVersion ) ;
4757
- return status ?. files ?. [ 0 ] ;
4751
+ const [ relativePath ] = splitPath ( pathOrUri , repoPath ) ;
4752
+ const file = status . files . find ( f => f . path === relativePath ) ;
4753
+ return file ;
4758
4754
}
4759
4755
4760
4756
@log ( )
4761
4757
async getStatusForFiles ( repoPath : string , pathOrGlob : Uri ) : Promise < GitStatusFile [ ] | undefined > {
4762
- const porcelainVersion = ( await this . git . isAtLeastVersion ( '2.11' ) ) ? 2 : 1 ;
4763
-
4764
- const [ relativePath , root ] = splitPath ( pathOrGlob , repoPath ) ;
4758
+ let [ relativePath ] = splitPath ( pathOrGlob , repoPath ) ;
4759
+ if ( ! relativePath . endsWith ( '/*' ) ) {
4760
+ return this . getStatusForFile ( repoPath , pathOrGlob ) . then ( f => ( f != null ? [ f ] : undefined ) ) ;
4761
+ }
4765
4762
4766
- const data = await this . git . status__file ( root , relativePath , porcelainVersion , {
4767
- similarityThreshold : configuration . get ( 'advanced.similarityThreshold' ) ,
4768
- } ) ;
4763
+ relativePath = relativePath . substring ( 0 , relativePath . length - 1 ) ;
4764
+ const status = await this . getStatusForRepo ( repoPath ) ;
4765
+ if ( ! status ?. files . length ) return undefined ;
4769
4766
4770
- const status = parseGitStatus ( data , root , porcelainVersion ) ;
4771
- return status ?. files ?? [ ] ;
4767
+ const files = status . files . filter ( f => f . path . startsWith ( relativePath ) ) ;
4768
+ return files ;
4772
4769
}
4773
4770
4774
4771
@log ( )
@@ -4778,7 +4775,7 @@ export class LocalGitProvider implements GitProvider, Disposable {
4778
4775
const porcelainVersion = ( await this . git . isAtLeastVersion ( '2.11' ) ) ? 2 : 1 ;
4779
4776
4780
4777
const data = await this . git . status ( repoPath , porcelainVersion , {
4781
- similarityThreshold : configuration . get ( 'advanced.similarityThreshold' ) ,
4778
+ similarityThreshold : configuration . get ( 'advanced.similarityThreshold' ) ?? undefined ,
4782
4779
} ) ;
4783
4780
const status = parseGitStatus ( data , repoPath , porcelainVersion ) ;
4784
4781
@@ -4935,13 +4932,13 @@ export class LocalGitProvider implements GitProvider, Disposable {
4935
4932
if ( ref === deletedOrMissing ) return undefined ;
4936
4933
4937
4934
repository = this . container . git . getRepository ( Uri . file ( pathOrUri ) ) ;
4938
- repoPath = repoPath || repository ?. path ;
4935
+ repoPath ||= repository ?. path ;
4939
4936
4940
4937
[ relativePath , repoPath ] = splitPath ( pathOrUri , repoPath ) ;
4941
4938
} else {
4942
4939
if ( ! this . isTrackable ( pathOrUri ) ) return undefined ;
4943
4940
4944
- if ( pathOrUri instanceof GitUri ) {
4941
+ if ( isGitUri ( pathOrUri ) ) {
4945
4942
// Always use the ref of the GitUri
4946
4943
ref = pathOrUri . sha ;
4947
4944
if ( ref === deletedOrMissing ) return undefined ;
@@ -5033,9 +5030,18 @@ export class LocalGitProvider implements GitProvider, Disposable {
5033
5030
5034
5031
continue ;
5035
5032
}
5033
+
5034
+ return undefined ;
5036
5035
}
5037
5036
5038
- return undefined ;
5037
+ if ( ref != null ) return undefined ;
5038
+
5039
+ // If we still didn't find anything then check if we've been renamed first
5040
+ const status = await this . getStatusForFile ( repoPath , relativePath ) ;
5041
+ if ( status ?. originalPath != null ) {
5042
+ tracked = Boolean ( await this . git . ls_files ( repoPath , status . originalPath , { ref : 'HEAD' } ) ) ;
5043
+ if ( ! tracked ) return undefined ;
5044
+ }
5039
5045
}
5040
5046
5041
5047
return [ relativePath , repoPath ] ;
0 commit comments