Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds commands for --no-verify commit variants #106335

Merged
merged 5 commits into from
Sep 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 119 additions & 1 deletion extensions/git/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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%",
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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",
Expand All @@ -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": [
Expand Down Expand Up @@ -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",
Expand Down
10 changes: 10 additions & 0 deletions extensions/git/package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -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...",
Expand Down Expand Up @@ -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.",
Expand Down
1 change: 1 addition & 0 deletions extensions/git/src/api/git.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ export interface CommitOptions {
signoff?: boolean;
signCommit?: boolean;
empty?: boolean;
noVerify?: boolean;
}

export interface BranchQuery {
Expand Down
70 changes: 67 additions & 3 deletions extensions/git/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1435,6 +1435,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) {
Expand Down Expand Up @@ -1539,8 +1559,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;
Expand All @@ -1558,7 +1577,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 })
Expand Down
5 changes: 5 additions & 0 deletions extensions/git/src/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down