diff --git a/extensions/git/package.json b/extensions/git/package.json index 3db3f72875d..cd9ea807d1f 100644 --- a/extensions/git/package.json +++ b/extensions/git/package.json @@ -192,6 +192,11 @@ "title": "%command.pullRebase%", "category": "Git" }, + { + "command": "git.pullFromRemoteBranch", + "title": "%command.pullFromRemoteBranch%", + "category": "Git" + }, { "command": "git.push", "title": "%command.push%", @@ -321,6 +326,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" @@ -377,6 +386,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 52edd8318c0..12f02512b18 100644 --- a/extensions/git/package.nls.json +++ b/extensions/git/package.nls.json @@ -25,6 +25,7 @@ "command.merge": "Merge 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 3eaa99748b3..334ec210714 100644 --- a/extensions/git/src/commands.ts +++ b/extensions/git/src/commands.ts @@ -810,6 +810,36 @@ 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 28e918ef536..49906563fe2 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; @@ -748,13 +751,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 073cb39fc8f..8f161f4336c 100644 --- a/extensions/git/src/model.ts +++ b/extensions/git/src/model.ts @@ -487,13 +487,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