From 91ec2ba0402bfe9a1c1ab3b323f24ab9917ea464 Mon Sep 17 00:00:00 2001 From: Joao Moreno Date: Thu, 3 Dec 2015 09:59:39 +0100 Subject: [PATCH] git pull with rebase fixes #907 related to #150 --- .../workbench/parts/git/browser/gitActions.ts | 29 +++++++++++++++++-- .../parts/git/browser/gitServices.ts | 4 +-- .../git/browser/views/changes/changesView.ts | 3 +- src/vs/workbench/parts/git/common/git.ts | 4 +-- .../parts/git/common/noopGitService.ts | 2 +- src/vs/workbench/parts/git/node/git.lib.ts | 7 +++-- .../workbench/parts/git/node/rawGitService.ts | 8 ++--- 7 files changed, 42 insertions(+), 15 deletions(-) diff --git a/src/vs/workbench/parts/git/browser/gitActions.ts b/src/vs/workbench/parts/git/browser/gitActions.ts index 729ca7ae817..57cb5219e20 100644 --- a/src/vs/workbench/parts/git/browser/gitActions.ts +++ b/src/vs/workbench/parts/git/browser/gitActions.ts @@ -819,9 +819,14 @@ export class SmartCommitAction extends BaseCommitAction { export class PullAction extends GitAction { static ID = 'workbench.action.pull'; + static LABEL = nls.localize('pull', "Pull"); - constructor(@IGitService gitService: IGitService) { - super(PullAction.ID, nls.localize('pull', "Pull"), 'git-action pull', gitService); + constructor( + id = PullAction.ID, + label = PullAction.LABEL, + @IGitService gitService: IGitService + ) { + super(id, label, 'git-action pull', gitService); } protected isEnabled():boolean { @@ -844,7 +849,11 @@ export class PullAction extends GitAction { } public run(context?: any):Promise { - return this.gitService.pull().then(null, (err) => { + return this.pull(); + } + + protected pull(rebase = false): Promise { + return this.gitService.pull(rebase).then(null, (err) => { if (err.gitErrorCode === GitErrorCodes.DirtyWorkTree) { return Promise.wrapError(errors.create(nls.localize('dirtyTreePull', "Can't pull. Please commit or stage your work first."), { severity: Severity.Warning })); } else if (err.gitErrorCode === GitErrorCodes.AuthenticationFailed) { @@ -856,6 +865,20 @@ export class PullAction extends GitAction { } } +export class PullWithRebaseAction extends PullAction { + + static ID = 'workbench.action.pull.rebase'; + static LABEL = nls.localize('pullWithRebase', "Pull (Rebase)"); + + constructor(@IGitService gitService: IGitService) { + super(PullWithRebaseAction.ID, PullWithRebaseAction.LABEL, gitService); + } + + public run(context?: any):Promise { + return this.pull(true); + } +} + export class PushAction extends GitAction { static ID = 'workbench.action.push'; diff --git a/src/vs/workbench/parts/git/browser/gitServices.ts b/src/vs/workbench/parts/git/browser/gitServices.ts index 5b11b5fd223..24a897d17f6 100644 --- a/src/vs/workbench/parts/git/browser/gitServices.ts +++ b/src/vs/workbench/parts/git/browser/gitServices.ts @@ -553,8 +553,8 @@ export class GitService extends ee.EventEmitter return this.run(git.ServiceOperations.BACKGROUND_FETCH, () => this.raw.fetch()); } - public pull(): winjs.Promise { - return this.run(git.ServiceOperations.PULL, () => this.raw.pull()); + public pull(rebase?: boolean): winjs.Promise { + return this.run(git.ServiceOperations.PULL, () => this.raw.pull(rebase)); } public push(): winjs.Promise { diff --git a/src/vs/workbench/parts/git/browser/views/changes/changesView.ts b/src/vs/workbench/parts/git/browser/views/changes/changesView.ts index 6bea2ae9707..b91d27a6d55 100644 --- a/src/vs/workbench/parts/git/browser/views/changes/changesView.ts +++ b/src/vs/workbench/parts/git/browser/views/changes/changesView.ts @@ -248,7 +248,8 @@ export class ChangesView extends EventEmitter.EventEmitter implements GitView.IV if (!this.secondaryActions) { this.secondaryActions = [ this.instantiationService.createInstance(GitActions.SyncAction, GitActions.SyncAction.ID, GitActions.SyncAction.LABEL), - this.instantiationService.createInstance(GitActions.PullAction), + this.instantiationService.createInstance(GitActions.PullAction, GitActions.PullAction.ID, GitActions.PullAction.LABEL), + this.instantiationService.createInstance(GitActions.PullWithRebaseAction), this.instantiationService.createInstance(GitActions.PushAction), new ActionBar.Separator(), this.instantiationService.createInstance(GitActions.CommitAction, this), diff --git a/src/vs/workbench/parts/git/common/git.ts b/src/vs/workbench/parts/git/common/git.ts index 0e006bd1db4..63165657ed1 100644 --- a/src/vs/workbench/parts/git/common/git.ts +++ b/src/vs/workbench/parts/git/common/git.ts @@ -259,7 +259,7 @@ export interface IRawGitService { reset(treeish:string, hard?: boolean): WinJS.TPromise; revertFiles(treeish:string, filePaths?: string[]): WinJS.TPromise; fetch(): WinJS.TPromise; - pull(): WinJS.TPromise; + pull(rebase?: boolean): WinJS.TPromise; push(): WinJS.TPromise; sync(): WinJS.TPromise; commit(message:string, amend?: boolean, stage?: boolean): WinJS.TPromise; @@ -285,7 +285,7 @@ export interface IGitService extends EventEmitter.IEventEmitter { reset(treeish:string, hard?: boolean): WinJS.TPromise; revertFiles(treeish:string, files?: IFileStatus[]): WinJS.TPromise; fetch(): WinJS.TPromise; - pull(): WinJS.TPromise; + pull(rebase?: boolean): WinJS.TPromise; push(): WinJS.TPromise; sync(): WinJS.TPromise; commit(message:string, amend?: boolean, stage?: boolean): WinJS.TPromise; diff --git a/src/vs/workbench/parts/git/common/noopGitService.ts b/src/vs/workbench/parts/git/common/noopGitService.ts index 295df50a36a..1c755742c4a 100644 --- a/src/vs/workbench/parts/git/common/noopGitService.ts +++ b/src/vs/workbench/parts/git/common/noopGitService.ts @@ -65,7 +65,7 @@ export class NoOpGitService implements git.IRawGitService { return winjs.Promise.as(NoOpGitService.STATUS); } - public pull(): winjs.TPromise { + public pull(rebase?: boolean): winjs.TPromise { return winjs.Promise.as(NoOpGitService.STATUS); } diff --git a/src/vs/workbench/parts/git/node/git.lib.ts b/src/vs/workbench/parts/git/node/git.lib.ts index bd8173162a8..935617acb36 100644 --- a/src/vs/workbench/parts/git/node/git.lib.ts +++ b/src/vs/workbench/parts/git/node/git.lib.ts @@ -506,8 +506,11 @@ export class Repository { }); } - public pull(): Promise { - return this.run(['pull']).then(null, (err: GitError) => { + public pull(rebase?: boolean): Promise { + const args = ['pull']; + rebase && args.push('-r'); + + return this.run(args).then(null, (err: GitError) => { if (/^CONFLICT \([^)]+\): \b/m.test(err.stdout)) { err.gitErrorCode = GitErrorCodes.Conflict; } else if (/Please tell me who you are\./.test(err.stderr)) { diff --git a/src/vs/workbench/parts/git/node/rawGitService.ts b/src/vs/workbench/parts/git/node/rawGitService.ts index 0cb084750c5..79c8dc596e0 100644 --- a/src/vs/workbench/parts/git/node/rawGitService.ts +++ b/src/vs/workbench/parts/git/node/rawGitService.ts @@ -116,8 +116,8 @@ export class RawGitService implements IRawGitService { }).then(() => this.status()); } - public pull(): TPromise { - return this.repo.pull().then(() => this.status()); + public pull(rebase?: boolean): TPromise { + return this.repo.pull(rebase).then(() => this.status()); } public push(): TPromise { @@ -235,8 +235,8 @@ export class DelayedRawGitService implements IRawGitService { return this.raw.then(raw => raw.fetch()); } - public pull(): TPromise { - return this.raw.then(raw => raw.pull()); + public pull(rebase?: boolean): TPromise { + return this.raw.then(raw => raw.pull(rebase)); } public push(): TPromise { -- GitLab