diff --git a/extensions/git/package.json b/extensions/git/package.json index fc31b690132..d011417e460 100644 --- a/extensions/git/package.json +++ b/extensions/git/package.json @@ -190,6 +190,11 @@ "title": "%command.commitStaged%", "category": "Git" }, + { + "command": "git.commitEmpty", + "title": "%command.commitEmpty%", + "category": "Git" + }, { "command": "git.commitStagedSigned", "title": "%command.commitStagedSigned%", @@ -417,6 +422,10 @@ "command": "git.commit", "when": "config.git.enabled && gitOpenRepositoryCount != 0" }, + { + "command": "git.commitEmpty", + "when": "config.git.allowcommitEmptys && gitOpenRepositoryCount != 0" + }, { "command": "git.commitStaged", "when": "config.git.enabled && gitOpenRepositoryCount != 0" @@ -599,6 +608,11 @@ "group": "3_commit", "when": "scmProvider == git" }, + { + "command": "git.commitEmpty", + "group": "3_commit", + "when": "scmProvider == git" + }, { "command": "git.commitStagedSigned", "group": "3_commit", @@ -991,6 +1005,12 @@ "description": "%config.enableCommitSigning%", "default": false }, + "git.allowEmptyCommits": { + "type": "boolean", + "scope": "resource", + "description": "%config.allowEmptyCommits%", + "default": false + }, "git.decorations.enabled": { "type": "boolean", "default": true, diff --git a/extensions/git/package.nls.json b/extensions/git/package.nls.json index b3991f94b5c..14f7f671e27 100644 --- a/extensions/git/package.nls.json +++ b/extensions/git/package.nls.json @@ -22,6 +22,7 @@ "command.cleanAll": "Discard All Changes", "command.commit": "Commit", "command.commitStaged": "Commit Staged", + "command.commitEmpty": "Commit Empty", "command.commitStagedSigned": "Commit Staged (Signed Off)", "command.commitStagedAmend": "Commit Staged (Amend)", "command.commitAll": "Commit All", diff --git a/extensions/git/src/commands.ts b/extensions/git/src/commands.ts index 0a2f7e22481..948cb1a2f5d 100644 --- a/extensions/git/src/commands.ts +++ b/extensions/git/src/commands.ts @@ -1086,10 +1086,13 @@ export class CommandCenter { } if ( + ( // no changes (noStagedChanges && noUnstagedChanges) // or no staged changes and not `all` || (!opts.all && noStagedChanges) + ) + && !opts.empty ) { window.showInformationMessage(localize('no changes', "There are no changes to commit.")); return false; @@ -1134,6 +1137,11 @@ export class CommandCenter { } } + @command('git.commitEmpty', { repository: true}) + async commit(repository: Repository): Promise { + await this.commitWithAnyInput(repository, { empty: true }); + } + @command('git.commit', { repository: true }) async commit(repository: Repository): Promise { await this.commitWithAnyInput(repository); diff --git a/extensions/git/src/git.ts b/extensions/git/src/git.ts index d678cd3b03d..97f76b8e844 100644 --- a/extensions/git/src/git.ts +++ b/extensions/git/src/git.ts @@ -958,6 +958,9 @@ export class Repository { if (opts.signCommit) { args.push('-S'); } + if (opts.empty) { + args.push('--allow-empty'); + } try { await this.run(args, { input: message || '' }); diff --git a/extensions/git/src/repository.ts b/extensions/git/src/repository.ts index 45c139c1e21..0e11466c688 100644 --- a/extensions/git/src/repository.ts +++ b/extensions/git/src/repository.ts @@ -395,6 +395,7 @@ export interface CommitOptions { amend?: boolean; signoff?: boolean; signCommit?: boolean; + empty?: boolean; } export interface GitResourceGroup extends SourceControlResourceGroup {