Skip to content

Commit 3c7adf3

Browse files
committed
split branch into branchCreate and branchRename
1 parent 446e23b commit 3c7adf3

File tree

3 files changed

+32
-24
lines changed

3 files changed

+32
-24
lines changed

src/commands/git/branch.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -393,12 +393,7 @@ export class BranchGitCommand extends QuickCommand {
393393
if (state.flags.includes('--switch')) {
394394
await state.repo.switch(state.reference.ref, { createBranch: state.name });
395395
} else {
396-
await state.repo.branch({
397-
create: {
398-
name: state.name,
399-
startRef: state.reference.ref,
400-
},
401-
});
396+
await state.repo.branchCreate(state.name, state.reference.ref);
402397
}
403398
}
404399
}
@@ -619,12 +614,7 @@ export class BranchGitCommand extends QuickCommand {
619614
state.flags = result;
620615

621616
endSteps(state);
622-
await state.repo.branch({
623-
rename: {
624-
old: state.reference.ref,
625-
new: state.name,
626-
},
627-
});
617+
await state.repo.branchRename(state.reference.ref, state.name);
628618
}
629619
}
630620

src/env/node/git/localGitProvider.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1229,13 +1229,12 @@ export class LocalGitProvider implements GitProvider, Disposable {
12291229

12301230
@log()
12311231
async branch(repoPath: string, options: GitBranchOptions): Promise<void> {
1232-
const { create = null, rename = null } = options;
12331232
try {
1234-
if (create != null) {
1233+
if (options?.create != null) {
12351234
await this.git.branch(repoPath, create.name, create.startRef);
12361235
}
12371236

1238-
if (rename != null) {
1237+
if (options?.rename != null) {
12391238
await this.git.branch(repoPath, '-m', rename.new, rename.old);
12401239
}
12411240

src/git/models/repository.ts

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,7 @@ import { basename, normalizePath } from '../../system/path';
2424
import { sortCompare } from '../../system/string';
2525
import { executeActionCommand } from '../../system/vscode/command';
2626
import { configuration } from '../../system/vscode/configuration';
27-
import type {
28-
GitBranchOptions,
29-
GitDir,
30-
GitProviderDescriptor,
31-
GitRepositoryCaches,
32-
PagingOptions,
33-
} from '../gitProvider';
27+
import type { GitDir, GitProviderDescriptor, GitRepositoryCaches, PagingOptions } from '../gitProvider';
3428
import type { RemoteProvider } from '../remotes/remoteProvider';
3529
import type { GitSearch } from '../search';
3630
import type { BranchSortOptions, GitBranch } from './branch';
@@ -574,8 +568,33 @@ export class Repository implements Disposable {
574568
}
575569

576570
@log()
577-
branch(options: GitBranchOptions) {
578-
return this.container.git.branch(this.uri, options);
571+
branchCreate(name: string, startRef: string): Promise<void> {
572+
try {
573+
return void this.container.git.branch(this.uri, {
574+
create: {
575+
name: name,
576+
startRef: startRef,
577+
},
578+
});
579+
} catch (ex) {
580+
Logger.error(ex);
581+
void showGenericErrorMessage('Unable to create branch');
582+
}
583+
}
584+
585+
@log()
586+
branchRename(oldName: string, newName: string) {
587+
try {
588+
return void this.container.git.branch(this.uri, {
589+
rename: {
590+
old: oldName,
591+
new: newName,
592+
},
593+
});
594+
} catch (ex) {
595+
Logger.error(ex);
596+
void showGenericErrorMessage('Unable to rename branch');
597+
}
579598
}
580599

581600
@log()

0 commit comments

Comments
 (0)