Skip to content

Commit c1f3e4e

Browse files
sergeibbbchivorotkiv
authored andcommitted
Selects if user wants to create a branch on a worktree or not
(#3621)
1 parent da28135 commit c1f3e4e

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/commands/git/branch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ export class BranchGitCommand extends QuickCommand {
377377
state.reference = result;
378378
}
379379

380-
if (state.counter < 4 || state.name == null) {
380+
if (state.counter < 4 || state.name == null || state.suggestNameOnly) {
381381
const result = yield* inputBranchNameStep(state, context, {
382382
titleContext: ` from ${getReferenceLabel(state.reference, {
383383
capitalize: true,

src/plus/startWork/startWork.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ interface Context {
5555
interface State {
5656
item?: StartWorkItem;
5757
action?: StartWorkAction;
58+
inWorktree?: boolean;
5859
}
5960

6061
export type StartWorkAction = 'start';
@@ -128,6 +129,7 @@ export class StartWorkCommand extends QuickCommand<State> {
128129
const result = yield* this.selectCommandStep(state);
129130
if (result === StepResultBreak) continue;
130131
state.action = result.action;
132+
state.inWorktree = result.inWorktree;
131133
}
132134

133135
if (state.counter < 2 && !state.action) {
@@ -154,7 +156,9 @@ export class StartWorkCommand extends QuickCommand<State> {
154156
name: issue ? slug(`${issue.id}-${issue.title}`) : undefined,
155157
suggestNameOnly: true,
156158
suggestRepoOnly: true,
159+
flags: state.inWorktree ? ['--worktree'] : ['--switch'],
157160
},
161+
confirm: false,
158162
},
159163
this.pickedVia,
160164
);
@@ -173,14 +177,18 @@ export class StartWorkCommand extends QuickCommand<State> {
173177
return state.counter < 0 ? StepResultBreak : undefined;
174178
}
175179

176-
private *selectCommandStep(state: StepState<State>): StepResultGenerator<{ action?: StartWorkAction }> {
180+
private *selectCommandStep(
181+
state: StepState<State>,
182+
): StepResultGenerator<{ action?: StartWorkAction; inWorktree?: boolean }> {
177183
const step = createPickStep({
178184
placeholder: 'Start work by creating a new branch',
179185
items: [
180186
createQuickPickItemOfT('Create a branch', {
181187
action: 'start',
182188
}),
189+
createQuickPickItemOfT('Create a branch on a worktree', { action: 'start', inWorktree: true }),
183190
createQuickPickItemOfT('Create a branch from an issue', {}),
191+
createQuickPickItemOfT('Create a branch from an issue on a worktree', { inWorktree: true }),
184192
],
185193
});
186194
const selection: StepSelection<typeof step> = yield step;

0 commit comments

Comments
 (0)