Skip to content

Commit

Permalink
Selects if user wants to create a branch on a worktree or not
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeibbb committed Nov 8, 2024
1 parent 7ffb6fd commit c20dca6
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/plus/startWork/startWork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ interface Context {
interface State {
item?: StartWorkItem;
action?: StartWorkAction;
inWorktree?: boolean;
}

type StartWorkStepState<T extends State = State> = RequireSome<StepState<T>, 'item'>;
Expand Down Expand Up @@ -136,6 +137,7 @@ export class StartWorkCommand extends QuickCommand<State> {
const result = yield* this.selectCommandStep(state);
if (result === StepResultBreak) continue;
state.action = result.action;
state.inWorktree = result.inWorktree;

await updateContextItems(this.container, context);

Expand All @@ -162,7 +164,9 @@ export class StartWorkCommand extends QuickCommand<State> {
name: issue ? slug(`${issue.id}-${issue.title}`) : undefined,
suggestNameOnly: true,
suggestRepoOnly: true,
flags: state.inWorktree ? ['--worktree'] : ['--switch'],
},
confirm: false,
},
this.pickedVia,
);
Expand All @@ -176,14 +180,18 @@ export class StartWorkCommand extends QuickCommand<State> {
return state.counter < 0 ? StepResultBreak : undefined;
}

private *selectCommandStep(state: StepState<State>): StepResultGenerator<{ action?: StartWorkAction }> {
private *selectCommandStep(
state: StepState<State>,
): StepResultGenerator<{ action?: StartWorkAction; inWorktree?: boolean }> {
const step = createPickStep({
placeholder: 'Start work by creating a new branch',
items: [
createQuickPickItemOfT('Create a branch', {
action: 'start',
}),
createQuickPickItemOfT('Create a branch on a worktree', { action: 'start', inWorktree: true }),
createQuickPickItemOfT('Create a branch from an issue', {}),
createQuickPickItemOfT('Create a branch from an issue on a worktree', { inWorktree: true }),
],
});
const selection: StepSelection<typeof step> = yield step;
Expand Down

0 comments on commit c20dca6

Please sign in to comment.