Skip to content

Commit 38f7ee0

Browse files
committed
Selects if user wants to create a branch on a worktree or not
(#3621, #3698)
1 parent ec80427 commit 38f7ee0

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
@@ -373,7 +373,7 @@ export class BranchGitCommand extends QuickCommand {
373373
state.reference = result;
374374
}
375375

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

src/plus/startWork/startWork.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ interface Context {
5050
interface State {
5151
item?: StartWorkItem;
5252
action?: StartWorkAction;
53+
inWorktree?: boolean;
5354
}
5455

5556
export type StartWorkAction = 'start';
@@ -123,6 +124,7 @@ export class StartWorkCommand extends QuickCommand<State> {
123124
const result = yield* this.selectCommandStep(state);
124125
if (result === StepResultBreak) continue;
125126
state.action = result.action;
127+
state.inWorktree = result.inWorktree;
126128
}
127129

128130
if (state.counter < 2 && !state.action) {
@@ -149,7 +151,9 @@ export class StartWorkCommand extends QuickCommand<State> {
149151
name: issue ? slug(`${issue.id}-${issue.title}`) : undefined,
150152
suggestNameOnly: true,
151153
suggestRepoOnly: true,
154+
flags: state.inWorktree ? ['--worktree'] : ['--switch'],
152155
},
156+
confirm: false,
153157
},
154158
this.pickedVia,
155159
);
@@ -168,14 +172,18 @@ export class StartWorkCommand extends QuickCommand<State> {
168172
return state.counter < 0 ? StepResultBreak : undefined;
169173
}
170174

171-
private *selectCommandStep(state: StepState<State>): StepResultGenerator<{ action?: StartWorkAction }> {
175+
private *selectCommandStep(
176+
state: StepState<State>,
177+
): StepResultGenerator<{ action?: StartWorkAction; inWorktree?: boolean }> {
172178
const step = createPickStep({
173179
placeholder: 'Start work by creating a new branch',
174180
items: [
175181
createQuickPickItemOfT('Create a Branch', {
176182
action: 'start',
177183
}),
184+
createQuickPickItemOfT('Create a Branch in a Worktree', { action: 'start', inWorktree: true }),
178185
createQuickPickItemOfT('Create a Branch from an Issue', {}),
186+
createQuickPickItemOfT('Create a Branch from an Issue in a Worktree', { inWorktree: true }),
179187
],
180188
});
181189
const selection: StepSelection<typeof step> = yield step;

0 commit comments

Comments
 (0)