提交 91ec2ba0 编写于 作者: J Joao Moreno

git pull with rebase

fixes #907
related to #150
上级 254ddfd8
......@@ -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';
......
......@@ -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 {
......
......@@ -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),
......
......@@ -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>;
......@@ -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>;
......
......@@ -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);
}
......
......@@ -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)) {
......
......@@ -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> {
......@@ -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> {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册