mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 04:49:35 +00:00
add git delete branch command
This commit is contained in:
parent
c73c21e234
commit
b96478ebcc
|
@ -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"
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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]);
|
||||
|
|
|
@ -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, []));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue