diff --git a/extensions/git/package.json b/extensions/git/package.json index 9bbce1ea371..2a47e2dc209 100644 --- a/extensions/git/package.json +++ b/extensions/git/package.json @@ -613,6 +613,11 @@ "type": "string", "default": null, "description": "%config.defaultCloneDirectory%" + }, + "git.enableSmartCommit": { + "type": "boolean", + "description": "%config.enableSmartCommit%", + "default": false } } } diff --git a/extensions/git/package.nls.json b/extensions/git/package.nls.json index 81188ab18a3..efdde34dd7a 100644 --- a/extensions/git/package.nls.json +++ b/extensions/git/package.nls.json @@ -38,5 +38,6 @@ "config.checkoutType": "Controls what type of branches are listed when running `Checkout to...`. `all` shows all refs, `local` shows only the local branchs, `tags` shows only tags and `remote` shows only remote branches.", "config.ignoreLegacyWarning": "Ignores the legacy Git warning", "config.ignoreLimitWarning": "Ignores the warning when there are too many changes in a repository", - "config.defaultCloneDirectory": "The default location where to clone a git repository" + "config.defaultCloneDirectory": "The default location where to clone a git repository", + "config.enableSmartCommit": "Commit all changes when there are not staged changes." } \ No newline at end of file diff --git a/extensions/git/src/commands.ts b/extensions/git/src/commands.ts index 5f2ea323c1c..6aa35dae3df 100644 --- a/extensions/git/src/commands.ts +++ b/extensions/git/src/commands.ts @@ -533,15 +533,40 @@ export class CommandCenter { getCommitMessage: () => Promise, opts?: CommitOptions ): Promise { + const config = workspace.getConfiguration('git'); + const enableSmartCommit = config.get('enableSmartCommit') === true; + const noStagedChanges = this.model.indexGroup.resources.length === 0; + const noUnstagedChanges = this.model.workingTreeGroup.resources.length === 0; + + // no changes, and the user has not configured to commit all in this case + if (!noUnstagedChanges && noStagedChanges && !enableSmartCommit) { + // prompt the user if we want to commit all or not + + const message = localize('no staged changes', "There are no staged changes to commit. Would you like to stage all changes and commit them?"); + const yes = localize('yes', "Yes"); + const always = localize('always', "Always"); + const pick = await window.showWarningMessage(message, { modal: true }, yes, always); + + if (pick === always) { + // update preference to enable smart commit always + config.update('enableSmartCommit', true, false); + } + else if (pick !== yes) { + // do not commit on cancel + return false; + } + // for yes or always, continue onto previous smart commit behavior + } + if (!opts) { - opts = { all: this.model.indexGroup.resources.length === 0 }; + opts = { all: noStagedChanges }; } if ( // no changes - (this.model.indexGroup.resources.length === 0 && this.model.workingTreeGroup.resources.length === 0) + (noStagedChanges && noUnstagedChanges) // or no staged changes and not `all` - || (!opts.all && this.model.indexGroup.resources.length === 0) + || (!opts.all && noStagedChanges) ) { window.showInformationMessage(localize('no changes', "There are no changes to commit.")); return false;