Skip to content

Commit 9560f47

Browse files
authored
feat: diff commit file in file history (#659)
1 parent 6e05c7f commit 9560f47

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

extensions/github1s/package.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,12 @@
170170
"category": "GitHub1s",
171171
"icon": "$(log-in)"
172172
},
173+
{
174+
"command": "github1s.commands.diffCommitFile",
175+
"title": "Diff File",
176+
"category": "GitHub1s",
177+
"icon": "$(diff)"
178+
},
173179
{
174180
"command": "github1s.commands.openCommitOnGitHub",
175181
"title": "Open on GitHub",
@@ -527,6 +533,11 @@
527533
"when": "viewItem == 'github1s:viewItems:commitListItem' && github1s:adapters:default:platformName == 'GitHub'",
528534
"group": "inline@2"
529535
},
536+
{
537+
"command": "github1s.commands.diffCommitFile",
538+
"when": "viewItem == 'github1s:viewItems:commitListItem' && view == 'github1s.views.fileHistory'",
539+
"group": "inline@3"
540+
},
530541
{
531542
"command": "github1s.commands.openCommitOnGitLab",
532543
"when": "viewItem == 'github1s:viewItems:commitListItem' && github1s:adapters:default:platformName == 'GitLab'",

extensions/github1s/src/commands/commit.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,20 @@ const commandSwitchToCommit = async (commitItemOrSha?: string | CommitTreeItem)
8282
}
8383
};
8484

85+
const commandDiffCommitFile = async (commitItem: CommitTreeItem) => {
86+
const commitSha = commitItem.commit.sha;
87+
if (!commitSha) {
88+
return;
89+
}
90+
const { repo } = await router.getState();
91+
const activeDocumentUri = vscode.window.activeTextEditor?.document?.uri;
92+
const fileUri = activeDocumentUri?.with({
93+
authority: `${repo}+${commitSha}`,
94+
query: '',
95+
});
96+
return vscode.commands.executeCommand('github1s.commands.openFilePreviousRevision', fileUri);
97+
};
98+
8599
// this command is used in `source control commit list view`
86100
const commandOpenCommitOnOfficialPage = async (commitItemOrSha?: string | CommitTreeItem) => {
87101
const commitSha = commitItemOrSha
@@ -127,6 +141,7 @@ export const registerCommitCommands = (context: vscode.ExtensionContext) => {
127141
vscode.commands.registerCommand('github1s.commands.refreshCommitList', commandRefreshCommitList),
128142
vscode.commands.registerCommand('github1s.commands.searchCommit', commandSwitchToCommit),
129143
vscode.commands.registerCommand('github1s.commands.switchToCommit', commandSwitchToCommit),
144+
vscode.commands.registerCommand('github1s.commands.diffCommitFile', commandDiffCommitFile),
130145
vscode.commands.registerCommand('github1s.commands.openCommitOnGitHub', commandOpenCommitOnOfficialPage),
131146
vscode.commands.registerCommand('github1s.commands.openCommitOnGitLab', commandOpenCommitOnOfficialPage),
132147
vscode.commands.registerCommand('github1s.commands.openCommitOnBitbucket', commandOpenCommitOnOfficialPage),

0 commit comments

Comments
 (0)