Skip to content

Commit

Permalink
set git flags only in localGitProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiolms committed Sep 24, 2024
1 parent 1bafd77 commit 446e23b
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 28 deletions.
14 changes: 12 additions & 2 deletions src/env/node/git/localGitProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import {
WorktreeDeleteErrorReason,
} from '../../../git/errors';
import type {
GitBranchOptions,
GitCaches,
GitDir,
GitProvider,
Expand Down Expand Up @@ -1227,9 +1228,18 @@ export class LocalGitProvider implements GitProvider, Disposable {
}

@log()
async branch(repoPath: string, ...args: string[]): Promise<void> {
async branch(repoPath: string, options: GitBranchOptions): Promise<void> {
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`);
Expand Down
13 changes: 12 additions & 1 deletion src/git/gitProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>;
get onDidChangeRepository(): Event<RepositoryChangeEvent>;
Expand Down Expand Up @@ -167,7 +178,7 @@ export interface GitProvider extends Disposable {
stash?: boolean | 'prompt';
},
): Promise<void>;
branch(repoPath: string, ...args: string[]): Promise<void>;
branch(repoPath: string, options: GitBranchOptions): Promise<void>;
checkout(
repoPath: string,
ref: string,
Expand Down
5 changes: 3 additions & 2 deletions src/git/gitProviderService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -1326,9 +1327,9 @@ export class GitProviderService implements Disposable {
}

@log()
branch(repoPath: string | Uri, ...args: string[]): Promise<void> {
branch(repoPath: string | Uri, options: GitBranchOptions): Promise<void> {
const { provider, path } = this.getProvider(repoPath);
return provider.branch(path, ...args);
return provider.branch(path, options);
}

@log()
Expand Down
30 changes: 8 additions & 22 deletions src/git/models/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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;
Expand Down Expand Up @@ -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()
Expand Down
3 changes: 2 additions & 1 deletion src/plus/integrations/providers/github/githubGitProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
import { Features } from '../../../../features';
import { GitSearchError } from '../../../../git/errors';
import type {
GitBranchOptions,
GitCaches,
GitProvider,
LeftRightCommitCountResult,
Expand Down Expand Up @@ -455,7 +456,7 @@ export class GitHubGitProvider implements GitProvider, Disposable {
async applyChangesToWorkingFile(_uri: GitUri, _ref1?: string, _ref2?: string): Promise<void> {}

@log()
async branch(_repoPath: string, ..._args: string[]): Promise<void> {}
async branch(_repoPath: string, _options: GitBranchOptions): Promise<void> {}

@log()
async branchContainsCommit(_repoPath: string, _name: string, _ref: string): Promise<boolean> {
Expand Down

0 comments on commit 446e23b

Please sign in to comment.