From 818fa5a50f39ed9a3f4803a7fd5f3f1fe0be2247 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rokas=20Ge=C4=8Das?= Date: Mon, 1 May 2017 16:44:00 +0300 Subject: [PATCH] #10542 Ability to merge local git branches --- extensions/git/package.json | 5 +++++ extensions/git/package.nls.json | 1 + extensions/git/src/commands.ts | 35 ++++++++++++++++++++++++++++++--- extensions/git/src/git.ts | 5 +++++ extensions/git/src/model.ts | 7 ++++++- 5 files changed, 49 insertions(+), 4 deletions(-) diff --git a/extensions/git/package.json b/extensions/git/package.json index bd3d175c58a..2d57328aeed 100644 --- a/extensions/git/package.json +++ b/extensions/git/package.json @@ -172,6 +172,11 @@ "title": "%command.branch%", "category": "Git" }, + { + "command": "git.merge", + "title": "%command.merge%", + "category": "Git" + }, { "command": "git.pull", "title": "%command.pull%", diff --git a/extensions/git/package.nls.json b/extensions/git/package.nls.json index 11c7347fa07..0559e657500 100644 --- a/extensions/git/package.nls.json +++ b/extensions/git/package.nls.json @@ -21,6 +21,7 @@ "command.undoCommit": "Undo Last Commit", "command.checkout": "Checkout to...", "command.branch": "Create Branch...", + "command.merge": "Merge Branch...", "command.pull": "Pull", "command.pullRebase": "Pull (Rebase)", "command.push": "Push", diff --git a/extensions/git/src/commands.ts b/extensions/git/src/commands.ts index 399cfd10a16..4f4856e6340 100644 --- a/extensions/git/src/commands.ts +++ b/extensions/git/src/commands.ts @@ -17,15 +17,21 @@ import * as nls from 'vscode-nls'; const localize = nls.loadMessageBundle(); -class CheckoutItem implements QuickPickItem { +class CheckoutBasicItem implements QuickPickItem { + get label(): string { return this.ref.name || ''; } + get description(): string { return this.ref.name || ''; } + + constructor(protected ref: Ref) { } +} + + +class CheckoutItem extends CheckoutBasicItem { protected get shortCommit(): string { return (this.ref.commit || '').substr(0, 8); } protected get treeish(): string | undefined { return this.ref.name; } get label(): string { return this.ref.name || this.shortCommit; } get description(): string { return this.shortCommit; } - constructor(protected ref: Ref) { } - async run(model: Model): Promise { const ref = this.treeish; @@ -671,6 +677,29 @@ export class CommandCenter { await this.model.branch(name); } + @command('git.merge') + async merge(): Promise { + const config = workspace.getConfiguration('git'); + const checkoutType = config.get('checkoutType') || 'all'; + const includeRemotes = checkoutType === 'all' || checkoutType === 'remote'; + + const heads = this.model.refs.filter(ref => ref.type === RefType.Head) + .map(ref => new CheckoutItem(ref)); + + const remoteHeads = (includeRemotes ? this.model.refs.filter(ref => ref.type === RefType.RemoteHead) : []) + .map(ref => new CheckoutRemoteHeadItem(ref)); + + const picks = [...heads, ...remoteHeads]; + const placeHolder = 'Select a ref to checkout'; + const choice = await window.showQuickPick(picks, { placeHolder }); + + if (!choice) { + return; + } + + await this.model.merge(choice.label); + } + @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 4adc617a3eb..e161b9ef65c 100644 --- a/extensions/git/src/git.ts +++ b/extensions/git/src/git.ts @@ -650,6 +650,11 @@ export class Repository { await this.run(args); } + async merge(name: string): Promise { + const args = ['merge', name]; + await this.run(args); + } + async clean(paths: string[]): Promise { const pathsByGroup = groupBy(paths, p => path.dirname(p)); const groups = Object.keys(pathsByGroup).map(k => pathsByGroup[k]); diff --git a/extensions/git/src/model.ts b/extensions/git/src/model.ts index 1d74a87d3a3..f8b1ce56e06 100644 --- a/extensions/git/src/model.ts +++ b/extensions/git/src/model.ts @@ -211,7 +211,8 @@ export enum Operation { Init = 1 << 12, Show = 1 << 13, Stage = 1 << 14, - GetCommitTemplate = 1 << 15 + GetCommitTemplate = 1 << 15, + Merge = 1 << 16 } // function getOperationName(operation: Operation): string { @@ -454,6 +455,10 @@ export class Model implements Disposable { await this.run(Operation.Branch, () => this.repository.branch(name, true)); } + async merge(name: string): Promise { + await this.run(Operation.Merge, () => this.repository.merge(name)); + } + async checkout(treeish: string): Promise { await this.run(Operation.Checkout, () => this.repository.checkout(treeish, [])); } -- GitLab