From 3cfd86034464cf2526b5ef5b20da2f1e05fac933 Mon Sep 17 00:00:00 2001 From: Phil Marshall Date: Tue, 15 Jan 2019 19:58:07 -0600 Subject: [PATCH 1/4] git prompts to save only staged files --- extensions/git/src/commands.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/extensions/git/src/commands.ts b/extensions/git/src/commands.ts index eb45f107f4b..26685a0afa3 100755 --- a/extensions/git/src/commands.ts +++ b/extensions/git/src/commands.ts @@ -1200,19 +1200,21 @@ export class CommandCenter { const promptToSaveFilesBeforeCommit = config.get('promptToSaveFilesBeforeCommit') === true; if (promptToSaveFilesBeforeCommit) { - const unsavedTextDocuments = workspace.textDocuments - .filter(d => !d.isUntitled && d.isDirty && isDescendant(repository.root, d.uri.fsPath)); + const stagedUnsavedTextDocuments = 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)); - if (unsavedTextDocuments.length > 0) { - const message = unsavedTextDocuments.length === 1 - ? localize('unsaved files single', "The following file is unsaved: {0}.\n\nWould you like to save it before committing?", path.basename(unsavedTextDocuments[0].uri.fsPath)) - : localize('unsaved files', "There are {0} unsaved files.\n\nWould you like to save them before committing?", unsavedTextDocuments.length); + if (stagedUnsavedTextDocuments.length > 0) { + const message = stagedUnsavedTextDocuments.length === 1 + ? localize('unsaved files single', "The following file is unsaved: {0}.\n\nWould you like to save it before committing?", path.basename(stagedUnsavedTextDocuments[0].uri.fsPath)) + : localize('unsaved files', "There are {0} unsaved files.\n\nWould you like to save them before committing?", stagedUnsavedTextDocuments.length); const saveAndCommit = localize('save and commit', "Save All & Commit"); const commit = localize('commit', "Commit Anyway"); const pick = await window.showWarningMessage(message, { modal: true }, saveAndCommit, commit); if (pick === saveAndCommit) { - await Promise.all(unsavedTextDocuments.map(d => d.save())); + await Promise.all(stagedUnsavedTextDocuments.map(d => d.save())); await repository.status(); } else if (pick !== commit) { return false; // do not commit on cancel From 957f809e4dd54bc85620fa5e480465c2b38d9a5b Mon Sep 17 00:00:00 2001 From: Phil Marshall Date: Wed, 16 Jan 2019 00:18:15 -0600 Subject: [PATCH 2/4] update strings for prompt to save staged files --- extensions/git/src/commands.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/extensions/git/src/commands.ts b/extensions/git/src/commands.ts index 26685a0afa3..14a3e8b2cf8 100755 --- a/extensions/git/src/commands.ts +++ b/extensions/git/src/commands.ts @@ -1207,8 +1207,8 @@ export class CommandCenter { if (stagedUnsavedTextDocuments.length > 0) { const message = stagedUnsavedTextDocuments.length === 1 - ? localize('unsaved files single', "The following file is unsaved: {0}.\n\nWould you like to save it before committing?", path.basename(stagedUnsavedTextDocuments[0].uri.fsPath)) - : localize('unsaved files', "There are {0} unsaved files.\n\nWould you like to save them before committing?", stagedUnsavedTextDocuments.length); + ? localize('unsaved files single', "The following staged file is unsaved: {0}.\n\nWould you like to save it before committing?", path.basename(stagedUnsavedTextDocuments[0].uri.fsPath)) + : localize('unsaved files', "There are {0} unsaved staged files.\n\nWould you like to save them before committing?", stagedUnsavedTextDocuments.length); const saveAndCommit = localize('save and commit', "Save All & Commit"); const commit = localize('commit', "Commit Anyway"); const pick = await window.showWarningMessage(message, { modal: true }, saveAndCommit, commit); From f7fd6b34ba78cf611501a8ca4f768b0c6e3076d0 Mon Sep 17 00:00:00 2001 From: Joao Moreno Date: Thu, 8 Aug 2019 11:22:52 +0200 Subject: [PATCH 3/4] git: improve promptToSaveFilesBeforeCommit message --- extensions/git/src/commands.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/git/src/commands.ts b/extensions/git/src/commands.ts index 3ff6be64541..2cdd0ebe8ff 100755 --- a/extensions/git/src/commands.ts +++ b/extensions/git/src/commands.ts @@ -1242,7 +1242,7 @@ export class CommandCenter { if (documents.length > 0) { const message = documents.length === 1 - ? localize('unsaved files single', "The following staged file is unsaved: {0}.\n\nWould you like to save it before committing?", path.basename(documents[0].uri.fsPath)) + ? localize('unsaved files single', "The following staged file is unsaved and will not be included in the commit if you proceed: {0}.\n\nWould you like to save it before committing?", path.basename(documents[0].uri.fsPath)) : localize('unsaved files', "There are {0} unsaved staged files.\n\nWould you like to save them before committing?", documents.length); const saveAndCommit = localize('save and commit', "Save All & Commit"); const commit = localize('commit', "Commit Anyway"); From fa5c79386cb6052d3321755ca3ccd3785d223f96 Mon Sep 17 00:00:00 2001 From: Joao Moreno Date: Thu, 8 Aug 2019 11:30:25 +0200 Subject: [PATCH 4/4] git: promptToSaveFilesBeforeCommit should have more options related to #66296 --- extensions/git/package.json | 14 ++++++++++++-- extensions/git/package.nls.json | 3 +++ extensions/git/src/commands.ts | 21 ++++++++++++++++----- 3 files changed, 31 insertions(+), 7 deletions(-) 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