diff --git a/extensions/git/package.json b/extensions/git/package.json index b2462371b3c..6db5f813cc3 100644 --- a/extensions/git/package.json +++ b/extensions/git/package.json @@ -93,6 +93,11 @@ "light": "resources/icons/light/clean.svg", "dark": "resources/icons/dark/clean.svg" } + }, + { + "command": "git.publish", + "title": "Publish", + "category": "Git" } ], "menus": { diff --git a/extensions/git/src/commands.ts b/extensions/git/src/commands.ts index 1424d1c16cb..8315b81a694 100644 --- a/extensions/git/src/commands.ts +++ b/extensions/git/src/commands.ts @@ -90,7 +90,8 @@ class CommandCenter { commands.registerCommand('git.unstageAll', this.unstageAll, this), commands.registerCommand('git.clean', this.clean, this), commands.registerCommand('git.cleanAll', this.cleanAll, this), - commands.registerCommand('git.checkout', this.checkout, this) + commands.registerCommand('git.checkout', this.checkout, this), + commands.registerCommand('git.publish', this.publish, this), ); } @@ -192,9 +193,9 @@ class CommandCenter { const remoteHeads = (includeRemotes ? this.model.refs.filter(ref => ref.type === RefType.RemoteHead) : []) .map(ref => new CheckoutRemoteHeadItem(ref)); - const choice = await window.showQuickPick([...heads, ...tags, ...remoteHeads], { - placeHolder: 'Select a ref to checkout' - }); + const picks = [...heads, ...tags, ...remoteHeads]; + const placeHolder = 'Select a ref to checkout'; + const choice = await window.showQuickPick(picks, { placeHolder }); if (!choice) { return; @@ -203,6 +204,20 @@ class CommandCenter { await choice.run(this.model); } + @decorate(catchErrors) + async publish(): Promise { + const branchName = this.model.HEAD && this.model.HEAD.name || ''; + const picks = this.model.remotes.map(r => r.name); + const placeHolder = `Pick a remote to publish the branch '${branchName}' to:`; + const choice = await window.showQuickPick(picks, { placeHolder }); + + if (!choice) { + return; + } + + await this.model.push(choice, branchName, { setUpstream: true }); + } + dispose(): void { this.disposables.forEach(d => d.dispose()); } diff --git a/extensions/git/src/model.ts b/extensions/git/src/model.ts index a463a759e19..8fac407207e 100644 --- a/extensions/git/src/model.ts +++ b/extensions/git/src/model.ts @@ -6,7 +6,7 @@ 'use strict'; import { Uri, EventEmitter, Event, SCMResource, SCMResourceDecorations, SCMResourceGroup } from 'vscode'; -import { Repository, IRef, IBranch, IRemote } from './git'; +import { Repository, IRef, IBranch, IRemote, IPushOptions } from './git'; import { throttle } from './util'; import { decorate } from 'core-decorators'; import * as path from 'path'; @@ -193,12 +193,12 @@ export class Model { return this._HEAD; } - private _refs: IRef[]; + private _refs: IRef[] = []; get refs(): IRef[] { return this._refs; } - private _remotes: IRemote[]; + private _remotes: IRemote[] = []; get remotes(): IRemote[] { return this._remotes; } @@ -326,4 +326,9 @@ export class Model { await this.repository.checkout(treeish, []); await this.update(); } + + async push(remote?: string, name?: string, options?: IPushOptions): Promise { + await this.repository.push(remote, name, options); + await this.update(); + } } \ No newline at end of file diff --git a/extensions/git/src/statusbar.ts b/extensions/git/src/statusbar.ts index 83e996b946d..c6332d3a12b 100644 --- a/extensions/git/src/statusbar.ts +++ b/extensions/git/src/statusbar.ts @@ -58,8 +58,6 @@ export class SyncStatusBar { constructor(private model: Model) { this.raw = window.createStatusBarItem(StatusBarAlignment.Left); - - this.disposables.push(this.raw); model.onDidChange(this.update, this, this.disposables); this.update();