Skip to content

Commit 46378fd

Browse files
Covers other delete branch cases
1 parent 1b803a8 commit 46378fd

File tree

12 files changed

+155
-41
lines changed

12 files changed

+155
-41
lines changed

src/commands/git/switch.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ interface State {
3838
reference: GitReference;
3939
createBranch?: string;
4040
fastForwardTo?: GitReference;
41-
skipWorktreeConfirmations?: boolean;
41+
worktreeDefaultOpen?: 'new' | 'current';
4242
}
4343

4444
type ConfirmationChoice =
@@ -223,7 +223,7 @@ export class SwitchGitCommand extends QuickCommand<State> {
223223
openOnly: true,
224224
overrides: {
225225
disallowBack: true,
226-
confirmation: state.skipWorktreeConfirmations
226+
confirmation: state.worktreeDefaultOpen
227227
? undefined
228228
: {
229229
title: `Confirm Switch to Worktree \u2022 ${getReferenceLabel(
@@ -241,12 +241,12 @@ export class SwitchGitCommand extends QuickCommand<State> {
241241
},
242242
onWorkspaceChanging: state.onWorkspaceChanging,
243243
repo: state.repos[0],
244-
skipWorktreeConfirmations: state.skipWorktreeConfirmations,
244+
worktreeDefaultOpen: state.worktreeDefaultOpen,
245245
},
246246
},
247247
this.pickedVia,
248248
);
249-
if (worktreeResult === StepResultBreak && !state.skipWorktreeConfirmations) continue;
249+
if (worktreeResult === StepResultBreak && !state.worktreeDefaultOpen) continue;
250250

251251
endSteps(state);
252252
return;
@@ -263,7 +263,7 @@ export class SwitchGitCommand extends QuickCommand<State> {
263263

264264
state.createBranch = undefined;
265265
context.promptToCreateBranch = false;
266-
if (state.skipWorktreeConfirmations) {
266+
if (state.worktreeDefaultOpen) {
267267
state.reference = context.canSwitchToLocalBranch;
268268
continue outer;
269269
}
@@ -273,7 +273,7 @@ export class SwitchGitCommand extends QuickCommand<State> {
273273
}
274274

275275
if (
276-
state.skipWorktreeConfirmations ||
276+
state.worktreeDefaultOpen ||
277277
this.confirm(context.promptToCreateBranch || context.canSwitchToLocalBranch ? true : state.confirm)
278278
) {
279279
const result = yield* this.confirmStep(state as SwitchStepState, context);
@@ -330,12 +330,12 @@ export class SwitchGitCommand extends QuickCommand<State> {
330330
result === 'switchToNewBranchViaWorktree' ? state.createBranch : undefined,
331331
repo: state.repos[0],
332332
onWorkspaceChanging: state.onWorkspaceChanging,
333-
skipWorktreeConfirmations: state.skipWorktreeConfirmations,
333+
worktreeDefaultOpen: state.worktreeDefaultOpen,
334334
},
335335
},
336336
this.pickedVia,
337337
);
338-
if (worktreeResult === StepResultBreak && !state.skipWorktreeConfirmations) continue outer;
338+
if (worktreeResult === StepResultBreak && !state.worktreeDefaultOpen) continue outer;
339339

340340
endSteps(state);
341341
return;
@@ -355,7 +355,7 @@ export class SwitchGitCommand extends QuickCommand<State> {
355355
const isRemoteBranch = isBranchReference(state.reference) && state.reference.remote;
356356

357357
type StepType = QuickPickItemOfT<ConfirmationChoice>;
358-
if (state.skipWorktreeConfirmations && state.repos.length === 1) {
358+
if (state.worktreeDefaultOpen && state.repos.length === 1) {
359359
if (isLocalBranch) {
360360
return 'switchViaWorktree';
361361
} else if (!state.createBranch && context.canSwitchToLocalBranch != null) {

src/commands/git/worktree.ts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ interface CreateState {
103103
};
104104

105105
onWorkspaceChanging?: ((isNewWorktree?: boolean) => Promise<void>) | ((isNewWorktree?: boolean) => void);
106-
skipWorktreeConfirmations?: boolean;
106+
worktreeDefaultOpen?: 'new' | 'current';
107107
}
108108

109109
type DeleteFlags = '--force' | '--delete-branches';
@@ -141,7 +141,7 @@ interface OpenState {
141141

142142
onWorkspaceChanging?: ((isNewWorktree?: boolean) => Promise<void>) | ((isNewWorktree?: boolean) => void);
143143
isNewWorktree?: boolean;
144-
skipWorktreeConfirmations?: boolean;
144+
worktreeDefaultOpen?: 'new' | 'current';
145145
}
146146

147147
interface CopyChangesState {
@@ -632,7 +632,7 @@ export class WorktreeGitCommand extends QuickCommand<State> {
632632
openOnly: true,
633633
overrides: { disallowBack: true },
634634
isNewWorktree: true,
635-
skipWorktreeConfirmations: state.skipWorktreeConfirmations,
635+
worktreeDefaultOpen: state.worktreeDefaultOpen,
636636
onWorkspaceChanging: state.onWorkspaceChanging,
637637
} satisfies OpenStepState,
638638
context,
@@ -739,7 +739,7 @@ export class WorktreeGitCommand extends QuickCommand<State> {
739739

740740
const confirmations: StepType[] = [];
741741
if (!createDirectlyInFolder) {
742-
if (state.skipWorktreeConfirmations) {
742+
if (state.worktreeDefaultOpen) {
743743
return [defaultOption.context, defaultOption.item];
744744
}
745745

@@ -1101,15 +1101,21 @@ export class WorktreeGitCommand extends QuickCommand<State> {
11011101
detail: 'Will open the worktree in a new window',
11021102
});
11031103

1104-
if (state.skipWorktreeConfirmations) {
1104+
const currentWindowItem = createFlagsQuickPickItem<OpenFlags>(state.flags, [], {
1105+
label: 'Open Worktree',
1106+
detail: 'Will open the worktree in the current window',
1107+
});
1108+
1109+
if (state.worktreeDefaultOpen === 'new') {
11051110
return newWindowItem.item;
11061111
}
11071112

1113+
if (state.worktreeDefaultOpen === 'current') {
1114+
return currentWindowItem.item;
1115+
}
1116+
11081117
const confirmations: StepType[] = [
1109-
createFlagsQuickPickItem<OpenFlags>(state.flags, [], {
1110-
label: 'Open Worktree',
1111-
detail: 'Will open the worktree in the current window',
1112-
}),
1118+
currentWindowItem,
11131119
newWindowItem,
11141120
createFlagsQuickPickItem<OpenFlags>(state.flags, ['--add-to-workspace'], {
11151121
label: `Add Worktree to Workspace`,

src/plus/launchpad/launchpad.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ export class LaunchpadCommand extends QuickCommand<State> {
391391
void this.container.launchpad.switchTo(state.item);
392392
break;
393393
case 'open-worktree':
394-
void this.container.launchpad.switchTo(state.item, { skipWorktreeConfirmations: true });
394+
void this.container.launchpad.switchTo(state.item, { openInWorktree: true });
395395
break;
396396
case 'switch-and-code-suggest':
397397
case 'code-suggest':
@@ -900,7 +900,7 @@ export class LaunchpadCommand extends QuickCommand<State> {
900900

901901
case OpenWorktreeInNewWindowQuickInputButton:
902902
this.sendItemActionTelemetry('open-worktree', item, group, context);
903-
await this.container.launchpad.switchTo(item, { skipWorktreeConfirmations: true });
903+
await this.container.launchpad.switchTo(item, { openInWorktree: true });
904904
break;
905905
}
906906

src/plus/launchpad/launchpadProvider.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ export class LaunchpadProvider implements Disposable {
467467
@log<LaunchpadProvider['switchTo']>({ args: { 0: i => `${i.id} (${i.provider.name} ${i.type})` } })
468468
async switchTo(
469469
item: LaunchpadItem,
470-
options?: { skipWorktreeConfirmations?: boolean; startCodeSuggestion?: boolean },
470+
options?: { openInWorktree?: boolean; startCodeSuggestion?: boolean },
471471
): Promise<void> {
472472
if (item.openRepository?.localBranch?.current) {
473473
void showInspectView({
@@ -483,7 +483,7 @@ export class LaunchpadProvider implements Disposable {
483483
item,
484484
options?.startCodeSuggestion
485485
? DeepLinkActionType.SwitchToAndSuggestPullRequest
486-
: options?.skipWorktreeConfirmations
486+
: options?.openInWorktree
487487
? DeepLinkActionType.SwitchToPullRequestWorktree
488488
: DeepLinkActionType.SwitchToPullRequest,
489489
);

src/uris/deepLinks/deepLink.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export const DeepLinkCommandTypeToCommand = new Map<DeepLinkCommandType, GlComma
4545
]);
4646

4747
export enum DeepLinkActionType {
48+
DeleteBranch = 'delete-branch',
4849
Switch = 'switch',
4950
SwitchToPullRequest = 'switch-to-pr',
5051
SwitchToPullRequestWorktree = 'switch-to-pr-worktree',
@@ -245,6 +246,7 @@ export const enum DeepLinkServiceState {
245246
SwitchToRef,
246247
RunCommand,
247248
OpenAllPrChanges,
249+
DeleteBranch,
248250
}
249251

250252
export const enum DeepLinkServiceAction {
@@ -278,6 +280,7 @@ export const enum DeepLinkServiceAction {
278280
OpenInspect,
279281
OpenSwitch,
280282
OpenAllPrChanges,
283+
DeleteBranch,
281284
}
282285

283286
export type DeepLinkRepoOpenType = 'clone' | 'folder' | 'workspace' | 'current';
@@ -396,6 +399,7 @@ export const deepLinkStateTransitionTable: Record<string, Record<string, DeepLin
396399
[DeepLinkServiceAction.OpenFile]: DeepLinkServiceState.OpenFile,
397400
[DeepLinkServiceAction.OpenSwitch]: DeepLinkServiceState.SwitchToRef,
398401
[DeepLinkServiceAction.OpenComparison]: DeepLinkServiceState.OpenComparison,
402+
[DeepLinkServiceAction.DeleteBranch]: DeepLinkServiceState.DeleteBranch,
399403
[DeepLinkServiceAction.DeepLinkErrored]: DeepLinkServiceState.Idle,
400404
[DeepLinkServiceAction.DeepLinkCancelled]: DeepLinkServiceState.Idle,
401405
},
@@ -446,6 +450,11 @@ export const deepLinkStateTransitionTable: Record<string, Record<string, DeepLin
446450
[DeepLinkServiceAction.DeepLinkErrored]: DeepLinkServiceState.Idle,
447451
[DeepLinkServiceAction.DeepLinkCancelled]: DeepLinkServiceState.Idle,
448452
},
453+
[DeepLinkServiceState.DeleteBranch]: {
454+
[DeepLinkServiceAction.DeepLinkResolved]: DeepLinkServiceState.Idle,
455+
[DeepLinkServiceAction.DeepLinkErrored]: DeepLinkServiceState.Idle,
456+
[DeepLinkServiceAction.DeepLinkCancelled]: DeepLinkServiceState.Idle,
457+
},
449458
};
450459

451460
export interface DeepLinkProgress {

src/uris/deepLinks/deepLinkService.ts

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,13 @@ export class DeepLinkService implements Disposable {
183183
return DeepLinkServiceAction.DeepLinkResolved;
184184
}
185185
}
186+
case DeepLinkServiceState.GoToTarget: {
187+
if (this._context.action === DeepLinkActionType.DeleteBranch) {
188+
return DeepLinkServiceAction.DeleteBranch;
189+
}
190+
191+
return DeepLinkServiceAction.DeepLinkErrored;
192+
}
186193
default:
187194
return DeepLinkServiceAction.DeepLinkErrored;
188195
}
@@ -1105,6 +1112,11 @@ export class DeepLinkService implements Disposable {
11051112
this._context.action === DeepLinkActionType.SwitchToAndSuggestPullRequest
11061113
) {
11071114
action = DeepLinkServiceAction.OpenSwitch;
1115+
} else if (
1116+
targetType === DeepLinkType.Branch &&
1117+
this._context.action === DeepLinkActionType.DeleteBranch
1118+
) {
1119+
action = DeepLinkServiceAction.DeleteBranch;
11081120
} else {
11091121
action = DeepLinkServiceAction.OpenGraph;
11101122
}
@@ -1344,8 +1356,10 @@ export class DeepLinkService implements Disposable {
13441356
repos: repo,
13451357
reference: ref,
13461358
onWorkspaceChanging: onWorkspaceChanging,
1347-
skipWorktreeConfirmations:
1348-
this._context.action === DeepLinkActionType.SwitchToPullRequestWorktree,
1359+
worktreeDefaultOpen:
1360+
this._context.action === DeepLinkActionType.SwitchToPullRequestWorktree
1361+
? 'new'
1362+
: undefined,
13491363
},
13501364
});
13511365

@@ -1462,6 +1476,38 @@ export class DeepLinkService implements Disposable {
14621476
action = DeepLinkServiceAction.DeepLinkResolved;
14631477
break;
14641478
}
1479+
case DeepLinkServiceState.DeleteBranch: {
1480+
if (!targetId || (!repo && !repoPath)) {
1481+
action = DeepLinkServiceAction.DeepLinkErrored;
1482+
message = 'Missing workspace id.';
1483+
break;
1484+
}
1485+
1486+
const repository = repo ?? this.container.git.getRepository(repoPath!);
1487+
if (!repository) {
1488+
action = DeepLinkServiceAction.DeepLinkErrored;
1489+
message = 'No matching repository found.';
1490+
break;
1491+
}
1492+
1493+
const branch = await repository.git.branches().getBranch(targetId);
1494+
if (!branch) {
1495+
action = DeepLinkServiceAction.DeepLinkErrored;
1496+
message = 'No matching branch found.';
1497+
break;
1498+
}
1499+
1500+
void executeGitCommand({
1501+
command: 'branch',
1502+
state: {
1503+
subcommand: 'delete',
1504+
repo: repoPath || repo!.uri.fsPath,
1505+
references: branch,
1506+
},
1507+
});
1508+
action = DeepLinkServiceAction.DeepLinkResolved;
1509+
break;
1510+
}
14651511
default: {
14661512
action = DeepLinkServiceAction.DeepLinkErrored;
14671513
message = 'Unknown state.';

src/views/viewCommands.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -945,7 +945,7 @@ export class ViewCommands implements Disposable {
945945
state: {
946946
repos: node.repo,
947947
reference: node.branch,
948-
skipWorktreeConfirmations: true,
948+
worktreeDefaultOpen: 'new',
949949
},
950950
});
951951
}

src/webviews/apps/plus/home/components/branch-card.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,9 @@ export abstract class GlBranchCardBase extends GlElement {
416416
repoPath: this.repo,
417417
branchId: this.branch.id,
418418
branchName: this.branch.name,
419+
worktree: this.branch.worktree
420+
? { name: this.branch.worktree.name, isDefault: this.branch.worktree.isDefault }
421+
: undefined,
419422
};
420423
}
421424

src/webviews/apps/plus/home/components/merge-target-status.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,9 @@ export class GlMergeTargetStatus extends LitElement {
240240
repoPath: this.branch.repoPath,
241241
branchId: this.branch.id,
242242
branchName: this.branch.name,
243+
worktree: this.branch.worktree
244+
? { name: this.branch.worktree.name, isDefault: this.branch.worktree.isDefault }
245+
: undefined,
243246
};
244247
}
245248

0 commit comments

Comments
 (0)