Skip to content

Commit 72992b8

Browse files
committed
change branch create and branch rename into normal commands
1 parent 4a1c96c commit 72992b8

File tree

7 files changed

+58
-4
lines changed

7 files changed

+58
-4
lines changed

src/commands/git/branch.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,12 @@ 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-
state.repo.branch(...state.flags, state.name, state.reference.ref);
396+
await state.repo.branch({
397+
create: {
398+
name: state.name,
399+
startRef: state.reference.ref,
400+
},
401+
});
397402
}
398403
}
399404
}
@@ -614,7 +619,12 @@ export class BranchGitCommand extends QuickCommand {
614619
state.flags = result;
615620

616621
endSteps(state);
617-
state.repo.branch(...state.flags, state.reference.ref, state.name);
622+
await state.repo.branch({
623+
rename: {
624+
old: state.reference.ref,
625+
new: state.name,
626+
},
627+
});
618628
}
619629
}
620630

src/env/node/git/git.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,10 @@ export class Git {
506506
}
507507
}
508508

509+
branch(repoPath: string, ...args: string[]) {
510+
return this.git<string>({ cwd: repoPath }, 'branch', ...args);
511+
}
512+
509513
branch__set_upstream(repoPath: string, branch: string, remote: string, remoteBranch: string) {
510514
return this.git<string>({ cwd: repoPath }, 'branch', '--set-upstream-to', `${remote}/${remoteBranch}`, branch);
511515
}

src/env/node/git/localGitProvider.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,6 +1225,16 @@ export class LocalGitProvider implements GitProvider, Disposable {
12251225
}
12261226
}
12271227

1228+
@log()
1229+
async branch(repoPath: string, ...args: string[]): Promise<void> {
1230+
try {
1231+
await this.git.branch(repoPath, ...args);
1232+
} catch (ex) {
1233+
Logger.error(ex, getLogScope());
1234+
void showGenericErrorMessage(`Unable to create branch`);
1235+
}
1236+
}
1237+
12281238
@log()
12291239
async checkout(
12301240
repoPath: string,

src/git/gitProvider.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ export interface GitProvider extends Disposable {
167167
stash?: boolean | 'prompt';
168168
},
169169
): Promise<void>;
170+
branch(repoPath: string, ...args: string[]): Promise<void>;
170171
checkout(
171172
repoPath: string,
172173
ref: string,

src/git/gitProviderService.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1325,6 +1325,12 @@ export class GitProviderService implements Disposable {
13251325
return provider.applyUnreachableCommitForPatch?.(path, ref, options);
13261326
}
13271327

1328+
@log()
1329+
branch(repoPath: string | Uri, ...args: string[]): Promise<void> {
1330+
const { provider, path } = this.getProvider(repoPath);
1331+
return provider.branch(path, ...args);
1332+
}
1333+
13281334
@log()
13291335
checkout(
13301336
repoPath: string | Uri,

src/git/models/repository.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,17 @@ export interface RepositoriesSortOptions {
4747
orderBy?: RepositoriesSorting;
4848
}
4949

50+
type GitBranchOptions = {
51+
rename?: {
52+
old: string;
53+
new: string;
54+
};
55+
create?: {
56+
name: string;
57+
startRef: string;
58+
};
59+
};
60+
5061
const emptyArray = Object.freeze([]) as unknown as any[];
5162

5263
const millisecondsPerMinute = 60 * 1000;
@@ -568,8 +579,17 @@ export class Repository implements Disposable {
568579
}
569580

570581
@log()
571-
branch(...args: string[]) {
572-
void this.runTerminalCommand('branch', ...args);
582+
branch(options: GitBranchOptions) {
583+
const { rename, create } = options;
584+
if (rename != null) {
585+
return this.container.git.branch(this.uri, '-m', rename.old, rename.new);
586+
}
587+
588+
if (create != null) {
589+
return this.container.git.branch(this.uri, create.name, create.startRef);
590+
}
591+
592+
throw new Error('Invalid branch options');
573593
}
574594

575595
@log()

src/plus/integrations/providers/github/githubGitProvider.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,9 @@ export class GitHubGitProvider implements GitProvider, Disposable {
452452
@log()
453453
async applyChangesToWorkingFile(_uri: GitUri, _ref1?: string, _ref2?: string): Promise<void> {}
454454

455+
@log()
456+
async branch(_repoPath: string, ..._args: string[]): Promise<void> {}
457+
455458
@log()
456459
async branchContainsCommit(_repoPath: string, _name: string, _ref: string): Promise<boolean> {
457460
return false;

0 commit comments

Comments
 (0)