add git delete branch command

This commit is contained in:
Maik Riechert 2017-05-03 22:53:26 +01:00 committed by Dirk Baeumer
parent c73c21e234
commit b96478ebcc
5 changed files with 60 additions and 1 deletions

View file

@ -172,6 +172,11 @@
"title": "%command.branch%",
"category": "Git"
},
{
"command": "git.deleteBranch",
"title": "%command.deleteBranch%",
"category": "Git"
},
{
"command": "git.pull",
"title": "%command.pull%",
@ -298,6 +303,10 @@
"command": "git.branch",
"when": "config.git.enabled && scmProvider == git && gitState == idle"
},
{
"command": "git.deleteBranch",
"when": "config.git.enabled && scmProvider == git && gitState == idle"
},
{
"command": "git.pull",
"when": "config.git.enabled && scmProvider == git && gitState == idle"

View file

@ -21,6 +21,7 @@
"command.undoCommit": "Undo Last Commit",
"command.checkout": "Checkout to...",
"command.branch": "Create Branch...",
"command.deleteBranch": "Delete Branch...",
"command.pull": "Pull",
"command.pullRebase": "Pull (Rebase)",
"command.push": "Push",

View file

@ -60,6 +60,26 @@ class CheckoutRemoteHeadItem extends CheckoutItem {
}
}
class BranchDeleteItem implements QuickPickItem {
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;
if (!ref) {
return;
}
await model.deleteBranch(ref);
}
}
interface Command {
commandId: string;
key: string;
@ -699,6 +719,25 @@ export class CommandCenter {
await this.model.branch(name);
}
@command('git.deleteBranch')
async deleteBranch(branchName: string): Promise<void> {
if (typeof branchName === 'string') {
return await this.model.deleteBranch(branchName);
}
const currentHead = this.model.HEAD && this.model.HEAD.name;
const heads = this.model.refs.filter(ref => ref.type === RefType.Head && ref.name !== currentHead)
.map(ref => new BranchDeleteItem(ref));
const placeHolder = 'Select a branch to delete';
const choice = await window.showQuickPick<BranchDeleteItem>(heads, { placeHolder });
if (!choice) {
return;
}
await choice.run(this.model);
}
@command('git.pull')
async pull(): Promise<void> {
const remotes = this.model.remotes;

View file

@ -650,6 +650,11 @@ export class Repository {
await this.run(args);
}
async deleteBranch(name: string): Promise<void> {
const args = ['branch', '-d', 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]);

View file

@ -210,7 +210,8 @@ export enum Operation {
Init = 1 << 12,
Show = 1 << 13,
Stage = 1 << 14,
GetCommitTemplate = 1 << 15
GetCommitTemplate = 1 << 15,
DeleteBranch = 1 << 16
}
// function getOperationName(operation: Operation): string {
@ -453,6 +454,10 @@ export class Model implements Disposable {
await this.run(Operation.Branch, () => this.repository.branch(name, true));
}
async deleteBranch(name: string): Promise<void> {
await this.run(Operation.DeleteBranch, () => this.repository.deleteBranch(name));
}
async checkout(treeish: string): Promise<void> {
await this.run(Operation.Checkout, () => this.repository.checkout(treeish, []));
}