diff --git a/extensions/git/package.json b/extensions/git/package.json index e61a88c2210..c443d4ce063 100644 --- a/extensions/git/package.json +++ b/extensions/git/package.json @@ -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", diff --git a/extensions/git/src/commands.ts b/extensions/git/src/commands.ts index 319e334041b..5860d54a507 100644 --- a/extensions/git/src/commands.ts +++ b/extensions/git/src/commands.ts @@ -449,25 +449,67 @@ export class CommandCenter { @CommandCenter.Command('git.pull') @CommandCenter.CatchErrors async pull(): Promise { - 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 { - 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 { - 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 { - 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 { + 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); diff --git a/extensions/git/src/model.ts b/extensions/git/src/model.ts index 9631eeed23a..349f5e37649 100644 --- a/extensions/git/src/model.ts +++ b/extensions/git/src/model.ts @@ -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 { - await this.run(Operation.Sync, () => this.repository.sync()); + async pull(rebase?: boolean): Promise { + 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 { + await this.run(Operation.Sync, () => this.repository.sync()); + } + private async run(operation: Operation, fn: () => Promise = () => Promise.resolve()): Promise { return window.withScmProgress(async () => { this._operations = this._operations.start(operation);