diff --git a/extensions/git/package.json b/extensions/git/package.json index 90064509397..aba696781b6 100644 --- a/extensions/git/package.json +++ b/extensions/git/package.json @@ -1172,9 +1172,19 @@ "description": "%config.decorations.enabled%" }, "git.promptToSaveFilesBeforeCommit": { - "type": "boolean", + "type": "string", + "enum": [ + "always", + "staged", + "never" + ], + "enumDescriptions": [ + "%config.promptToSaveFilesBeforeCommit.always%", + "%config.promptToSaveFilesBeforeCommit.staged%", + "%config.promptToSaveFilesBeforeCommit.never%" + ], "scope": "resource", - "default": true, + "default": "always", "description": "%config.promptToSaveFilesBeforeCommit%" }, "git.postCommitCommand": { diff --git a/extensions/git/package.nls.json b/extensions/git/package.nls.json index 4d8bccf4e0b..cddbdad605e 100644 --- a/extensions/git/package.nls.json +++ b/extensions/git/package.nls.json @@ -94,6 +94,9 @@ "config.discardAllScope": "Controls what changes are discarded by the `Discard all changes` command. `all` discards all changes. `tracked` discards only tracked files. `prompt` shows a prompt dialog every time the action is run.", "config.decorations.enabled": "Controls whether Git contributes colors and badges to the explorer and the open editors view.", "config.promptToSaveFilesBeforeCommit": "Controls whether Git should check for unsaved files before committing.", + "config.promptToSaveFilesBeforeCommit.always": "Check for any unsaved files.", + "config.promptToSaveFilesBeforeCommit.staged": "Check only for unsaved staged files.", + "config.promptToSaveFilesBeforeCommit.never": "Disable this check.", "config.postCommitCommand": "Runs a git command after a successful commit.", "config.postCommitCommand.none": "Don't run any command after a commit.", "config.postCommitCommand.push": "Run 'Git Push' after a successful commit.", diff --git a/extensions/git/src/commands.ts b/extensions/git/src/commands.ts index 2cdd0ebe8ff..39b48f2c5e9 100755 --- a/extensions/git/src/commands.ts +++ b/extensions/git/src/commands.ts @@ -1233,12 +1233,23 @@ export class CommandCenter { opts?: CommitOptions ): Promise { const config = workspace.getConfiguration('git', Uri.file(repository.root)); - const promptToSaveFilesBeforeCommit = config.get('promptToSaveFilesBeforeCommit') === true; + let promptToSaveFilesBeforeCommit = config.get<'always' | 'staged' | 'never'>('promptToSaveFilesBeforeCommit'); - if (promptToSaveFilesBeforeCommit) { - const documents = workspace.textDocuments - .filter(d => !d.isUntitled && d.isDirty && isDescendant(repository.root, d.uri.fsPath)) - .filter(d => repository.indexGroup.resourceStates.some(s => s.resourceUri.path === d.uri.fsPath)); + // migration + if (promptToSaveFilesBeforeCommit as any === true) { + promptToSaveFilesBeforeCommit = 'always'; + } else if (promptToSaveFilesBeforeCommit as any === false) { + promptToSaveFilesBeforeCommit = 'never'; + } + + if (promptToSaveFilesBeforeCommit !== 'never') { + let documents = workspace.textDocuments + .filter(d => !d.isUntitled && d.isDirty && isDescendant(repository.root, d.uri.fsPath)); + + if (promptToSaveFilesBeforeCommit === 'staged') { + documents = documents + .filter(d => repository.indexGroup.resourceStates.some(s => s.resourceUri.path === d.uri.fsPath)); + } if (documents.length > 0) { const message = documents.length === 1