mirror of
https://github.com/Microsoft/vscode
synced 2024-09-18 01:58:27 +00:00
git: pull, push, sync commands
This commit is contained in:
parent
8929a0e759
commit
a0b3d09ab4
|
@ -202,22 +202,22 @@
|
|||
{
|
||||
"command": "git.pull",
|
||||
"group": "1_sync",
|
||||
"when": "scmProvider == none"
|
||||
"when": "scmProvider == git"
|
||||
},
|
||||
{
|
||||
"command": "git.pullRebase",
|
||||
"group": "1_sync",
|
||||
"when": "scmProvider == none"
|
||||
"when": "scmProvider == git"
|
||||
},
|
||||
{
|
||||
"command": "git.push",
|
||||
"group": "1_sync",
|
||||
"when": "scmProvider == none"
|
||||
"when": "scmProvider == git"
|
||||
},
|
||||
{
|
||||
"command": "git.pushTo",
|
||||
"group": "1_sync",
|
||||
"when": "scmProvider == none"
|
||||
"when": "scmProvider == git"
|
||||
},
|
||||
{
|
||||
"command": "git.publish",
|
||||
|
|
|
@ -449,25 +449,67 @@ export class CommandCenter {
|
|||
@CommandCenter.Command('git.pull')
|
||||
@CommandCenter.CatchErrors
|
||||
async pull(): Promise<void> {
|
||||
await Promise.reject('not implemented');
|
||||
const remotes = this.model.remotes;
|
||||
|
||||
if (remotes.length === 0) {
|
||||
window.showWarningMessage(localize('no remotes to pull', "Your repository has no remotes configured to pull from."));
|
||||
return;
|
||||
}
|
||||
|
||||
await this.model.pull();
|
||||
}
|
||||
|
||||
@CommandCenter.Command('git.pullRebase')
|
||||
@CommandCenter.CatchErrors
|
||||
async pullRebase(): Promise<void> {
|
||||
await Promise.reject('not implemented');
|
||||
const remotes = this.model.remotes;
|
||||
|
||||
if (remotes.length === 0) {
|
||||
window.showWarningMessage(localize('no remotes to pull', "Your repository has no remotes configured to pull from."));
|
||||
return;
|
||||
}
|
||||
|
||||
await this.model.pull(true);
|
||||
}
|
||||
|
||||
@CommandCenter.Command('git.push')
|
||||
@CommandCenter.CatchErrors
|
||||
async push(): Promise<void> {
|
||||
await Promise.reject('not implemented');
|
||||
const remotes = this.model.remotes;
|
||||
|
||||
if (remotes.length === 0) {
|
||||
window.showWarningMessage(localize('no remotes to push', "Your repository has no remotes configured to push to."));
|
||||
return;
|
||||
}
|
||||
|
||||
await this.model.push();
|
||||
}
|
||||
|
||||
@CommandCenter.Command('git.pushTo')
|
||||
@CommandCenter.CatchErrors
|
||||
async pushTo(): Promise<void> {
|
||||
await Promise.reject('not implemented');
|
||||
const remotes = this.model.remotes;
|
||||
|
||||
if (remotes.length === 0) {
|
||||
window.showWarningMessage(localize('no remotes to push', "Your repository has no remotes configured to push to."));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.model.HEAD || !this.model.HEAD.name) {
|
||||
window.showWarningMessage(localize('nobranch', "Please check out a branch to push to a remote."));
|
||||
return;
|
||||
}
|
||||
|
||||
const branchName = this.model.HEAD.name;
|
||||
const picks = remotes.map(r => ({ label: r.name, description: r.url }));
|
||||
const placeHolder = localize('pick remote', "Pick a remote to publish the branch '{0}' to:", branchName);
|
||||
const pick = await window.showQuickPick(picks, { placeHolder });
|
||||
|
||||
if (!pick) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.model.push(pick.label, branchName);
|
||||
}
|
||||
|
||||
@CommandCenter.Command('git.sync')
|
||||
|
@ -501,6 +543,13 @@ export class CommandCenter {
|
|||
@CommandCenter.Command('git.publish')
|
||||
@CommandCenter.CatchErrors
|
||||
async publish(): Promise<void> {
|
||||
const remotes = this.model.remotes;
|
||||
|
||||
if (remotes.length === 0) {
|
||||
window.showWarningMessage(localize('no remotes to publish', "Your repository has no remotes configured to publish to."));
|
||||
return;
|
||||
}
|
||||
|
||||
const branchName = this.model.HEAD && this.model.HEAD.name || '';
|
||||
const picks = this.model.remotes.map(r => r.name);
|
||||
const placeHolder = localize('pick remote', "Pick a remote to publish the branch '{0}' to:", branchName);
|
||||
|
|
|
@ -154,16 +154,17 @@ export class WorkingTreeGroup extends ResourceGroup {
|
|||
}
|
||||
|
||||
export enum Operation {
|
||||
Status = 0o1,
|
||||
Stage = 0o2,
|
||||
Unstage = 0o4,
|
||||
Commit = 0o10,
|
||||
Clean = 0o20,
|
||||
Branch = 0o40,
|
||||
Checkout = 0o100,
|
||||
Fetch = 0o200,
|
||||
Sync = 0o400,
|
||||
Push = 0o1000
|
||||
Status = 1 << 0,
|
||||
Stage = 1 << 1,
|
||||
Unstage = 1 << 2,
|
||||
Commit = 1 << 3,
|
||||
Clean = 1 << 4,
|
||||
Branch = 1 << 5,
|
||||
Checkout = 1 << 6,
|
||||
Fetch = 1 << 7,
|
||||
Pull = 1 << 8,
|
||||
Push = 1 << 9,
|
||||
Sync = 1 << 10
|
||||
}
|
||||
|
||||
export interface Operations {
|
||||
|
@ -357,8 +358,8 @@ export class Model {
|
|||
}
|
||||
|
||||
@throttle
|
||||
async sync(): Promise<void> {
|
||||
await this.run(Operation.Sync, () => this.repository.sync());
|
||||
async pull(rebase?: boolean): Promise<void> {
|
||||
await this.run(Operation.Pull, () => this.repository.pull(rebase));
|
||||
}
|
||||
|
||||
@throttle
|
||||
|
@ -366,6 +367,11 @@ export class Model {
|
|||
await this.run(Operation.Push, () => this.repository.push(remote, name, options));
|
||||
}
|
||||
|
||||
@throttle
|
||||
async sync(): Promise<void> {
|
||||
await this.run(Operation.Sync, () => this.repository.sync());
|
||||
}
|
||||
|
||||
private async run(operation: Operation, fn: () => Promise<void> = () => Promise.resolve()): Promise<void> {
|
||||
return window.withScmProgress(async () => {
|
||||
this._operations = this._operations.start(operation);
|
||||
|
|
Loading…
Reference in a new issue