Skip to content

Commit 95fb6be

Browse files
authored
We couldn't find commit (#6209)
Fixes #1691
1 parent 106cb98 commit 95fb6be

2 files changed

Lines changed: 22 additions & 8 deletions

File tree

src/view/gitContentProvider.ts

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,37 @@ import Logger from '../common/logger';
1212
import { fromReviewUri } from '../common/uri';
1313
import { CredentialStore } from '../github/credentials';
1414
import { getRepositoryForFile } from '../github/utils';
15+
import { GitFileChangeModel } from './fileChangeModel';
1516
import { RepositoryFileSystemProvider } from './repositoryFileSystemProvider';
1617
import { ReviewManager } from './reviewManager';
18+
import { GitFileChangeNode, RemoteFileChangeNode } from './treeNodes/fileChangeNode';
1719

1820
export 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
}

src/view/reviewsManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export class ReviewsManager {
3131
private _gitApi: GitApiImpl,
3232
) {
3333
this._disposables = [];
34-
const gitContentProvider = new GitContentFileSystemProvider(_gitApi, _credentialStore, _reviewManagers);
34+
const gitContentProvider = new GitContentFileSystemProvider(_gitApi, _credentialStore, () => this._reviewManagers);
3535
gitContentProvider.registerTextDocumentContentFallback(this.provideTextDocumentContent.bind(this));
3636
this._disposables.push(vscode.workspace.registerFileSystemProvider(Schemes.Review, gitContentProvider, { isReadonly: true }));
3737
this.registerListeners();

0 commit comments

Comments
 (0)