diff --git a/src/env/node/git/localGitProvider.ts b/src/env/node/git/localGitProvider.ts index 1eff40bb3d040..c31deacb6681e 100644 --- a/src/env/node/git/localGitProvider.ts +++ b/src/env/node/git/localGitProvider.ts @@ -39,6 +39,7 @@ import { WorktreeDeleteErrorReason, } from '../../../git/errors'; import type { + GitBranchOptions, GitCaches, GitDir, GitProvider, @@ -1227,9 +1228,18 @@ export class LocalGitProvider implements GitProvider, Disposable { } @log() - async branch(repoPath: string, ...args: string[]): Promise { + async branch(repoPath: string, options: GitBranchOptions): Promise { + const { create = null, rename = null } = options; try { - await this.git.branch(repoPath, ...args); + if (create != null) { + await this.git.branch(repoPath, create.name, create.startRef); + } + + if (rename != null) { + await this.git.branch(repoPath, '-m', rename.new, rename.old); + } + + throw new Error('Invalid branch options'); } catch (ex) { Logger.error(ex, getLogScope()); void showGenericErrorMessage(`Unable to create branch`); diff --git a/src/git/gitProvider.ts b/src/git/gitProvider.ts index 5311451c9fa05..24f9e3e8e3f02 100644 --- a/src/git/gitProvider.ts +++ b/src/git/gitProvider.ts @@ -112,6 +112,17 @@ export interface RepositoryVisibilityInfo { remotesHash?: string; } +export type GitBranchOptions = { + rename?: { + old: string; + new: string; + }; + create?: { + name: string; + startRef: string; + }; +}; + export interface GitProvider extends Disposable { get onDidChange(): Event; get onDidChangeRepository(): Event; @@ -167,7 +178,7 @@ export interface GitProvider extends Disposable { stash?: boolean | 'prompt'; }, ): Promise; - branch(repoPath: string, ...args: string[]): Promise; + branch(repoPath: string, options: GitBranchOptions): Promise; checkout( repoPath: string, ref: string, diff --git a/src/git/gitProviderService.ts b/src/git/gitProviderService.ts index 3d23d28e1f605..aa4ac486543ba 100644 --- a/src/git/gitProviderService.ts +++ b/src/git/gitProviderService.ts @@ -43,6 +43,7 @@ import { configuration } from '../system/vscode/configuration'; import { setContext } from '../system/vscode/context'; import { getBestPath } from '../system/vscode/path'; import type { + GitBranchOptions, GitCaches, GitDir, GitProvider, @@ -1326,9 +1327,9 @@ export class GitProviderService implements Disposable { } @log() - branch(repoPath: string | Uri, ...args: string[]): Promise { + branch(repoPath: string | Uri, options: GitBranchOptions): Promise { const { provider, path } = this.getProvider(repoPath); - return provider.branch(path, ...args); + return provider.branch(path, options); } @log() diff --git a/src/git/models/repository.ts b/src/git/models/repository.ts index e7d4e9f739592..6f88cd2d39acb 100644 --- a/src/git/models/repository.ts +++ b/src/git/models/repository.ts @@ -24,7 +24,13 @@ 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 { GitDir, GitProviderDescriptor, GitRepositoryCaches, PagingOptions } from '../gitProvider'; +import type { + GitBranchOptions, + GitDir, + GitProviderDescriptor, + GitRepositoryCaches, + PagingOptions, +} from '../gitProvider'; import type { RemoteProvider } from '../remotes/remoteProvider'; import type { GitSearch } from '../search'; import type { BranchSortOptions, GitBranch } from './branch'; @@ -47,17 +53,6 @@ export interface RepositoriesSortOptions { orderBy?: RepositoriesSorting; } -type GitBranchOptions = { - rename?: { - old: string; - new: string; - }; - create?: { - name: string; - startRef: string; - }; -}; - const emptyArray = Object.freeze([]) as unknown as any[]; const millisecondsPerMinute = 60 * 1000; @@ -580,16 +575,7 @@ export class Repository implements Disposable { @log() branch(options: GitBranchOptions) { - const { rename, create } = options; - if (rename != null) { - return this.container.git.branch(this.uri, '-m', rename.old, rename.new); - } - - if (create != null) { - return this.container.git.branch(this.uri, create.name, create.startRef); - } - - throw new Error('Invalid branch options'); + return this.container.git.branch(this.uri, options); } @log() diff --git a/src/plus/integrations/providers/github/githubGitProvider.ts b/src/plus/integrations/providers/github/githubGitProvider.ts index 96d00a9406e5f..0eb3145cd8065 100644 --- a/src/plus/integrations/providers/github/githubGitProvider.ts +++ b/src/plus/integrations/providers/github/githubGitProvider.ts @@ -25,6 +25,7 @@ import { import { Features } from '../../../../features'; import { GitSearchError } from '../../../../git/errors'; import type { + GitBranchOptions, GitCaches, GitProvider, LeftRightCommitCountResult, @@ -455,7 +456,7 @@ export class GitHubGitProvider implements GitProvider, Disposable { async applyChangesToWorkingFile(_uri: GitUri, _ref1?: string, _ref2?: string): Promise {} @log() - async branch(_repoPath: string, ..._args: string[]): Promise {} + async branch(_repoPath: string, _options: GitBranchOptions): Promise {} @log() async branchContainsCommit(_repoPath: string, _name: string, _ref: string): Promise {