Adds commands for --no-verify commit variants (#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
This commit is contained in:
Vyacheslav Pukhanov 2020-09-10 12:14:28 +03:00 committed by GitHub
parent 82d953a731
commit 663810e275
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 202 additions and 4 deletions

View file

@ -216,6 +216,47 @@
"title": "%command.commitAllAmend%",
"category": "Git"
},
{
"command": "git.commitNoVerify",
"title": "%command.commitNoVerify%",
"category": "Git",
"icon": "$(check)"
},
{
"command": "git.commitStagedNoVerify",
"title": "%command.commitStagedNoVerify%",
"category": "Git"
},
{
"command": "git.commitEmptyNoVerify",
"title": "%command.commitEmptyNoVerify%",
"category": "Git"
},
{
"command": "git.commitStagedSignedNoVerify",
"title": "%command.commitStagedSignedNoVerify%",
"category": "Git"
},
{
"command": "git.commitStagedAmendNoVerify",
"title": "%command.commitStagedAmendNoVerify%",
"category": "Git"
},
{
"command": "git.commitAllNoVerify",
"title": "%command.commitAllNoVerify%",
"category": "Git"
},
{
"command": "git.commitAllSignedNoVerify",
"title": "%command.commitAllSignedNoVerify%",
"category": "Git"
},
{
"command": "git.commitAllAmendNoVerify",
"title": "%command.commitAllAmendNoVerify%",
"category": "Git"
},
{
"command": "git.restoreCommitTemplate",
"title": "%command.restoreCommitTemplate%",
@ -581,6 +622,38 @@
"command": "git.commitAllAmend",
"when": "config.git.enabled && !git.missing && gitOpenRepositoryCount != 0"
},
{
"command": "git.commitNoVerify",
"when": "config.git.enabled && !git.missing && config.git.allowNoVerifyCommit && gitOpenRepositoryCount != 0"
},
{
"command": "git.commitStagedNoVerify",
"when": "config.git.enabled && !git.missing && config.git.allowNoVerifyCommit && gitOpenRepositoryCount != 0"
},
{
"command": "git.commitEmptyNoVerify",
"when": "config.git.enabled && !git.missing && config.git.allowNoVerifyCommit && gitOpenRepositoryCount != 0"
},
{
"command": "git.commitStagedSignedNoVerify",
"when": "config.git.enabled && !git.missing && config.git.allowNoVerifyCommit && gitOpenRepositoryCount != 0"
},
{
"command": "git.commitStagedAmendNoVerify",
"when": "config.git.enabled && !git.missing && config.git.allowNoVerifyCommit && gitOpenRepositoryCount != 0"
},
{
"command": "git.commitAllNoVerify",
"when": "config.git.enabled && !git.missing && config.git.allowNoVerifyCommit && gitOpenRepositoryCount != 0"
},
{
"command": "git.commitAllSignedNoVerify",
"when": "config.git.enabled && !git.missing && config.git.allowNoVerifyCommit && gitOpenRepositoryCount != 0"
},
{
"command": "git.commitAllAmendNoVerify",
"when": "config.git.enabled && !git.missing && config.git.allowNoVerifyCommit && gitOpenRepositoryCount != 0"
},
{
"command": "git.restoreCommitTemplate",
"when": "false"
@ -1239,13 +1312,38 @@
"command": "git.rebaseAbort",
"group": "1_commit@5"
},
{
"command": "git.commitNoVerify",
"group": "1_commit@6",
"when": "config.git.allowNoVerifyCommit"
},
{
"command": "git.commitStagedNoVerify",
"group": "1_commit@7",
"when": "config.git.allowNoVerifyCommit"
},
{
"command": "git.commitAllNoVerify",
"group": "1_commit@8",
"when": "config.git.allowNoVerifyCommit"
},
{
"command": "git.commitStagedAmend",
"group": "2_amend@1"
},
{
"command": "git.commitAllAmend",
"group": "2_amend@1"
"group": "2_amend@2"
},
{
"command": "git.commitStagedAmendNoVerify",
"group": "2_amend@3",
"when": "config.git.allowNoVerifyCommit"
},
{
"command": "git.commitAllAmendNoVerify",
"group": "2_amend@4",
"when": "config.git.allowNoVerifyCommit"
},
{
"command": "git.commitStagedSigned",
@ -1254,6 +1352,16 @@
{
"command": "git.commitAllSigned",
"group": "3_signoff@2"
},
{
"command": "git.commitStagedSignedNoVerify",
"group": "3_signoff@3",
"when": "config.git.allowNoVerifyCommit"
},
{
"command": "git.commitAllSignedNoVerify",
"group": "3_signoff@4",
"when": "config.git.allowNoVerifyCommit"
}
],
"git.changes": [
@ -1730,6 +1838,16 @@
"default": true,
"description": "%config.confirmForcePush%"
},
"git.allowNoVerifyCommit": {
"type": "boolean",
"default": false,
"description": "%config.allowNoVerifyCommit%"
},
"git.confirmNoVerifyCommit": {
"type": "boolean",
"default": true,
"description": "%config.confirmNoVerifyCommit%"
},
"git.openDiffOnClick": {
"type": "boolean",
"scope": "resource",

View file

@ -34,6 +34,14 @@
"command.commitAll": "Commit All",
"command.commitAllSigned": "Commit All (Signed Off)",
"command.commitAllAmend": "Commit All (Amend)",
"command.commitNoVerify": "Commit (No Nerify)",
"command.commitStagedNoVerify": "Commit Staged (No Verify)",
"command.commitEmptyNoVerify": "Commit Empty (No Verify)",
"command.commitStagedSignedNoVerify": "Commit Staged (Signed Off, No Verify)",
"command.commitStagedAmendNoVerify": "Commit Staged (Amend, No Verify)",
"command.commitAllNoVerify": "Commit All (No Verify)",
"command.commitAllSignedNoVerify": "Commit All (Signed Off, No Verify)",
"command.commitAllAmendNoVerify": "Commit All (Amend, No Verify)",
"command.restoreCommitTemplate": "Restore Commit Template",
"command.undoCommit": "Undo Last Commit",
"command.checkout": "Checkout to...",
@ -139,6 +147,8 @@
"config.allowForcePush": "Controls whether force push (with or without lease) is enabled.",
"config.useForcePushWithLease": "Controls whether force pushing uses the safer force-with-lease variant.",
"config.confirmForcePush": "Controls whether to ask for confirmation before force-pushing.",
"config.allowNoVerifyCommit": "Controls whether commits without running pre-commit and commit-msg hooks are allowed.",
"config.confirmNoVerifyCommit": "Controls whether to ask for confirmation before commiting without verification.",
"config.openDiffOnClick": "Controls whether the diff editor should be opened when clicking a change. Otherwise the regular editor will be opened.",
"config.supportCancellation": "Controls whether a notification comes up when running the Sync action, which allows the user to cancel the operation.",
"config.branchSortOrder": "Controls the sort order for branches.",

View file

@ -130,6 +130,7 @@ export interface CommitOptions {
signoff?: boolean;
signCommit?: boolean;
empty?: boolean;
noVerify?: boolean;
}
export interface BranchQuery {

View file

@ -1441,6 +1441,26 @@ export class CommandCenter {
return false;
}
if (opts.noVerify) {
if (!config.get<boolean>('allowNoVerifyCommit')) {
await window.showErrorMessage(localize('no verify commit not allowed', "Commits without verification are not allowed, please enable them with the 'git.allowNoVerifyCommit' setting."));
return false;
}
if (config.get<boolean>('confirmNoVerifyCommit')) {
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?");
const yes = localize('ok', "OK");
const neverAgain = localize('never ask again', "OK, Don't Ask Again");
const pick = await window.showWarningMessage(message, { modal: true }, yes, neverAgain);
if (pick === neverAgain) {
config.update('confirmNoVerifyCommit', false, true);
} else if (pick !== yes) {
return false;
}
}
}
const message = await getCommitMessage();
if (!message) {
@ -1545,8 +1565,7 @@ export class CommandCenter {
await this.commitWithAnyInput(repository, { all: true, amend: true });
}
@command('git.commitEmpty', { repository: true })
async commitEmpty(repository: Repository): Promise<void> {
private async _commitEmpty(repository: Repository, noVerify?: boolean): Promise<void> {
const root = Uri.file(repository.root);
const config = workspace.getConfiguration('git', root);
const shouldPrompt = config.get<boolean>('confirmEmptyCommits') === true;
@ -1564,7 +1583,52 @@ export class CommandCenter {
}
}
await this.commitWithAnyInput(repository, { empty: true });
await this.commitWithAnyInput(repository, { empty: true, noVerify });
}
@command('git.commitEmpty', { repository: true })
async commitEmpty(repository: Repository): Promise<void> {
await this._commitEmpty(repository);
}
@command('git.commitNoVerify', { repository: true })
async commitNoVerify(repository: Repository): Promise<void> {
await this.commitWithAnyInput(repository, { noVerify: true });
}
@command('git.commitStagedNoVerify', { repository: true })
async commitStagedNoVerify(repository: Repository): Promise<void> {
await this.commitWithAnyInput(repository, { all: false, noVerify: true });
}
@command('git.commitStagedSignedNoVerify', { repository: true })
async commitStagedSignedNoVerify(repository: Repository): Promise<void> {
await this.commitWithAnyInput(repository, { all: false, signoff: true, noVerify: true });
}
@command('git.commitStagedAmendNoVerify', { repository: true })
async commitStagedAmendNoVerify(repository: Repository): Promise<void> {
await this.commitWithAnyInput(repository, { all: false, amend: true, noVerify: true });
}
@command('git.commitAllNoVerify', { repository: true })
async commitAllNoVerify(repository: Repository): Promise<void> {
await this.commitWithAnyInput(repository, { all: true, noVerify: true });
}
@command('git.commitAllSignedNoVerify', { repository: true })
async commitAllSignedNoVerify(repository: Repository): Promise<void> {
await this.commitWithAnyInput(repository, { all: true, signoff: true, noVerify: true });
}
@command('git.commitAllAmendNoVerify', { repository: true })
async commitAllAmendNoVerify(repository: Repository): Promise<void> {
await this.commitWithAnyInput(repository, { all: true, amend: true, noVerify: true });
}
@command('git.commitEmptyNoVerify', { repository: true })
async commitEmptyNoVerify(repository: Repository): Promise<void> {
await this._commitEmpty(repository, true);
}
@command('git.restoreCommitTemplate', { repository: true })

View file

@ -1322,10 +1322,15 @@ export class Repository {
if (opts.signCommit) {
args.push('-S');
}
if (opts.empty) {
args.push('--allow-empty');
}
if (opts.noVerify) {
args.push('--no-verify');
}
try {
await this.run(args, { input: message || '' });
} catch (commitErr) {