提交 818fa5a5 编写于 作者: R Rokas Gečas

#10542 Ability to merge local git branches

上级 e7ff4c37
......@@ -172,6 +172,11 @@
"title": "%command.branch%",
"category": "Git"
},
{
"command": "git.merge",
"title": "%command.merge%",
"category": "Git"
},
{
"command": "git.pull",
"title": "%command.pull%",
......
......@@ -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",
......
......@@ -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<void> {
const ref = this.treeish;
......@@ -671,6 +677,29 @@ export class CommandCenter {
await this.model.branch(name);
}
@command('git.merge')
async merge(): Promise<void> {
const config = workspace.getConfiguration('git');
const checkoutType = config.get<string>('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<CheckoutBasicItem>(picks, { placeHolder });
if (!choice) {
return;
}
await this.model.merge(choice.label);
}
@command('git.pull')
async pull(): Promise<void> {
const remotes = this.model.remotes;
......
......@@ -650,6 +650,11 @@ export class Repository {
await this.run(args);
}
async merge(name: string): Promise<void> {
const args = ['merge', name];
await this.run(args);
}
async clean(paths: string[]): Promise<void> {
const pathsByGroup = groupBy(paths, p => path.dirname(p));
const groups = Object.keys(pathsByGroup).map(k => pathsByGroup[k]);
......
......@@ -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<void> {
await this.run(Operation.Merge, () => this.repository.merge(name));
}
async checkout(treeish: string): Promise<void> {
await this.run(Operation.Checkout, () => this.repository.checkout(treeish, []));
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册