Skip to content

Commit d1e38a1

Browse files
author
Rachel Macfarlane
committed
Fixes #162, 'Couldn't find commit' error notification
1 parent ce1233c commit d1e38a1

2 files changed

Lines changed: 22 additions & 6 deletions

File tree

src/common/repository.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,15 @@ export class Repository {
288288
}
289289
}
290290

291+
async checkCommitExists(commit: string): Promise<boolean> {
292+
try {
293+
const result = await this.run(['show', '-q', commit]);
294+
return result.stdout.trim().length !== 0;
295+
} catch (e) {
296+
return false;
297+
}
298+
}
299+
291300
async getFileObjectId(commit: string, path: string): Promise<string> {
292301
try {
293302
const args = ['rev-parse', `${commit}:${path}`];

src/view/gitContentProvider.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,21 @@ export class GitContentProvider implements vscode.TextDocumentContentProvider {
2323
return '';
2424
}
2525

26-
let ret = await this.repository.show(`${commit}:${path}`);
27-
28-
if (!ret) {
29-
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`);
30-
ret = await this._fallback(uri);
26+
let content = await this.repository.show(`${commit}:${path}`);
27+
28+
if (!content) {
29+
content = await this._fallback(uri);
30+
if (!content) {
31+
// Content does not exist for the base or modified file for a file deletion or addition.
32+
// Manually check if the commit exists before notifying the user.
33+
const commitExistsLocally = await this.repository.checkCommitExists(commit);
34+
if (!commitExistsLocally) {
35+
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`);
36+
}
37+
}
3138
}
3239

33-
return ret || '';
40+
return content || '';
3441
}
3542

3643
registerTextDocumentContentFallback(provider: (uri: vscode.Uri) => Promise<string>) {

0 commit comments

Comments
 (0)