From 39f33ae2ae89c0a9cc17b22f60e7221df6e0225b Mon Sep 17 00:00:00 2001 From: Bugra Cuhadaroglu Date: Sat, 20 May 2017 01:48:59 -0400 Subject: [PATCH] Git: Pull from specific branch --- extensions/git/package.json | 14 ++++++++++++++ extensions/git/package.nls.json | 1 + extensions/git/src/commands.ts | 31 +++++++++++++++++++++++++++++++ extensions/git/src/git.ts | 15 +++++++++++++-- extensions/git/src/model.ts | 8 ++++---- 5 files changed, 63 insertions(+), 6 deletions(-) diff --git a/extensions/git/package.json b/extensions/git/package.json index 62c735337de..30c84cb156f 100644 --- a/extensions/git/package.json +++ b/extensions/git/package.json @@ -187,6 +187,11 @@ "title": "%command.pullRebase%", "category": "Git" }, + { + "command": "git.pullFromRemoteBranch", + "title": "%command.pullFromRemoteBranch%", + "category": "Git" + }, { "command": "git.push", "title": "%command.push%", @@ -311,6 +316,10 @@ "command": "git.pull", "when": "config.git.enabled && scmProvider == git && gitState == idle" }, + { + "command": "git.pullFromRemoteBranch", + "when": "config.git.enabled && scmProvider == git && gitState == idle" + }, { "command": "git.pullRebase", "when": "config.git.enabled && scmProvider == git && gitState == idle" @@ -367,6 +376,11 @@ "group": "1_sync", "when": "config.git.enabled && scmProvider == git && gitState == idle" }, + { + "command": "git.pullFromRemoteBranch", + "group": "1_sync", + "when": "config.git.enabled && scmProvider == git && gitState == idle" + }, { "command": "git.push", "group": "1_sync", diff --git a/extensions/git/package.nls.json b/extensions/git/package.nls.json index 655074654b2..f58899056ff 100644 --- a/extensions/git/package.nls.json +++ b/extensions/git/package.nls.json @@ -24,6 +24,7 @@ "command.deleteBranch": "Delete Branch...", "command.pull": "Pull", "command.pullRebase": "Pull (Rebase)", + "command.pullFromRemoteBranch": "Pull From...", "command.push": "Push", "command.pushTo": "Push to...", "command.sync": "Sync", diff --git a/extensions/git/src/commands.ts b/extensions/git/src/commands.ts index 05a93640ca1..ca93b622377 100644 --- a/extensions/git/src/commands.ts +++ b/extensions/git/src/commands.ts @@ -764,6 +764,37 @@ export class CommandCenter { } } + @command('git.pullFromRemoteBranch') + async pullFrom(): Promise { + 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; + } + + const picks = remotes.map(r => ({ label: r.name, description: r.url })); + const placeHolder = localize('pick remote pull repo', "Pick a remote to pull the branch from"); + const pick = await window.showQuickPick(picks, { placeHolder }); + + if (!pick) { + return; + } + + + const branchName = await window.showInputBox({ + placeHolder: localize('branch name', "Branch name"), + prompt: localize('provide branch name', "Please provide a branch name"), + ignoreFocusOut: true + }); + + if (!branchName) { + return; + } + + this.model.pull(false, pick.label, branchName); + } + @command('git.pull') async pull(): Promise { const remotes = this.model.remotes; diff --git a/extensions/git/src/git.ts b/extensions/git/src/git.ts index ad023efdf6e..d7769d5f922 100644 --- a/extensions/git/src/git.ts +++ b/extensions/git/src/git.ts @@ -270,7 +270,8 @@ export const GitErrorCodes = { CantAccessRemote: 'CantAccessRemote', RepositoryNotFound: 'RepositoryNotFound', RepositoryIsLocked: 'RepositoryIsLocked', - BranchNotFullyMerged: 'BranchNotFullyMerged' + BranchNotFullyMerged: 'BranchNotFullyMerged', + NoRemoteReference: 'NoRemoteReference' }; function getGitErrorCode(stderr: string): string | undefined { @@ -290,6 +291,8 @@ function getGitErrorCode(stderr: string): string | undefined { return GitErrorCodes.CantAccessRemote; } else if (/branch '.+' is not fully merged/.test(stderr)) { return GitErrorCodes.BranchNotFullyMerged; + } else if (/Couldn\'t find remote ref/.test(stderr)) { + return GitErrorCodes.NoRemoteReference; } return void 0; @@ -734,13 +737,21 @@ export class Repository { } } - async pull(rebase?: boolean): Promise { + async pull(rebase?: boolean, remote?: string, name?: string): Promise { const args = ['pull']; if (rebase) { args.push('-r'); } + if (remote) { + args.push(remote); + } + + if (name) { + args.push(name); + } + try { await this.run(args); } catch (err) { diff --git a/extensions/git/src/model.ts b/extensions/git/src/model.ts index 4b2cf900350..e47b35768b0 100644 --- a/extensions/git/src/model.ts +++ b/extensions/git/src/model.ts @@ -480,13 +480,13 @@ export class Model implements Disposable { } @throttle - async pull(): Promise { - await this.run(Operation.Pull, () => this.repository.pull()); + async pullWithRebase(): Promise { + await this.run(Operation.Pull, () => this.repository.pull(true)); } @throttle - async pullWithRebase(): Promise { - await this.run(Operation.Pull, () => this.repository.pull(true)); + async pull(rebase?: boolean, remote?: string, name?: string): Promise { + await this.run(Operation.Pull, () => this.repository.pull(rebase, remote, name)); } @throttle -- GitLab