Skip to content

Commit

Permalink
git pull with rebase
Browse files Browse the repository at this point in the history
fixes #907
related to #150
  • Loading branch information
joaomoreno committed Dec 3, 2015
1 parent 254ddfd commit 91ec2ba
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 15 deletions.
29 changes: 26 additions & 3 deletions src/vs/workbench/parts/git/browser/gitActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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) {
Expand All @@ -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';
Expand Down
4 changes: 2 additions & 2 deletions src/vs/workbench/parts/git/browser/gitServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
4 changes: 2 additions & 2 deletions src/vs/workbench/parts/git/common/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ export interface IRawGitService {
reset(treeish:string, hard?: boolean): WinJS.TPromise<IRawStatus>;
revertFiles(treeish:string, filePaths?: string[]): WinJS.TPromise<IRawStatus>;
fetch(): WinJS.TPromise<IRawStatus>;
pull(): WinJS.TPromise<IRawStatus>;
pull(rebase?: boolean): WinJS.TPromise<IRawStatus>;
push(): WinJS.TPromise<IRawStatus>;
sync(): WinJS.TPromise<IRawStatus>;
commit(message:string, amend?: boolean, stage?: boolean): WinJS.TPromise<IRawStatus>;
Expand All @@ -285,7 +285,7 @@ export interface IGitService extends EventEmitter.IEventEmitter {
reset(treeish:string, hard?: boolean): WinJS.TPromise<IModel>;
revertFiles(treeish:string, files?: IFileStatus[]): WinJS.TPromise<IModel>;
fetch(): WinJS.TPromise<IModel>;
pull(): WinJS.TPromise<IModel>;
pull(rebase?: boolean): WinJS.TPromise<IModel>;
push(): WinJS.TPromise<IModel>;
sync(): WinJS.TPromise<IModel>;
commit(message:string, amend?: boolean, stage?: boolean): WinJS.TPromise<IModel>;
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/parts/git/common/noopGitService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export class NoOpGitService implements git.IRawGitService {
return winjs.Promise.as(NoOpGitService.STATUS);
}

public pull(): winjs.TPromise<git.IRawStatus> {
public pull(rebase?: boolean): winjs.TPromise<git.IRawStatus> {
return winjs.Promise.as(NoOpGitService.STATUS);
}

Expand Down
7 changes: 5 additions & 2 deletions src/vs/workbench/parts/git/node/git.lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
8 changes: 4 additions & 4 deletions src/vs/workbench/parts/git/node/rawGitService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ export class RawGitService implements IRawGitService {
}).then(() => this.status());
}

public pull(): TPromise<IRawStatus> {
return this.repo.pull().then(() => this.status());
public pull(rebase?: boolean): TPromise<IRawStatus> {
return this.repo.pull(rebase).then(() => this.status());
}

public push(): TPromise<IRawStatus> {
Expand Down Expand Up @@ -235,8 +235,8 @@ export class DelayedRawGitService implements IRawGitService {
return this.raw.then(raw => raw.fetch());
}

public pull(): TPromise<IRawStatus> {
return this.raw.then(raw => raw.pull());
public pull(rebase?: boolean): TPromise<IRawStatus> {
return this.raw.then(raw => raw.pull(rebase));
}

public push(): TPromise<IRawStatus> {
Expand Down

0 comments on commit 91ec2ba

Please sign in to comment.