From 3c7adf36de51e40cd35f11f9b850724d2591bab5 Mon Sep 17 00:00:00 2001 From: Sergio Date: Mon, 23 Sep 2024 16:39:28 +0200 Subject: [PATCH] split `branch` into `branchCreate` and `branchRename` --- src/commands/git/branch.ts | 14 ++--------- src/env/node/git/localGitProvider.ts | 5 ++-- src/git/models/repository.ts | 37 +++++++++++++++++++++------- 3 files changed, 32 insertions(+), 24 deletions(-) diff --git a/src/commands/git/branch.ts b/src/commands/git/branch.ts index 6e2e4b7786025..4eb6531103b7d 100644 --- a/src/commands/git/branch.ts +++ b/src/commands/git/branch.ts @@ -393,12 +393,7 @@ export class BranchGitCommand extends QuickCommand { if (state.flags.includes('--switch')) { await state.repo.switch(state.reference.ref, { createBranch: state.name }); } else { - await state.repo.branch({ - create: { - name: state.name, - startRef: state.reference.ref, - }, - }); + await state.repo.branchCreate(state.name, state.reference.ref); } } } @@ -619,12 +614,7 @@ export class BranchGitCommand extends QuickCommand { state.flags = result; endSteps(state); - await state.repo.branch({ - rename: { - old: state.reference.ref, - new: state.name, - }, - }); + await state.repo.branchRename(state.reference.ref, state.name); } } diff --git a/src/env/node/git/localGitProvider.ts b/src/env/node/git/localGitProvider.ts index c31deacb6681e..280211dc9f4c3 100644 --- a/src/env/node/git/localGitProvider.ts +++ b/src/env/node/git/localGitProvider.ts @@ -1229,13 +1229,12 @@ export class LocalGitProvider implements GitProvider, Disposable { @log() async branch(repoPath: string, options: GitBranchOptions): Promise { - const { create = null, rename = null } = options; try { - if (create != null) { + if (options?.create != null) { await this.git.branch(repoPath, create.name, create.startRef); } - if (rename != null) { + if (options?.rename != null) { await this.git.branch(repoPath, '-m', rename.new, rename.old); } diff --git a/src/git/models/repository.ts b/src/git/models/repository.ts index 6f88cd2d39acb..d9e70de1dd18c 100644 --- a/src/git/models/repository.ts +++ b/src/git/models/repository.ts @@ -24,13 +24,7 @@ import { basename, normalizePath } from '../../system/path'; import { sortCompare } from '../../system/string'; import { executeActionCommand } from '../../system/vscode/command'; import { configuration } from '../../system/vscode/configuration'; -import type { - GitBranchOptions, - GitDir, - GitProviderDescriptor, - GitRepositoryCaches, - PagingOptions, -} from '../gitProvider'; +import type { GitDir, GitProviderDescriptor, GitRepositoryCaches, PagingOptions } from '../gitProvider'; import type { RemoteProvider } from '../remotes/remoteProvider'; import type { GitSearch } from '../search'; import type { BranchSortOptions, GitBranch } from './branch'; @@ -574,8 +568,33 @@ export class Repository implements Disposable { } @log() - branch(options: GitBranchOptions) { - return this.container.git.branch(this.uri, options); + branchCreate(name: string, startRef: string): Promise { + try { + return void this.container.git.branch(this.uri, { + create: { + name: name, + startRef: startRef, + }, + }); + } catch (ex) { + Logger.error(ex); + void showGenericErrorMessage('Unable to create branch'); + } + } + + @log() + branchRename(oldName: string, newName: string) { + try { + return void this.container.git.branch(this.uri, { + rename: { + old: oldName, + new: newName, + }, + }); + } catch (ex) { + Logger.error(ex); + void showGenericErrorMessage('Unable to rename branch'); + } } @log()