Skip to content

Commit b0da547

Browse files
Copilotalexr00
andcommitted
Add EmptyCommitFileSystemProvider for displaying empty commits
Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
1 parent 3265feb commit b0da547

4 files changed

Lines changed: 35 additions & 4 deletions

File tree

src/common/uri.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,14 @@ export function toGitHubCommitUri(fileName: string, params: GitHubCommitUriParam
117117
});
118118
}
119119

120+
export function toEmptyCommitUri(commitSha: string): vscode.Uri {
121+
return vscode.Uri.from({
122+
scheme: Schemes.EmptyCommit,
123+
path: `/commit-${commitSha.substring(0, 7)}.txt`,
124+
query: commitSha
125+
});
126+
}
127+
120128
const ImageMimetypes = ['image/png', 'image/gif', 'image/jpeg', 'image/webp', 'image/tiff', 'image/bmp'];
121129
// Known media types that VS Code can handle: https://github.com/microsoft/vscode/blob/a64e8e5673a44e5b9c2d493666bde684bd5a135c/src/vs/base/common/mime.ts#L33-L84
122130
export const KnownMediaExtensions = [
@@ -750,7 +758,8 @@ export enum Schemes {
750758
Repo = 'repo', // New issue file for passing data
751759
Git = 'git', // File content from the git extension
752760
PRQuery = 'prquery', // PR query tree item
753-
GitHubCommit = 'githubcommit' // file content from GitHub for a commit
761+
GitHubCommit = 'githubcommit', // file content from GitHub for a commit
762+
EmptyCommit = 'emptycommit' // Empty commit placeholder file
754763
}
755764

756765
export function resolvePath(from: vscode.Uri, to: string) {

src/extension.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import { CommentDecorationProvider } from './view/commentDecorationProvider';
4444
import { CompareChanges } from './view/compareChangesTreeDataProvider';
4545
import { CreatePullRequestHelper } from './view/createPullRequestHelper';
4646
import { EmojiCompletionProvider } from './view/emojiCompletionProvider';
47+
import { EmptyCommitFileSystemProvider } from './view/emptyCommitFileSystemProvider';
4748
import { FileTypeDecorationProvider } from './view/fileTypeDecorationProvider';
4849
import { GitHubCommitFileSystemProvider } from './view/githubFileContentProvider';
4950
import { getInMemPRFileSystemProvider } from './view/inMemPRContentProvider';
@@ -500,6 +501,8 @@ async function deferredActivate(context: vscode.ExtensionContext, showPRControll
500501
context.subscriptions.push(vscode.workspace.registerFileSystemProvider(Schemes.Pr, inMemPRFileSystemProvider, { isReadonly: readOnlyMessage }));
501502
const githubFilesystemProvider = new GitHubCommitFileSystemProvider(reposManager, apiImpl, credentialStore);
502503
context.subscriptions.push(vscode.workspace.registerFileSystemProvider(Schemes.GitHubCommit, githubFilesystemProvider, { isReadonly: new vscode.MarkdownString(vscode.l10n.t('GitHub commits cannot be edited')) }));
504+
const emptyCommitFileSystemProvider = new EmptyCommitFileSystemProvider();
505+
context.subscriptions.push(vscode.workspace.registerFileSystemProvider(Schemes.EmptyCommit, emptyCommitFileSystemProvider, { isReadonly: true }));
503506

504507
await init(context, apiImpl, credentialStore, repositories, prTree, liveshareApiPromise, showPRController, reposManager, createPrHelper, copilotRemoteAgentManager, themeWatcher, prsTreeModel);
505508
return apiImpl;

src/github/pullRequestModel.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ import { Remote } from '../common/remote';
8989
import { DEFAULT_MERGE_METHOD, PR_SETTINGS_NAMESPACE } from '../common/settingKeys';
9090
import { ITelemetry } from '../common/telemetry';
9191
import { ClosedEvent, EventType, ReviewEvent, TimelineEvent } from '../common/timelineEvent';
92-
import { resolvePath, Schemes, toGitHubCommitUri, toPRUri, toReviewUri } from '../common/uri';
92+
import { resolvePath, Schemes, toEmptyCommitUri, toGitHubCommitUri, toPRUri, toReviewUri } from '../common/uri';
9393
import { formatError, isDescendant } from '../common/utils';
9494
import { InMemFileChangeModel, RemoteFileChangeModel } from '../view/fileChangeModel';
9595

@@ -1475,8 +1475,9 @@ export class PullRequestModel extends IssueModel<PullRequest> implements IPullRe
14751475

14761476
const changes = await githubRepository.compareCommits(parentCommit, commitSha);
14771477
if (!changes?.files || changes.files.length === 0) {
1478-
vscode.window.showInformationMessage(vscode.l10n.t('No changes found in commit {0}', commitSha.substring(0, 7)));
1479-
return;
1478+
// Open a file showing the empty commit message instead of showing a notification
1479+
const emptyCommitUri = toEmptyCommitUri(commitSha);
1480+
return vscode.window.showTextDocument(emptyCommitUri, { preview: false });
14801481
}
14811482

14821483
// Create URI pairs for the multi diff editor using review scheme
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import * as vscode from 'vscode';
7+
import { ReadonlyFileSystemProvider } from './readonlyFileSystemProvider';
8+
9+
/**
10+
* File system provider for displaying empty commits.
11+
* This provides a simple file that explains when a commit has no content.
12+
*/
13+
export class EmptyCommitFileSystemProvider extends ReadonlyFileSystemProvider {
14+
async readFile(_uri: vscode.Uri): Promise<Uint8Array> {
15+
const message = vscode.l10n.t('No changes to show.\nThis commit has no content.');
16+
return new TextEncoder().encode(message);
17+
}
18+
}

0 commit comments

Comments
 (0)