mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-24 18:49:00 +01:00
Git: Pull from specific branch
This commit is contained in:
@@ -764,6 +764,37 @@ export class CommandCenter {
|
||||
}
|
||||
}
|
||||
|
||||
@command('git.pullFromRemoteBranch')
|
||||
async pullFrom(): Promise<void> {
|
||||
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<void> {
|
||||
const remotes = this.model.remotes;
|
||||
|
||||
@@ -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<void> {
|
||||
async pull(rebase?: boolean, remote?: string, name?: string): Promise<void> {
|
||||
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) {
|
||||
|
||||
@@ -480,13 +480,13 @@ export class Model implements Disposable {
|
||||
}
|
||||
|
||||
@throttle
|
||||
async pull(): Promise<void> {
|
||||
await this.run(Operation.Pull, () => this.repository.pull());
|
||||
async pullWithRebase(): Promise<void> {
|
||||
await this.run(Operation.Pull, () => this.repository.pull(true));
|
||||
}
|
||||
|
||||
@throttle
|
||||
async pullWithRebase(): Promise<void> {
|
||||
await this.run(Operation.Pull, () => this.repository.pull(true));
|
||||
async pull(rebase?: boolean, remote?: string, name?: string): Promise<void> {
|
||||
await this.run(Operation.Pull, () => this.repository.pull(rebase, remote, name));
|
||||
}
|
||||
|
||||
@throttle
|
||||
|
||||
Reference in New Issue
Block a user