From 3085d3ebd761e293f6a67340924b6a2ab8cc174e Mon Sep 17 00:00:00 2001 From: Harjyot Singh Date: Wed, 26 Jul 2017 03:36:26 +0530 Subject: [PATCH] Command added --- extensions/git/package.json | 14 ++++++++++++++ extensions/git/package.nls.json | 1 + extensions/git/src/commands.ts | 26 ++++++++++++++++++++++++++ extensions/git/src/model.ts | 13 +++++++++++++ 4 files changed, 54 insertions(+) diff --git a/extensions/git/package.json b/extensions/git/package.json index bf8fe767cdf..87ff2d14a19 100644 --- a/extensions/git/package.json +++ b/extensions/git/package.json @@ -217,6 +217,11 @@ "title": "%command.sync%", "category": "Git" }, + { + "command": "git.syncRebase", + "title": "%command.syncRebase%", + "category": "Git" + }, { "command": "git.publish", "title": "%command.publish%", @@ -359,6 +364,10 @@ "command": "git.sync", "when": "config.git.enabled && scmProvider == git && gitState == idle" }, + { + "command": "git.syncRebase", + "when": "config.git.enabled && scmProvider == git && gitState == idle" + }, { "command": "git.publish", "when": "config.git.enabled && scmProvider == git && gitState == idle" @@ -389,6 +398,11 @@ "group": "1_sync", "when": "config.git.enabled && scmProvider == git && gitState == idle" }, + { + "command": "git.syncRebase", + "group": "1_sync", + "when": "config.git.enabled && scmProvider == git && gitState == idle" + }, { "command": "git.pull", "group": "1_sync", diff --git a/extensions/git/package.nls.json b/extensions/git/package.nls.json index bc8bc381786..de74d50440d 100644 --- a/extensions/git/package.nls.json +++ b/extensions/git/package.nls.json @@ -30,6 +30,7 @@ "command.push": "Push", "command.pushTo": "Push to...", "command.sync": "Sync", + "command.syncRebase": "Sync (Rebase)", "command.publish": "Publish Branch", "command.showOutput": "Show Git Output", "command.ignore": "Add File to .gitignore", diff --git a/extensions/git/src/commands.ts b/extensions/git/src/commands.ts index 31f4fcf408a..09026aa255e 100644 --- a/extensions/git/src/commands.ts +++ b/extensions/git/src/commands.ts @@ -956,6 +956,32 @@ export class CommandCenter { await this.model.sync(); } + @command('git.syncRebase') + async syncRebase(): 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.syncRebase(); + } + @command('git.publish') async publish(): Promise { const remotes = this.model.remotes; diff --git a/extensions/git/src/model.ts b/extensions/git/src/model.ts index 7d852bc8a39..90a8346de6e 100644 --- a/extensions/git/src/model.ts +++ b/extensions/git/src/model.ts @@ -522,6 +522,19 @@ export class Model implements Disposable { }); } + @throttle + async syncRebase(): Promise { + await this.run(Operation.Sync, async () => { + await this.repository.pull(true); + + const shouldPush = this.HEAD && typeof this.HEAD.ahead === 'number' ? this.HEAD.ahead > 0 : true; + + if (shouldPush) { + await this.repository.push(); + } + }); + } + async show(ref: string, filePath: string): Promise { return await this.run(Operation.Show, async () => { const relativePath = path.relative(this.repository.root, filePath).replace(/\\/g, '/');