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 12, 2024
1 parent ec80427 commit 38f7ee0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/commands/git/branch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ export class BranchGitCommand extends QuickCommand {
state.reference = result;
}

if (state.counter < 4 || state.name == null) {
if (state.counter < 4 || state.name == null || state.suggestNameOnly) {
const result = yield* inputBranchNameStep(state, context, {
titleContext: ` from ${getReferenceLabel(state.reference, {
capitalize: true,
Expand Down
10 changes: 9 additions & 1 deletion src/plus/startWork/startWork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ interface Context {
interface State {
item?: StartWorkItem;
action?: StartWorkAction;
inWorktree?: boolean;
}

export type StartWorkAction = 'start';
Expand Down Expand Up @@ -123,6 +124,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;
}

if (state.counter < 2 && !state.action) {
Expand All @@ -149,7 +151,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 @@ -168,14 +172,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 in a Worktree', { action: 'start', inWorktree: true }),
createQuickPickItemOfT('Create a Branch from an Issue', {}),
createQuickPickItemOfT('Create a Branch from an Issue in a Worktree', { inWorktree: true }),
],
});
const selection: StepSelection<typeof step> = yield step;
Expand Down

0 comments on commit 38f7ee0

Please sign in to comment.