Skip to content

Commit cf00fc4

Browse files
Inverts flow of Start Work
- Removes 'worktree' options from first prompt - Adds confirmation back to the end of the 'create branch' command flow which gives option to create a worktree - Removes option to create branch without switching when command is invoked from Start Work
1 parent 8ec8bb7 commit cf00fc4

File tree

3 files changed

+37
-54
lines changed

3 files changed

+37
-54
lines changed

docs/telemetry-events.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1379,7 +1379,7 @@ void
13791379
```typescript
13801380
{
13811381
'instance': number,
1382-
'type': 'branch' | 'branch-worktree' | 'issue' | 'issue-worktree'
1382+
'type': 'branch' | 'issue'
13831383
}
13841384
```
13851385

@@ -1390,7 +1390,7 @@ void
13901390
```typescript
13911391
{
13921392
'instance': number,
1393-
'type': 'branch' | 'branch-worktree' | 'issue' | 'issue-worktree',
1393+
'type': 'branch' | 'issue',
13941394
'items.count': number,
13951395
'connected': false | true
13961396
}
@@ -1403,7 +1403,7 @@ void
14031403
```typescript
14041404
{
14051405
'instance': number,
1406-
'type': 'branch' | 'branch-worktree' | 'issue' | 'issue-worktree',
1406+
'type': 'branch' | 'issue',
14071407
'items.count': number,
14081408
'connected': false | true
14091409
}
@@ -1416,7 +1416,7 @@ void
14161416
```typescript
14171417
{
14181418
'instance': number,
1419-
'type': 'branch' | 'branch-worktree' | 'issue' | 'issue-worktree',
1419+
'type': 'branch' | 'issue',
14201420
'items.count': number,
14211421
'action': 'soft-open',
14221422
'connected': false | true,
@@ -1431,7 +1431,7 @@ void
14311431
```typescript
14321432
{
14331433
'instance': number,
1434-
'type': 'branch' | 'branch-worktree' | 'issue' | 'issue-worktree',
1434+
'type': 'branch' | 'issue',
14351435
'items.count': number,
14361436
'connected': false | true,
14371437
[`item.${string}`]: string | number | false | true
@@ -1445,7 +1445,7 @@ void
14451445
```typescript
14461446
{
14471447
'instance': number,
1448-
'type': 'branch' | 'branch-worktree' | 'issue' | 'issue-worktree',
1448+
'type': 'branch' | 'issue',
14491449
'items.count': number,
14501450
'connected': false | true
14511451
}
@@ -1456,7 +1456,7 @@ void
14561456
```typescript
14571457
{
14581458
'instance': number,
1459-
'type': 'branch' | 'branch-worktree' | 'issue' | 'issue-worktree',
1459+
'type': 'branch' | 'issue',
14601460
'items.count': number,
14611461
'connected': false | true
14621462
}
@@ -1467,7 +1467,7 @@ void
14671467
```typescript
14681468
{
14691469
'instance': number,
1470-
'type': 'branch' | 'branch-worktree' | 'issue' | 'issue-worktree',
1470+
'type': 'branch' | 'issue',
14711471
'items.count': number,
14721472
'connected': false | true
14731473
}
@@ -1513,7 +1513,7 @@ void
15131513
{
15141514
'hostingProvider.provider': 'github' | 'gitlab' | 'bitbucket' | 'azureDevOps' | 'jira' | 'trello' | 'github-enterprise' | 'gitlab-self-hosted',
15151515
'hostingProvider.key': string,
1516-
// @deprecated:
1516+
// @deprecated:
15171517
'remoteProviders.key': string
15181518
}
15191519
```
@@ -1526,7 +1526,7 @@ void
15261526
{
15271527
'hostingProvider.provider': 'github' | 'gitlab' | 'bitbucket' | 'azureDevOps' | 'jira' | 'trello' | 'github-enterprise' | 'gitlab-self-hosted',
15281528
'hostingProvider.key': string,
1529-
// @deprecated:
1529+
// @deprecated:
15301530
'remoteProviders.key': string
15311531
}
15321532
```

src/commands/git/branch.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ interface CreateState {
6464

6565
suggestNameOnly?: boolean;
6666
suggestRepoOnly?: boolean;
67+
confirmOptions?: CreateFlags[];
6768
}
6869

6970
function isCreateState(state: Partial<State> | undefined): state is Partial<CreateState> {
@@ -434,27 +435,42 @@ export class BranchGitCommand extends QuickCommand {
434435
}
435436

436437
private *createCommandConfirmStep(state: CreateStepState, context: Context): StepResultGenerator<CreateFlags[]> {
437-
const step: QuickPickStep<FlagsQuickPickItem<CreateFlags>> = createConfirmStep(
438-
appendReposToTitle(`Confirm ${context.title}`, state, context),
439-
[
438+
const confirmItems = [];
439+
if (!state.confirmOptions) {
440+
confirmItems.push(
440441
createFlagsQuickPickItem<CreateFlags>(state.flags, [], {
441442
label: context.title,
442443
detail: `Will create a new branch named ${state.name} from ${getReferenceLabel(state.reference)}`,
443444
}),
445+
);
446+
}
447+
448+
if (!state.confirmOptions || state.confirmOptions.includes('--switch')) {
449+
confirmItems.push(
444450
createFlagsQuickPickItem<CreateFlags>(state.flags, ['--switch'], {
445451
label: `Create & Switch to Branch`,
446452
detail: `Will create and switch to a new branch named ${state.name} from ${getReferenceLabel(
447453
state.reference,
448454
)}`,
449455
}),
456+
);
457+
}
458+
459+
if (!state.confirmOptions || state.confirmOptions.includes('--worktree')) {
460+
confirmItems.push(
450461
createFlagsQuickPickItem<CreateFlags>(state.flags, ['--worktree'], {
451462
label: `${context.title} in New Worktree`,
452463
description: 'avoids modifying your working tree',
453464
detail: `Will create a new worktree for a new branch named ${state.name} from ${getReferenceLabel(
454465
state.reference,
455466
)}`,
456467
}),
457-
],
468+
);
469+
}
470+
471+
const step: QuickPickStep<FlagsQuickPickItem<CreateFlags>> = createConfirmStep(
472+
appendReposToTitle(`Confirm ${context.title}`, state, context),
473+
confirmItems,
458474
context,
459475
);
460476
const selection: StepSelection<typeof step> = yield step;

src/plus/startWork/startWork.ts

Lines changed: 7 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import type { Issue, IssueShape, SearchedIssue } from '../../git/models/issue';
2929
import { getOrOpenIssueRepository } from '../../git/models/issue';
3030
import type { Repository } from '../../git/models/repository';
3131
import type { QuickPickItemOfT } from '../../quickpicks/items/common';
32-
import { createQuickPickItemOfT, createQuickPickSeparator } from '../../quickpicks/items/common';
32+
import { createQuickPickItemOfT } from '../../quickpicks/items/common';
3333
import type { DirectiveQuickPickItem } from '../../quickpicks/items/directive';
3434
import { createDirectiveQuickPickItem, Directive } from '../../quickpicks/items/directive';
3535
import { getScopedCounter } from '../../system/counter';
@@ -54,14 +54,13 @@ interface Context {
5454
interface State {
5555
item?: StartWorkItem;
5656
type?: StartWorkType;
57-
inWorktree?: boolean;
5857
}
5958
interface StateWithType extends State {
6059
type: StartWorkType;
6160
}
6261

63-
export type StartWorkType = 'branch' | 'branch-worktree' | 'issue' | 'issue-worktree';
64-
type StartWorkTypeItem = { type: StartWorkType; inWorktree?: boolean };
62+
export type StartWorkType = 'branch' | 'issue';
63+
type StartWorkTypeItem = { type: StartWorkType };
6564

6665
export interface StartWorkCommandArgs {
6766
readonly command: 'startWork';
@@ -125,7 +124,6 @@ export class StartWorkCommand extends QuickCommand<State> {
125124
const result = yield* this.selectTypeStep(state);
126125
if (result === StepResultBreak) continue;
127126
state.type = result.type;
128-
state.inWorktree = result.inWorktree;
129127
if (this.container.telemetry.enabled) {
130128
this.container.telemetry.sendEvent(
131129
'startWork/type/chosen',
@@ -139,7 +137,7 @@ export class StartWorkCommand extends QuickCommand<State> {
139137
}
140138
}
141139

142-
if ((state.counter < 2 && state.type === 'issue') || state.type === 'issue-worktree') {
140+
if (state.counter < 2 && state.type === 'issue') {
143141
if (!hasConnectedIntegrations) {
144142
if (this.container.telemetry.enabled) {
145143
this.container.telemetry.sendEvent(
@@ -189,7 +187,6 @@ export class StartWorkCommand extends QuickCommand<State> {
189187
}
190188
} else {
191189
state.type = result.type;
192-
state.inWorktree = result.inWorktree;
193190
}
194191
}
195192

@@ -206,9 +203,8 @@ export class StartWorkCommand extends QuickCommand<State> {
206203
name: issue ? `${slug(issue.id, { lower: false })}-${slug(issue.title)}` : undefined,
207204
suggestNameOnly: true,
208205
suggestRepoOnly: true,
209-
flags: state.inWorktree ? ['--worktree'] : ['--switch'],
206+
confirmOptions: ['--switch', '--worktree'],
210207
},
211-
confirm: false,
212208
},
213209
this.pickedVia,
214210
);
@@ -222,47 +218,23 @@ export class StartWorkCommand extends QuickCommand<State> {
222218
return state.counter < 0 ? StepResultBreak : undefined;
223219
}
224220

225-
private *selectTypeStep(
226-
state: StepState<State>,
227-
): StepResultGenerator<{ type: StartWorkType; inWorktree?: boolean }> {
221+
private *selectTypeStep(state: StepState<State>): StepResultGenerator<{ type: StartWorkType }> {
228222
const step = createPickStep({
229223
placeholder: 'Choose how to start work',
230224
items: [
231-
createQuickPickSeparator('Issues'),
232225
createQuickPickItemOfT<StartWorkTypeItem>(
233226
{
234227
label: 'Create Branch from Issue...',
235228
detail: 'Will create a new branch after selecting an issue',
236229
},
237230
{ type: 'issue' },
238231
),
239-
createQuickPickItemOfT<StartWorkTypeItem>(
240-
{
241-
label: 'Create Branch & Worktree from Issue...',
242-
detail: 'Will create a new branch & worktree after selecting an issue',
243-
},
244-
{
245-
type: 'issue-worktree',
246-
inWorktree: true,
247-
},
248-
),
249-
createQuickPickSeparator('References'),
250232
createQuickPickItemOfT<StartWorkTypeItem>(
251233
{ label: 'Create Branch...', detail: 'Will create a new branch after selecting a reference' },
252234
{
253235
type: 'branch',
254236
},
255237
),
256-
createQuickPickItemOfT<StartWorkTypeItem>(
257-
{
258-
label: 'Create Branch & Worktree...',
259-
detail: 'Will create a new branch & worktree after selecting a reference',
260-
},
261-
{
262-
type: 'branch-worktree',
263-
inWorktree: true,
264-
},
265-
),
266238
],
267239
});
268240
const selection: StepSelection<typeof step> = yield step;
@@ -444,12 +416,7 @@ export class StartWorkCommand extends QuickCommand<State> {
444416
if (!context.result.items.length) {
445417
return {
446418
placeholder: 'No issues found. Start work anyway.',
447-
items: [
448-
createQuickPickItemOfT<StartWorkTypeItem>(
449-
state.inWorktree ? 'Create a branch on a worktree' : 'Create a branch',
450-
{ type: state.inWorktree ? 'branch-worktree' : 'branch', inWorktree: state.inWorktree },
451-
),
452-
],
419+
items: [createQuickPickItemOfT<StartWorkTypeItem>('Create a branch', { type: 'branch' })],
453420
};
454421
}
455422

0 commit comments

Comments
 (0)