Skip to content

Commit 663810e

Browse files
authored
Adds commands for --no-verify commit variants (microsoft#106335)
* add `{allow,confirm}NoVerifyCommit` options * adds commit comands with no verify * handles no verify command variants * handle no verify commit option * only display no verify variants when option is set
1 parent 82d953a commit 663810e

5 files changed

Lines changed: 202 additions & 4 deletions

File tree

extensions/git/package.json

Lines changed: 119 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,47 @@
216216
"title": "%command.commitAllAmend%",
217217
"category": "Git"
218218
},
219+
{
220+
"command": "git.commitNoVerify",
221+
"title": "%command.commitNoVerify%",
222+
"category": "Git",
223+
"icon": "$(check)"
224+
},
225+
{
226+
"command": "git.commitStagedNoVerify",
227+
"title": "%command.commitStagedNoVerify%",
228+
"category": "Git"
229+
},
230+
{
231+
"command": "git.commitEmptyNoVerify",
232+
"title": "%command.commitEmptyNoVerify%",
233+
"category": "Git"
234+
},
235+
{
236+
"command": "git.commitStagedSignedNoVerify",
237+
"title": "%command.commitStagedSignedNoVerify%",
238+
"category": "Git"
239+
},
240+
{
241+
"command": "git.commitStagedAmendNoVerify",
242+
"title": "%command.commitStagedAmendNoVerify%",
243+
"category": "Git"
244+
},
245+
{
246+
"command": "git.commitAllNoVerify",
247+
"title": "%command.commitAllNoVerify%",
248+
"category": "Git"
249+
},
250+
{
251+
"command": "git.commitAllSignedNoVerify",
252+
"title": "%command.commitAllSignedNoVerify%",
253+
"category": "Git"
254+
},
255+
{
256+
"command": "git.commitAllAmendNoVerify",
257+
"title": "%command.commitAllAmendNoVerify%",
258+
"category": "Git"
259+
},
219260
{
220261
"command": "git.restoreCommitTemplate",
221262
"title": "%command.restoreCommitTemplate%",
@@ -581,6 +622,38 @@
581622
"command": "git.commitAllAmend",
582623
"when": "config.git.enabled && !git.missing && gitOpenRepositoryCount != 0"
583624
},
625+
{
626+
"command": "git.commitNoVerify",
627+
"when": "config.git.enabled && !git.missing && config.git.allowNoVerifyCommit && gitOpenRepositoryCount != 0"
628+
},
629+
{
630+
"command": "git.commitStagedNoVerify",
631+
"when": "config.git.enabled && !git.missing && config.git.allowNoVerifyCommit && gitOpenRepositoryCount != 0"
632+
},
633+
{
634+
"command": "git.commitEmptyNoVerify",
635+
"when": "config.git.enabled && !git.missing && config.git.allowNoVerifyCommit && gitOpenRepositoryCount != 0"
636+
},
637+
{
638+
"command": "git.commitStagedSignedNoVerify",
639+
"when": "config.git.enabled && !git.missing && config.git.allowNoVerifyCommit && gitOpenRepositoryCount != 0"
640+
},
641+
{
642+
"command": "git.commitStagedAmendNoVerify",
643+
"when": "config.git.enabled && !git.missing && config.git.allowNoVerifyCommit && gitOpenRepositoryCount != 0"
644+
},
645+
{
646+
"command": "git.commitAllNoVerify",
647+
"when": "config.git.enabled && !git.missing && config.git.allowNoVerifyCommit && gitOpenRepositoryCount != 0"
648+
},
649+
{
650+
"command": "git.commitAllSignedNoVerify",
651+
"when": "config.git.enabled && !git.missing && config.git.allowNoVerifyCommit && gitOpenRepositoryCount != 0"
652+
},
653+
{
654+
"command": "git.commitAllAmendNoVerify",
655+
"when": "config.git.enabled && !git.missing && config.git.allowNoVerifyCommit && gitOpenRepositoryCount != 0"
656+
},
584657
{
585658
"command": "git.restoreCommitTemplate",
586659
"when": "false"
@@ -1239,13 +1312,38 @@
12391312
"command": "git.rebaseAbort",
12401313
"group": "1_commit@5"
12411314
},
1315+
{
1316+
"command": "git.commitNoVerify",
1317+
"group": "1_commit@6",
1318+
"when": "config.git.allowNoVerifyCommit"
1319+
},
1320+
{
1321+
"command": "git.commitStagedNoVerify",
1322+
"group": "1_commit@7",
1323+
"when": "config.git.allowNoVerifyCommit"
1324+
},
1325+
{
1326+
"command": "git.commitAllNoVerify",
1327+
"group": "1_commit@8",
1328+
"when": "config.git.allowNoVerifyCommit"
1329+
},
12421330
{
12431331
"command": "git.commitStagedAmend",
12441332
"group": "2_amend@1"
12451333
},
12461334
{
12471335
"command": "git.commitAllAmend",
1248-
"group": "2_amend@1"
1336+
"group": "2_amend@2"
1337+
},
1338+
{
1339+
"command": "git.commitStagedAmendNoVerify",
1340+
"group": "2_amend@3",
1341+
"when": "config.git.allowNoVerifyCommit"
1342+
},
1343+
{
1344+
"command": "git.commitAllAmendNoVerify",
1345+
"group": "2_amend@4",
1346+
"when": "config.git.allowNoVerifyCommit"
12491347
},
12501348
{
12511349
"command": "git.commitStagedSigned",
@@ -1254,6 +1352,16 @@
12541352
{
12551353
"command": "git.commitAllSigned",
12561354
"group": "3_signoff@2"
1355+
},
1356+
{
1357+
"command": "git.commitStagedSignedNoVerify",
1358+
"group": "3_signoff@3",
1359+
"when": "config.git.allowNoVerifyCommit"
1360+
},
1361+
{
1362+
"command": "git.commitAllSignedNoVerify",
1363+
"group": "3_signoff@4",
1364+
"when": "config.git.allowNoVerifyCommit"
12571365
}
12581366
],
12591367
"git.changes": [
@@ -1730,6 +1838,16 @@
17301838
"default": true,
17311839
"description": "%config.confirmForcePush%"
17321840
},
1841+
"git.allowNoVerifyCommit": {
1842+
"type": "boolean",
1843+
"default": false,
1844+
"description": "%config.allowNoVerifyCommit%"
1845+
},
1846+
"git.confirmNoVerifyCommit": {
1847+
"type": "boolean",
1848+
"default": true,
1849+
"description": "%config.confirmNoVerifyCommit%"
1850+
},
17331851
"git.openDiffOnClick": {
17341852
"type": "boolean",
17351853
"scope": "resource",

extensions/git/package.nls.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@
3434
"command.commitAll": "Commit All",
3535
"command.commitAllSigned": "Commit All (Signed Off)",
3636
"command.commitAllAmend": "Commit All (Amend)",
37+
"command.commitNoVerify": "Commit (No Nerify)",
38+
"command.commitStagedNoVerify": "Commit Staged (No Verify)",
39+
"command.commitEmptyNoVerify": "Commit Empty (No Verify)",
40+
"command.commitStagedSignedNoVerify": "Commit Staged (Signed Off, No Verify)",
41+
"command.commitStagedAmendNoVerify": "Commit Staged (Amend, No Verify)",
42+
"command.commitAllNoVerify": "Commit All (No Verify)",
43+
"command.commitAllSignedNoVerify": "Commit All (Signed Off, No Verify)",
44+
"command.commitAllAmendNoVerify": "Commit All (Amend, No Verify)",
3745
"command.restoreCommitTemplate": "Restore Commit Template",
3846
"command.undoCommit": "Undo Last Commit",
3947
"command.checkout": "Checkout to...",
@@ -139,6 +147,8 @@
139147
"config.allowForcePush": "Controls whether force push (with or without lease) is enabled.",
140148
"config.useForcePushWithLease": "Controls whether force pushing uses the safer force-with-lease variant.",
141149
"config.confirmForcePush": "Controls whether to ask for confirmation before force-pushing.",
150+
"config.allowNoVerifyCommit": "Controls whether commits without running pre-commit and commit-msg hooks are allowed.",
151+
"config.confirmNoVerifyCommit": "Controls whether to ask for confirmation before commiting without verification.",
142152
"config.openDiffOnClick": "Controls whether the diff editor should be opened when clicking a change. Otherwise the regular editor will be opened.",
143153
"config.supportCancellation": "Controls whether a notification comes up when running the Sync action, which allows the user to cancel the operation.",
144154
"config.branchSortOrder": "Controls the sort order for branches.",

extensions/git/src/api/git.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ export interface CommitOptions {
130130
signoff?: boolean;
131131
signCommit?: boolean;
132132
empty?: boolean;
133+
noVerify?: boolean;
133134
}
134135

135136
export interface BranchQuery {

extensions/git/src/commands.ts

Lines changed: 67 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1441,6 +1441,26 @@ export class CommandCenter {
14411441
return false;
14421442
}
14431443

1444+
if (opts.noVerify) {
1445+
if (!config.get<boolean>('allowNoVerifyCommit')) {
1446+
await window.showErrorMessage(localize('no verify commit not allowed', "Commits without verification are not allowed, please enable them with the 'git.allowNoVerifyCommit' setting."));
1447+
return false;
1448+
}
1449+
1450+
if (config.get<boolean>('confirmNoVerifyCommit')) {
1451+
const message = localize('confirm no verify commit', "You are about to commit your changes without verification, this skips pre-commit hooks and can be undesirable.\n\nAre you sure to continue?");
1452+
const yes = localize('ok', "OK");
1453+
const neverAgain = localize('never ask again', "OK, Don't Ask Again");
1454+
const pick = await window.showWarningMessage(message, { modal: true }, yes, neverAgain);
1455+
1456+
if (pick === neverAgain) {
1457+
config.update('confirmNoVerifyCommit', false, true);
1458+
} else if (pick !== yes) {
1459+
return false;
1460+
}
1461+
}
1462+
}
1463+
14441464
const message = await getCommitMessage();
14451465

14461466
if (!message) {
@@ -1545,8 +1565,7 @@ export class CommandCenter {
15451565
await this.commitWithAnyInput(repository, { all: true, amend: true });
15461566
}
15471567

1548-
@command('git.commitEmpty', { repository: true })
1549-
async commitEmpty(repository: Repository): Promise<void> {
1568+
private async _commitEmpty(repository: Repository, noVerify?: boolean): Promise<void> {
15501569
const root = Uri.file(repository.root);
15511570
const config = workspace.getConfiguration('git', root);
15521571
const shouldPrompt = config.get<boolean>('confirmEmptyCommits') === true;
@@ -1564,7 +1583,52 @@ export class CommandCenter {
15641583
}
15651584
}
15661585

1567-
await this.commitWithAnyInput(repository, { empty: true });
1586+
await this.commitWithAnyInput(repository, { empty: true, noVerify });
1587+
}
1588+
1589+
@command('git.commitEmpty', { repository: true })
1590+
async commitEmpty(repository: Repository): Promise<void> {
1591+
await this._commitEmpty(repository);
1592+
}
1593+
1594+
@command('git.commitNoVerify', { repository: true })
1595+
async commitNoVerify(repository: Repository): Promise<void> {
1596+
await this.commitWithAnyInput(repository, { noVerify: true });
1597+
}
1598+
1599+
@command('git.commitStagedNoVerify', { repository: true })
1600+
async commitStagedNoVerify(repository: Repository): Promise<void> {
1601+
await this.commitWithAnyInput(repository, { all: false, noVerify: true });
1602+
}
1603+
1604+
@command('git.commitStagedSignedNoVerify', { repository: true })
1605+
async commitStagedSignedNoVerify(repository: Repository): Promise<void> {
1606+
await this.commitWithAnyInput(repository, { all: false, signoff: true, noVerify: true });
1607+
}
1608+
1609+
@command('git.commitStagedAmendNoVerify', { repository: true })
1610+
async commitStagedAmendNoVerify(repository: Repository): Promise<void> {
1611+
await this.commitWithAnyInput(repository, { all: false, amend: true, noVerify: true });
1612+
}
1613+
1614+
@command('git.commitAllNoVerify', { repository: true })
1615+
async commitAllNoVerify(repository: Repository): Promise<void> {
1616+
await this.commitWithAnyInput(repository, { all: true, noVerify: true });
1617+
}
1618+
1619+
@command('git.commitAllSignedNoVerify', { repository: true })
1620+
async commitAllSignedNoVerify(repository: Repository): Promise<void> {
1621+
await this.commitWithAnyInput(repository, { all: true, signoff: true, noVerify: true });
1622+
}
1623+
1624+
@command('git.commitAllAmendNoVerify', { repository: true })
1625+
async commitAllAmendNoVerify(repository: Repository): Promise<void> {
1626+
await this.commitWithAnyInput(repository, { all: true, amend: true, noVerify: true });
1627+
}
1628+
1629+
@command('git.commitEmptyNoVerify', { repository: true })
1630+
async commitEmptyNoVerify(repository: Repository): Promise<void> {
1631+
await this._commitEmpty(repository, true);
15681632
}
15691633

15701634
@command('git.restoreCommitTemplate', { repository: true })

extensions/git/src/git.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1322,10 +1322,15 @@ export class Repository {
13221322
if (opts.signCommit) {
13231323
args.push('-S');
13241324
}
1325+
13251326
if (opts.empty) {
13261327
args.push('--allow-empty');
13271328
}
13281329

1330+
if (opts.noVerify) {
1331+
args.push('--no-verify');
1332+
}
1333+
13291334
try {
13301335
await this.run(args, { input: message || '' });
13311336
} catch (commitErr) {

0 commit comments

Comments
 (0)