mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-28 04:23:32 +01:00
Implement rename branch command
This commit is contained in:
@@ -843,6 +843,44 @@ export class CommandCenter {
|
||||
}
|
||||
}
|
||||
|
||||
@command('git.renameBranch')
|
||||
async renameBranch(): Promise<void> {
|
||||
const placeHolder = localize('provide branch name', "Please provide a branch name");
|
||||
const name = await window.showInputBox({ placeHolder });
|
||||
|
||||
if (!name || name.trim().length === 0) {
|
||||
return;
|
||||
}
|
||||
const run = force => this.model.renameBranch(name);
|
||||
|
||||
try {
|
||||
await run(name);
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
if (err.gitErrorCode !== GitErrorCodes.InvalidBranchName &&
|
||||
err.gitErrorCode !== GitErrorCodes.BranchAlreadyExists) {
|
||||
return err;
|
||||
}
|
||||
|
||||
let message = '';
|
||||
switch (err.gitErrorCode) {
|
||||
case GitErrorCodes.InvalidBranchName:
|
||||
message = localize('invalid branch name', 'Invalid branch name');
|
||||
break;
|
||||
case GitErrorCodes.BranchAlreadyExists:
|
||||
message = localize('branch already exists', `A branch named '${name}' already exists`);
|
||||
break;
|
||||
}
|
||||
|
||||
if (!message) {
|
||||
return;
|
||||
}
|
||||
|
||||
window.showErrorMessage(message);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@command('git.merge')
|
||||
async merge(): Promise<void> {
|
||||
const config = workspace.getConfiguration('git');
|
||||
|
||||
@@ -213,9 +213,10 @@ export enum Operation {
|
||||
Stage = 1 << 14,
|
||||
GetCommitTemplate = 1 << 15,
|
||||
DeleteBranch = 1 << 16,
|
||||
Merge = 1 << 17,
|
||||
Ignore = 1 << 18,
|
||||
Tag = 1 << 19
|
||||
RenameBranch = 1 << 17,
|
||||
Merge = 1 << 18,
|
||||
Ignore = 1 << 19,
|
||||
Tag = 1 << 20
|
||||
}
|
||||
|
||||
// function getOperationName(operation: Operation): string {
|
||||
@@ -463,6 +464,10 @@ export class Model implements Disposable {
|
||||
await this.run(Operation.DeleteBranch, () => this.repository.deleteBranch(name, force));
|
||||
}
|
||||
|
||||
async renameBranch(name: string): Promise<void> {
|
||||
await this.run(Operation.RenameBranch, () => this.repository.renameBranch(name));
|
||||
}
|
||||
|
||||
async merge(ref: string): Promise<void> {
|
||||
await this.run(Operation.Merge, () => this.repository.merge(ref));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user