Skip to content

Commit

Permalink
We couldn't find commit (#6209)
Browse files Browse the repository at this point in the history
Fixes #1691
  • Loading branch information
alexr00 authored Sep 10, 2024
1 parent 106cb98 commit 95fb6be
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
28 changes: 21 additions & 7 deletions src/view/gitContentProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,37 @@ import Logger from '../common/logger';
import { fromReviewUri } from '../common/uri';
import { CredentialStore } from '../github/credentials';
import { getRepositoryForFile } from '../github/utils';
import { GitFileChangeModel } from './fileChangeModel';
import { RepositoryFileSystemProvider } from './repositoryFileSystemProvider';
import { ReviewManager } from './reviewManager';
import { GitFileChangeNode, RemoteFileChangeNode } from './treeNodes/fileChangeNode';

export class GitContentFileSystemProvider extends RepositoryFileSystemProvider {
private _fallback?: (uri: vscode.Uri) => Promise<string>;

constructor(gitAPI: GitApiImpl, credentialStore: CredentialStore, private readonly reviewManagers: ReviewManager[]) {
constructor(gitAPI: GitApiImpl, credentialStore: CredentialStore, private readonly getReviewManagers: () => ReviewManager[]) {
super(gitAPI, credentialStore);
}

private getChangeModelForFile(file: vscode.Uri) {
for (const manager of this.reviewManagers) {
for (const change of manager.reviewModel.localFileChanges) {
private getChangeModelForFileAndFilesArray(file: vscode.Uri, getFiles: (manager: ReviewManager) => (GitFileChangeNode | RemoteFileChangeNode)[]) {
for (const manager of this.getReviewManagers()) {
const files = getFiles(manager);
for (const change of files) {
if ((change.changeModel.filePath.authority === file.authority) && (change.changeModel.filePath.path === file.path)) {
return change.changeModel;
}
}
}
}

private getChangeModelForFile(file: vscode.Uri): GitFileChangeModel | undefined {
return this.getChangeModelForFileAndFilesArray(file, manager => manager.reviewModel.localFileChanges) as GitFileChangeModel;
}

private getOutdatedChangeModelForFile(file: vscode.Uri) {
return this.getChangeModelForFileAndFilesArray(file, manager => manager.reviewModel.obsoleteFileChanges);
}

private async getRepositoryForFile(file: vscode.Uri): Promise<Repository | undefined> {
await this.waitForAuth();
if ((this.gitAPI.state !== 'initialized') || (this.gitAPI.repositories.length === 0)) {
Expand Down Expand Up @@ -81,9 +92,12 @@ export class GitContentFileSystemProvider extends RepositoryFileSystemProvider {
await repository.getCommit(commit);
} catch (err) {
Logger.error(err);
vscode.window.showErrorMessage(
`We couldn't find commit ${commit} locally. You may want to sync the branch with remote. Sometimes commits can disappear after a force-push`,
);
// Only show the error if we know it's not an outdated commit
if (!this.getOutdatedChangeModelForFile(uri)) {
vscode.window.showErrorMessage(
`We couldn't find commit ${commit} locally. You may want to sync the branch with remote. Sometimes commits can disappear after a force-push`,
);
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/view/reviewsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class ReviewsManager {
private _gitApi: GitApiImpl,
) {
this._disposables = [];
const gitContentProvider = new GitContentFileSystemProvider(_gitApi, _credentialStore, _reviewManagers);
const gitContentProvider = new GitContentFileSystemProvider(_gitApi, _credentialStore, () => this._reviewManagers);
gitContentProvider.registerTextDocumentContentFallback(this.provideTextDocumentContent.bind(this));
this._disposables.push(vscode.workspace.registerFileSystemProvider(Schemes.Review, gitContentProvider, { isReadonly: true }));
this.registerListeners();
Expand Down

0 comments on commit 95fb6be

Please sign in to comment.