diff --git a/extensions/git/package.json b/extensions/git/package.json index 1fd7cc8e15f..9c3aad52bfa 100644 --- a/extensions/git/package.json +++ b/extensions/git/package.json @@ -397,6 +397,11 @@ "description": "%config.enableLongCommitWarning%", "default": true }, + "git.confirmSync": { + "type": "boolean", + "description": "%config.confirmSync%", + "default": true + }, "git.countBadge": { "type": "string", "enum": [ diff --git a/extensions/git/package.nls.json b/extensions/git/package.nls.json index 825ab65f516..2dced4cba91 100644 --- a/extensions/git/package.nls.json +++ b/extensions/git/package.nls.json @@ -27,6 +27,7 @@ "config.autorefresh": "Whether auto refreshing is enabled", "config.autofetch": "Whether auto fetching is enabled", "config.enableLongCommitWarning": "Whether long commit messages should be warned about", + "config.confirmSync": "Confirm before synchronizing git repositories", "config.countBadge": "Controls the git badge counter", "config.checkoutType": "Controls what type of branches are listed" } \ No newline at end of file diff --git a/extensions/git/src/commands.ts b/extensions/git/src/commands.ts index 6eb416100aa..ad18da5d32e 100644 --- a/extensions/git/src/commands.ts +++ b/extensions/git/src/commands.ts @@ -461,6 +461,28 @@ export class CommandCenter { @CommandCenter.Command('git.sync') @CommandCenter.CatchErrors async sync(): Promise { + const HEAD = this.model.HEAD; + + if (!HEAD || !HEAD.upstream) { + return; + } + + const config = workspace.getConfiguration('git'); + const shouldPrompt = config.get('confirmSync') === true; + + if (shouldPrompt) { + const message = localize('sync is unpredictable', "This action will push and pull commits to and from '{0}'.", HEAD.upstream); + const yes = localize('ok', "OK"); + const neverAgain = localize('never again', "OK, Never Show Again"); + const pick = await window.showWarningMessage(message, { modal: true }, yes, neverAgain); + + if (pick === neverAgain) { + await config.update('confirmSync', false, true); + } else if (pick !== yes) { + return; + } + } + await this.model.sync(); }