Skip to content

Commit 01e466e

Browse files
committed
git: publish command, statusbar
1 parent 4c3f63a commit 01e466e

4 files changed

Lines changed: 32 additions & 9 deletions

File tree

extensions/git/package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@
9393
"light": "resources/icons/light/clean.svg",
9494
"dark": "resources/icons/dark/clean.svg"
9595
}
96+
},
97+
{
98+
"command": "git.publish",
99+
"title": "Publish",
100+
"category": "Git"
96101
}
97102
],
98103
"menus": {

extensions/git/src/commands.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ class CommandCenter {
9090
commands.registerCommand('git.unstageAll', this.unstageAll, this),
9191
commands.registerCommand('git.clean', this.clean, this),
9292
commands.registerCommand('git.cleanAll', this.cleanAll, this),
93-
commands.registerCommand('git.checkout', this.checkout, this)
93+
commands.registerCommand('git.checkout', this.checkout, this),
94+
commands.registerCommand('git.publish', this.publish, this),
9495
);
9596
}
9697

@@ -192,9 +193,9 @@ class CommandCenter {
192193
const remoteHeads = (includeRemotes ? this.model.refs.filter(ref => ref.type === RefType.RemoteHead) : [])
193194
.map(ref => new CheckoutRemoteHeadItem(ref));
194195

195-
const choice = await window.showQuickPick<CheckoutItem>([...heads, ...tags, ...remoteHeads], {
196-
placeHolder: 'Select a ref to checkout'
197-
});
196+
const picks = [...heads, ...tags, ...remoteHeads];
197+
const placeHolder = 'Select a ref to checkout';
198+
const choice = await window.showQuickPick<CheckoutItem>(picks, { placeHolder });
198199

199200
if (!choice) {
200201
return;
@@ -203,6 +204,20 @@ class CommandCenter {
203204
await choice.run(this.model);
204205
}
205206

207+
@decorate(catchErrors)
208+
async publish(): Promise<void> {
209+
const branchName = this.model.HEAD && this.model.HEAD.name || '';
210+
const picks = this.model.remotes.map(r => r.name);
211+
const placeHolder = `Pick a remote to publish the branch '${branchName}' to:`;
212+
const choice = await window.showQuickPick(picks, { placeHolder });
213+
214+
if (!choice) {
215+
return;
216+
}
217+
218+
await this.model.push(choice, branchName, { setUpstream: true });
219+
}
220+
206221
dispose(): void {
207222
this.disposables.forEach(d => d.dispose());
208223
}

extensions/git/src/model.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
'use strict';
77

88
import { Uri, EventEmitter, Event, SCMResource, SCMResourceDecorations, SCMResourceGroup } from 'vscode';
9-
import { Repository, IRef, IBranch, IRemote } from './git';
9+
import { Repository, IRef, IBranch, IRemote, IPushOptions } from './git';
1010
import { throttle } from './util';
1111
import { decorate } from 'core-decorators';
1212
import * as path from 'path';
@@ -193,12 +193,12 @@ export class Model {
193193
return this._HEAD;
194194
}
195195

196-
private _refs: IRef[];
196+
private _refs: IRef[] = [];
197197
get refs(): IRef[] {
198198
return this._refs;
199199
}
200200

201-
private _remotes: IRemote[];
201+
private _remotes: IRemote[] = [];
202202
get remotes(): IRemote[] {
203203
return this._remotes;
204204
}
@@ -326,4 +326,9 @@ export class Model {
326326
await this.repository.checkout(treeish, []);
327327
await this.update();
328328
}
329+
330+
async push(remote?: string, name?: string, options?: IPushOptions): Promise<void> {
331+
await this.repository.push(remote, name, options);
332+
await this.update();
333+
}
329334
}

extensions/git/src/statusbar.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@ export class SyncStatusBar {
5858

5959
constructor(private model: Model) {
6060
this.raw = window.createStatusBarItem(StatusBarAlignment.Left);
61-
62-
6361
this.disposables.push(this.raw);
6462
model.onDidChange(this.update, this, this.disposables);
6563
this.update();

0 commit comments

Comments
 (0)