Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Push To Remote #12550

Merged
merged 1 commit into from
Oct 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {IFileService} from 'vs/platform/files/common/files';
import {IInstantiationService} from 'vs/platform/instantiation/common/instantiation';
import wbar = require('vs/workbench/common/actionRegistry');
import { SyncActionDescriptor } from 'vs/platform/actions/common/actions';
import { OpenChangeAction, OpenFileAction, SyncAction, PullAction, PushAction, PublishAction, StartGitBranchAction, StartGitCheckoutAction, InputCommitAction, UndoLastCommitAction, BaseStageAction, BaseUnstageAction } from './gitActions';
import { OpenChangeAction, OpenFileAction, SyncAction, PullAction, PushAction, PushToRemoteAction, PublishAction, StartGitBranchAction, StartGitCheckoutAction, InputCommitAction, UndoLastCommitAction, BaseStageAction, BaseUnstageAction } from './gitActions';
import paths = require('vs/base/common/paths');
import URI from 'vs/base/common/uri';

Expand Down Expand Up @@ -633,6 +633,7 @@ workbenchActionRegistry.registerWorkbenchAction(new SyncActionDescriptor(GlobalO
workbenchActionRegistry.registerWorkbenchAction(new SyncActionDescriptor(GlobalOpenInEditorAction, GlobalOpenInEditorAction.ID, GlobalOpenInEditorAction.LABEL), 'Git: Open File', category);
workbenchActionRegistry.registerWorkbenchAction(new SyncActionDescriptor(PullAction, PullAction.ID, PullAction.LABEL), 'Git: Pull', category);
workbenchActionRegistry.registerWorkbenchAction(new SyncActionDescriptor(PushAction, PushAction.ID, PushAction.LABEL), 'Git: Push', category);
workbenchActionRegistry.registerWorkbenchAction(new SyncActionDescriptor(PushToRemoteAction, PushToRemoteAction.ID, PushToRemoteAction.LABEL), 'Git: Push To Remote', category);
workbenchActionRegistry.registerWorkbenchAction(new SyncActionDescriptor(SyncAction, SyncAction.ID, SyncAction.LABEL), 'Git: Sync', category);
workbenchActionRegistry.registerWorkbenchAction(new SyncActionDescriptor(PublishAction, PublishAction.ID, PublishAction.LABEL), 'Git: Publish', category);
workbenchActionRegistry.registerWorkbenchAction(new SyncActionDescriptor(StartGitBranchAction, StartGitBranchAction.ID, StartGitBranchAction.LABEL), 'Git: Branch', category);
Expand Down
68 changes: 68 additions & 0 deletions src/vs/workbench/parts/git/browser/gitActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1008,6 +1008,74 @@ export class PushAction extends GitAction {
}
}

export class PushToRemoteAction extends GitAction {

static ID = 'workbench.action.git.pushToRemote';
static LABEL = nls.localize('pushToRemote', "Push To Remote");

constructor(
id: string = PushToRemoteAction.ID,
label: string = PushToRemoteAction.LABEL,
@IGitService gitService: IGitService,
@IQuickOpenService private quickOpenService: IQuickOpenService
) {
super(id, label, 'git-action publish', gitService);
}

protected isEnabled():boolean {
if (!super.isEnabled()) {
return false;
}

if (!this.gitService.isIdle()) {
return false;
}

const model = this.gitService.getModel();

if (model.getRemotes().length === 0) {
return false;
}

const HEAD = model.getHEAD();

if (!HEAD || !HEAD.name) {
return false;
}

return true;
}

public run(context?: any):Promise {
const model = this.gitService.getModel();
const remotes = model.getRemotes();
const branchName = model.getHEAD().name;
let promise: TPromise<string>;


const picks = remotes.map(({ name, url }) => ({
label: name,
description: url
}));

const placeHolder = nls.localize('pushToRemotePickMessage', "Pick a remote to push the branch '{0}' to:", branchName);

promise = this.quickOpenService.pick(picks, { placeHolder })
.then(pick => pick && pick.label);


return promise
.then(remote => remote && this.gitService.push(remote, branchName))
.then(null, err => {
if (err.gitErrorCode === GitErrorCodes.AuthenticationFailed) {
return Promise.wrapError(errors.create(nls.localize('authFailed', "Authentication failed on the git remote.")));
}

return Promise.wrapError(err);
});
}
}

export class PublishAction extends GitAction {

static ID = 'workbench.action.git.publish';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ export class ChangesView extends EventEmitter.EventEmitter implements GitView.IV
this.instantiationService.createInstance(GitActions.PullAction, GitActions.PullAction.ID, GitActions.PullAction.LABEL),
this.instantiationService.createInstance(GitActions.PullWithRebaseAction),
this.instantiationService.createInstance(GitActions.PushAction, GitActions.PushAction.ID, GitActions.PushAction.LABEL),
this.instantiationService.createInstance(GitActions.PushToRemoteAction, GitActions.PushToRemoteAction.ID, GitActions.PushToRemoteAction.LABEL),
new ActionBar.Separator(),
this.instantiationService.createInstance(GitActions.PublishAction, GitActions.PublishAction.ID, GitActions.PublishAction.LABEL),
new ActionBar.Separator(),
Expand Down