Skip to content

Commit 72da243

Browse files
committed
Use a popup to suggest verbose Git commits
1 parent a6317a5 commit 72da243

6 files changed

Lines changed: 47 additions & 18 deletions

File tree

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ messages](https://cbea.ms/git-commit).
3939

4040
### TODO
4141

42-
- When a user opens a `COMMIT_EDITMESSAGE` file and verbose commits are not
43-
enabled, open a popup in the bottom right corner offering a fix-it button
4442
- Consider the tests for no-diffs for both diagnostics and quick fixes. Are we
4543
really testing for comment-line followed by an empty line at the end?
4644
- Disable `@typescript-eslint/no-non-null-assertion` in `*.test.*` files, or in

src/extension.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ import * as vscode from "vscode";
22
import GitCommitCodeActionProvider from "./quickfix";
33
import GitCommitCompletionsProvider from "./completions";
44
import getCurrentGitBranch from "./getgitbranch";
5-
import { setVerboseCommitCommand } from "./setverbosecommits";
5+
import * as verbosecommits from "./verbosecommits";
66
import { getDiagnostics } from "./diagnostics";
7+
import { displayVerboseDiffMessage } from "./messages";
78

89
export const setVerboseCommitCommandId =
910
"git-commit-message-plus.setVerboseGitCommits";
@@ -41,7 +42,7 @@ export async function activate(context: vscode.ExtensionContext) {
4142
context.subscriptions.push(
4243
vscode.commands.registerCommand(
4344
setVerboseCommitCommandId,
44-
setVerboseCommitCommand
45+
verbosecommits.enable
4546
)
4647
);
4748

@@ -55,6 +56,13 @@ export async function activate(context: vscode.ExtensionContext) {
5556
)
5657
);
5758

59+
// Show informational toast about doing verbose Git commits
60+
vscode.workspace.onDidOpenTextDocument(
61+
displayVerboseDiffMessage,
62+
null,
63+
context.subscriptions
64+
);
65+
5866
// Call the listeners on initilization for current active text editor
5967
//
6068
// Inspiration from here:
@@ -64,6 +72,7 @@ export async function activate(context: vscode.ExtensionContext) {
6472
if (editor && editor.document.languageId === "git-commit") {
6573
gitBranch = await getCurrentGitBranch(editor.document.uri);
6674
doLinting(editor.document);
75+
displayVerboseDiffMessage(editor.document);
6776
}
6877
}
6978
vscode.window.onDidChangeActiveTextEditor(

src/messages.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import * as vscode from "vscode";
2+
import * as path from "path";
3+
import * as verbosecommits from "./verbosecommits";
4+
5+
/** Show informational toast about doing verbose Git commits */
6+
export async function displayVerboseDiffMessage(doc: vscode.TextDocument) {
7+
if (path.basename(doc.fileName) !== "COMMIT_EDITMSG") {
8+
// We only like one kind of files
9+
return;
10+
}
11+
12+
if (await verbosecommits.isEnabled()) {
13+
// Already done
14+
return;
15+
}
16+
17+
const decision = await vscode.window.showInformationMessage(
18+
"Use verbose Git commits to see diffs while typing your commit message",
19+
"Enable verbose commits"
20+
);
21+
if (decision === undefined) {
22+
return;
23+
}
24+
25+
// User picked the only option, let's do it!
26+
await verbosecommits.enable();
27+
}

src/quickfix.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as path from "path";
33
import * as utils from "./utils";
44
import { gitBranch, setVerboseCommitCommandId } from "./extension";
55
import { createBranchIssueIdFix, createUpcaseJiraIdFix } from "./jira";
6-
import { isVerboseCommitsEnabled } from "./setverbosecommits";
6+
import * as verbosecommits from "./verbosecommits";
77

88
// Inspired by:
99
// https://github.com/microsoft/vscode-extension-samples/blob/main/code-actions-sample/src/extension.ts
@@ -141,7 +141,7 @@ async function createEnableGitVerboseCommitFix(
141141
return [];
142142
}
143143

144-
if (await isVerboseCommitsEnabled()) {
144+
if (await verbosecommits.isEnabled()) {
145145
// Already enabled, we can't do anything
146146
return [];
147147
}

src/test/suite/quickfix.test.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,7 @@ import * as utils from "../../utils";
66
import * as vscode from "vscode";
77
import { ConfigurationTarget, workspace } from "vscode";
88
import { setVerboseCommitCommandId } from "../../extension";
9-
import {
10-
doesGitDoVerboseCommits,
11-
doesVsCodeDoVerboseCommits,
12-
isVerboseCommitsEnabled,
13-
} from "../../setverbosecommits";
9+
import * as verbosecommits from "../../verbosecommits";
1410

1511
import * as child_process from "child_process";
1612
import * as util from "util";
@@ -218,18 +214,18 @@ suite("Quick Fix", () => {
218214
// Verify VSCode verbose commits are now enabled
219215

220216
assert.equal(
221-
doesVsCodeDoVerboseCommits(),
217+
verbosecommits.doesVsCodeDoVerboseCommits(),
222218
true,
223219
"Verbose Git commits in VSCode"
224220
);
225221

226222
assert.equal(
227-
await doesGitDoVerboseCommits(),
223+
await verbosecommits.doesGitDoVerboseCommits(),
228224
true,
229225
"Verbose Git commits in Git"
230226
);
231227

232-
assert.equal(await isVerboseCommitsEnabled(), true);
228+
assert.equal(await verbosecommits.isEnabled(), true);
233229
});
234230
}
235231
}
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import * as util from "util";
55
const execFile = util.promisify(child_process.execFile);
66

77
/** Tell both Git and VSCode that commit messages should contain diffs */
8-
export async function setVerboseCommitCommand() {
8+
export async function enable() {
99
return Promise.all([
1010
// Set command line verbose-commits-by-default
1111
execFile("git", ["config", "--global", "commit.verbose", "true"]),
@@ -21,10 +21,9 @@ export async function setVerboseCommitCommand() {
2121
* Check whether there's something we can change to make verbose commits more
2222
* likely.
2323
*
24-
* Basically, if this function returns true then setVerboseCommitCommand() won't
25-
* have any effect.
24+
* Basically, if this function returns true then enable() won't have any effect.
2625
*/
27-
export async function isVerboseCommitsEnabled(): Promise<boolean> {
26+
export async function isEnabled(): Promise<boolean> {
2827
if (!doesVsCodeDoVerboseCommits()) {
2928
// VSCode setting can be updated
3029
return false;

0 commit comments

Comments
 (0)