@@ -12,26 +12,37 @@ import Logger from '../common/logger';
1212import { fromReviewUri } from '../common/uri' ;
1313import { CredentialStore } from '../github/credentials' ;
1414import { getRepositoryForFile } from '../github/utils' ;
15+ import { GitFileChangeModel } from './fileChangeModel' ;
1516import { RepositoryFileSystemProvider } from './repositoryFileSystemProvider' ;
1617import { ReviewManager } from './reviewManager' ;
18+ import { GitFileChangeNode , RemoteFileChangeNode } from './treeNodes/fileChangeNode' ;
1719
1820export class GitContentFileSystemProvider extends RepositoryFileSystemProvider {
1921 private _fallback ?: ( uri : vscode . Uri ) => Promise < string > ;
2022
21- constructor ( gitAPI : GitApiImpl , credentialStore : CredentialStore , private readonly reviewManagers : ReviewManager [ ] ) {
23+ constructor ( gitAPI : GitApiImpl , credentialStore : CredentialStore , private readonly getReviewManagers : ( ) => ReviewManager [ ] ) {
2224 super ( gitAPI , credentialStore ) ;
2325 }
2426
25- private getChangeModelForFile ( file : vscode . Uri ) {
26- for ( const manager of this . reviewManagers ) {
27- for ( const change of manager . reviewModel . localFileChanges ) {
27+ private getChangeModelForFileAndFilesArray ( file : vscode . Uri , getFiles : ( manager : ReviewManager ) => ( GitFileChangeNode | RemoteFileChangeNode ) [ ] ) {
28+ for ( const manager of this . getReviewManagers ( ) ) {
29+ const files = getFiles ( manager ) ;
30+ for ( const change of files ) {
2831 if ( ( change . changeModel . filePath . authority === file . authority ) && ( change . changeModel . filePath . path === file . path ) ) {
2932 return change . changeModel ;
3033 }
3134 }
3235 }
3336 }
3437
38+ private getChangeModelForFile ( file : vscode . Uri ) : GitFileChangeModel | undefined {
39+ return this . getChangeModelForFileAndFilesArray ( file , manager => manager . reviewModel . localFileChanges ) as GitFileChangeModel ;
40+ }
41+
42+ private getOutdatedChangeModelForFile ( file : vscode . Uri ) {
43+ return this . getChangeModelForFileAndFilesArray ( file , manager => manager . reviewModel . obsoleteFileChanges ) ;
44+ }
45+
3546 private async getRepositoryForFile ( file : vscode . Uri ) : Promise < Repository | undefined > {
3647 await this . waitForAuth ( ) ;
3748 if ( ( this . gitAPI . state !== 'initialized' ) || ( this . gitAPI . repositories . length === 0 ) ) {
@@ -81,9 +92,12 @@ export class GitContentFileSystemProvider extends RepositoryFileSystemProvider {
8192 await repository . getCommit ( commit ) ;
8293 } catch ( err ) {
8394 Logger . error ( err ) ;
84- vscode . window . showErrorMessage (
85- `We couldn't find commit ${ commit } locally. You may want to sync the branch with remote. Sometimes commits can disappear after a force-push` ,
86- ) ;
95+ // Only show the error if we know it's not an outdated commit
96+ if ( ! this . getOutdatedChangeModelForFile ( uri ) ) {
97+ vscode . window . showErrorMessage (
98+ `We couldn't find commit ${ commit } locally. You may want to sync the branch with remote. Sometimes commits can disappear after a force-push` ,
99+ ) ;
100+ }
87101 }
88102 }
89103 }
0 commit comments