Skip to content

Commit

Permalink
split branch into branchCreate and branchRename
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiolms committed Sep 24, 2024
1 parent 446e23b commit 3c7adf3
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 24 deletions.
14 changes: 2 additions & 12 deletions src/commands/git/branch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down Expand Up @@ -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);
}
}

Expand Down
5 changes: 2 additions & 3 deletions src/env/node/git/localGitProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1229,13 +1229,12 @@ export class LocalGitProvider implements GitProvider, Disposable {

@log()
async branch(repoPath: string, options: GitBranchOptions): Promise<void> {
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);
}

Expand Down
37 changes: 28 additions & 9 deletions src/git/models/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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<void> {
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()
Expand Down

0 comments on commit 3c7adf3

Please sign in to comment.