Skip to content

Commit d7bd82b

Browse files
committed
Refactors reference picker includes to avoid enum
1 parent 0577820 commit d7bd82b

File tree

13 files changed

+90
-90
lines changed

13 files changed

+90
-90
lines changed

src/commands/copyDeepLink.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type { GitReference } from '../git/models/reference';
66
import { getBranchNameAndRemote } from '../git/utils/branch.utils';
77
import { createReference } from '../git/utils/reference.utils';
88
import { showGenericErrorMessage } from '../messages';
9-
import { ReferencesQuickPickIncludes, showReferencePicker } from '../quickpicks/referencePicker';
9+
import { showReferencePicker2 } from '../quickpicks/referencePicker';
1010
import { showRemotePicker } from '../quickpicks/remotePicker';
1111
import { getBestRepositoryOrShowPicker } from '../quickpicks/repositoryPicker';
1212
import { command } from '../system/-webview/command';
@@ -261,22 +261,22 @@ export class CopyFileDeepLinkCommand extends ActiveEditorCommand {
261261
if (!repoPath || !filePath) return;
262262

263263
if (args?.chooseRef) {
264-
const pick = await showReferencePicker(
264+
const result = await showReferencePicker2(
265265
repoPath,
266266
`Copy Link to ${filePath} at Reference`,
267267
'Choose a reference (branch, tag, etc) to copy the file link for',
268268
{
269269
allowedAdditionalInput: { rev: true },
270-
include: ReferencesQuickPickIncludes.All,
270+
include: ['branches', 'tags', 'workingTree', 'HEAD'],
271271
},
272272
);
273273

274-
if (pick == null) {
274+
if (result.value == null) {
275275
return;
276-
} else if (pick.ref === '') {
276+
} else if (result.value.ref === '') {
277277
ref = undefined;
278278
} else {
279-
ref = pick;
279+
ref = result.value;
280280
}
281281
}
282282

src/commands/diffFolderWithRevisionFrom.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { openFolderCompare } from '../git/actions/commit';
66
import { GitUri } from '../git/gitUri';
77
import { shortenRevision } from '../git/utils/revision.utils';
88
import { showGenericErrorMessage } from '../messages';
9-
import { ReferencesQuickPickIncludes, showReferencePicker } from '../quickpicks/referencePicker';
9+
import { showReferencePicker2 } from '../quickpicks/referencePicker';
1010
import { getBestRepositoryOrShowPicker } from '../quickpicks/repositoryPicker';
1111
import { command } from '../system/-webview/command';
1212
import { isFolderUri } from '../system/-webview/path';
@@ -55,24 +55,24 @@ export class DiffFolderWithRevisionFromCommand extends ActiveEditorCommand {
5555
const gitUri = await GitUri.fromUri(uri);
5656
args.rhs = gitUri.sha ?? '';
5757
} else {
58-
const pick = await showReferencePicker(
58+
const result = await showReferencePicker2(
5959
repoPath,
6060
`Open Folder Changes with Branch or Tag${pad(GlyphChars.Dot, 2, 2)}${relativePath}`,
6161
'Choose a reference (branch, tag, etc) to compare',
6262
{
6363
allowedAdditionalInput: { rev: true },
64-
include: ReferencesQuickPickIncludes.All,
64+
include: ['branches', 'tags', 'workingTree', 'HEAD'],
6565
sort: { branches: { current: true }, tags: {} },
6666
},
6767
);
68-
if (pick?.ref == null) return;
68+
if (result.value?.ref == null) return;
6969

70-
args.rhs = pick.ref;
70+
args.rhs = result.value.ref;
7171
}
7272
}
7373

7474
if (!args.lhs) {
75-
const pick = await showReferencePicker(
75+
const result = await showReferencePicker2(
7676
repoPath,
7777
`Open Folder Changes with Branch or Tag${pad(GlyphChars.Dot, 2, 2)}${relativePath}${
7878
args.rhs ? ` at ${shortenRevision(args.rhs)}` : ''
@@ -82,13 +82,13 @@ export class DiffFolderWithRevisionFromCommand extends ActiveEditorCommand {
8282
allowedAdditionalInput: { rev: true },
8383
include:
8484
args.rhs === ''
85-
? ReferencesQuickPickIncludes.All & ~ReferencesQuickPickIncludes.WorkingTree
86-
: ReferencesQuickPickIncludes.All,
85+
? ['branches', 'tags', 'HEAD']
86+
: ['branches', 'tags', 'workingTree', 'HEAD'],
8787
},
8888
);
89-
if (pick?.ref == null) return;
89+
if (result.value?.ref == null) return;
9090

91-
args.lhs = pick.ref;
91+
args.lhs = result.value.ref;
9292

9393
// If we are trying to compare to the working tree, swap the lhs and rhs
9494
if (args.rhs !== '' && args.lhs === '') {

src/commands/explainBranch.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import type { TextEditor, Uri } from 'vscode';
22
import { ProgressLocation } from 'vscode';
33
import type { Container } from '../container';
4-
import type { GitBranchReference } from '../git/models/reference';
54
import { getBranchMergeTargetName } from '../git/utils/-webview/branch.utils';
65
import { showGenericErrorMessage } from '../messages';
76
import { prepareCompareDataForAIRequest } from '../plus/ai/aiProviderService';
8-
import { ReferencesQuickPickIncludes, showReferencePicker } from '../quickpicks/referencePicker';
7+
import { showReferencePicker2 } from '../quickpicks/referencePicker';
98
import { command } from '../system/-webview/command';
109
import { Logger } from '../system/logger';
1110
import { getNodeRepoPath } from '../views/nodes/abstract/viewNode';
@@ -52,12 +51,12 @@ export class ExplainBranchCommand extends ExplainCommandBase {
5251
// Clarifying the head branch
5352
if (args.ref == null) {
5453
// If no ref is provided, show a picker to select a branch
55-
const pick = (await showReferencePicker(svc.path, this.pickerTitle, 'Choose a branch to explain', {
56-
include: ReferencesQuickPickIncludes.Branches,
54+
const result = await showReferencePicker2(svc.path, this.pickerTitle, 'Choose a branch to explain', {
55+
include: ['branches'],
5756
sort: { branches: { current: true } },
58-
})) as GitBranchReference | undefined;
59-
if (pick?.ref == null) return;
60-
args.ref = pick.ref;
57+
});
58+
if (result.value?.ref == null) return;
59+
args.ref = result.value.ref;
6160
}
6261

6362
// Get the branch

src/commands/git/search.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { showContributorsPicker } from '../../quickpicks/contributorsPicker';
1212
import type { QuickPickItemOfT } from '../../quickpicks/items/common';
1313
import { ActionQuickPickItem, createQuickPickSeparator } from '../../quickpicks/items/common';
1414
import { isDirectiveQuickPickItem } from '../../quickpicks/items/directive';
15-
import { ReferencesQuickPickIncludes, showReferencePicker2 } from '../../quickpicks/referencePicker';
15+
import { showReferencePicker2 } from '../../quickpicks/referencePicker';
1616
import { configuration } from '../../system/-webview/configuration';
1717
import { getContext } from '../../system/-webview/context';
1818
import { first, join, map } from '../../system/iterable';
@@ -625,7 +625,7 @@ async function updateSearchQuery(
625625
'Choose a reference to search',
626626
{
627627
allowedAdditionalInput: { range: true, rev: false },
628-
include: ReferencesQuickPickIncludes.All,
628+
include: ['branches', 'tags', 'HEAD'],
629629
picked: refs && first(refs),
630630
},
631631
);

src/commands/openBranchOnRemote.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { RemoteResourceType } from '../git/models/remoteResource';
55
import { getBranchNameWithoutRemote, getRemoteNameFromBranchName } from '../git/utils/branch.utils';
66
import { showGenericErrorMessage } from '../messages';
77
import { CommandQuickPickItem } from '../quickpicks/items/common';
8-
import { ReferencesQuickPickIncludes, showReferencePicker } from '../quickpicks/referencePicker';
8+
import { showReferencePicker2 } from '../quickpicks/referencePicker';
99
import { getBestRepositoryOrShowPicker } from '../quickpicks/repositoryPicker';
1010
import { command, executeCommand } from '../system/-webview/command';
1111
import { Logger } from '../system/logger';
@@ -62,19 +62,21 @@ export class OpenBranchOnRemoteCommand extends ActiveEditorCommand {
6262

6363
try {
6464
if (args.branch == null) {
65-
const pick = await showReferencePicker(
65+
const result = await showReferencePicker2(
6666
repoPath,
6767
args.clipboard ? 'Copy Remote Branch URL' : 'Open Branch On Remote',
6868
args.clipboard ? 'Choose a branch to copy the URL from' : 'Choose a branch to open',
6969
{
7070
autoPick: true,
7171
// checkmarks: false,
7272
filter: { branches: b => b.upstream != null },
73-
include: ReferencesQuickPickIncludes.Branches,
73+
include: ['branches'],
7474
sort: { branches: { current: true }, tags: {} },
7575
},
7676
);
77-
if (pick == null || pick instanceof CommandQuickPickItem) return;
77+
if (result.value == null || result.value instanceof CommandQuickPickItem) return;
78+
79+
const pick = result.value;
7880

7981
if (pick.refType === 'branch') {
8082
if (pick.remote || (pick.upstream != null && !pick.upstream.missing)) {

src/commands/recomposeBranch.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { window } from 'vscode';
22
import type { Sources } from '../constants.telemetry';
33
import type { Container } from '../container';
44
import { CommandQuickPickItem } from '../quickpicks/items/common';
5-
import { ReferencesQuickPickIncludes, showReferencePicker } from '../quickpicks/referencePicker';
5+
import { showReferencePicker2 } from '../quickpicks/referencePicker';
66
import { getBestRepositoryOrShowPicker } from '../quickpicks/repositoryPicker';
77
import { command, executeCommand } from '../system/-webview/command';
88
import { getNodeRepoPath } from '../views/nodes/abstract/viewNode';
@@ -47,12 +47,18 @@ export class RecomposeBranchCommand extends GlCommandBase {
4747
// Get branch name using picker fallback
4848
let branchName = args.branchName;
4949
if (!branchName) {
50-
const pick = await showReferencePicker(repoPath, 'Recompose Branch', 'Choose a branch to recompose', {
51-
include: ReferencesQuickPickIncludes.Branches,
52-
sort: { branches: { current: true } },
53-
});
54-
if (pick == null || pick instanceof CommandQuickPickItem) return;
50+
const result = await showReferencePicker2(
51+
repoPath,
52+
'Recompose Branch',
53+
'Choose a branch to recompose',
54+
{
55+
include: ['branches'],
56+
sort: { branches: { current: true } },
57+
},
58+
);
59+
if (result.value == null || result.value instanceof CommandQuickPickItem) return;
5560

61+
const pick = result.value;
5662
if (pick.refType === 'branch') {
5763
branchName = pick.name;
5864
} else {

src/quickpicks/comparisonPicker.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { getBranchMergeTargetInfo } from '../git/utils/-webview/branch.utils';
44
import { createReference, getReferenceLabel, isBranchReference } from '../git/utils/reference.utils';
55
import { getRevisionRangeParts, isRevisionRange } from '../git/utils/revision.utils';
66
import { Directive } from './items/directive';
7-
import { ReferencesQuickPickIncludes, showReferencePicker2 } from './referencePicker';
7+
import { showReferencePicker2 } from './referencePicker';
88
import { getRepositoryOrShowPicker } from './repositoryPicker';
99

1010
export interface ComparisonPickerOptions {
@@ -48,7 +48,7 @@ export async function showComparisonPicker(
4848
if (head == null || force) {
4949
const pick = await showReferencePicker2(repoPath, title, placeholder, {
5050
allowedAdditionalInput: { range: true, rev: true },
51-
include: ReferencesQuickPickIncludes.BranchesAndTags | ReferencesQuickPickIncludes.HEAD,
51+
include: ['branches', 'tags', 'HEAD'],
5252
picked: head?.ref,
5353
sort: { branches: { current: true } },
5454
});
@@ -96,7 +96,7 @@ export async function showComparisonPicker(
9696
allowBack: true,
9797
allowedAdditionalInput: { rev: true },
9898
exclude: [head.ref],
99-
include: ReferencesQuickPickIncludes.BranchesAndTags | ReferencesQuickPickIncludes.HEAD,
99+
include: ['branches', 'tags', 'HEAD'],
100100
picked: base?.ref,
101101
sort: { branches: { current: true } },
102102
});

src/quickpicks/contributorsPicker.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,20 @@ import { debounce } from '../system/function/debounce';
1313
import { defer } from '../system/promise';
1414
import { pad, truncate } from '../system/string';
1515

16+
export interface ContributorQuickPickOptions {
17+
appendReposToTitle?: boolean;
18+
clearButton?: boolean;
19+
ignoreFocusOut?: boolean;
20+
multiselect?: boolean;
21+
picked?: (contributor: GitContributor) => boolean;
22+
}
23+
1624
export async function showContributorsPicker(
1725
container: Container,
1826
repository: Repository,
1927
title: string,
2028
placeholder: string,
21-
options?: {
22-
appendReposToTitle?: boolean;
23-
clearButton?: boolean;
24-
ignoreFocusOut?: boolean;
25-
multiselect?: boolean;
26-
picked?: (contributor: GitContributor) => boolean;
27-
},
29+
options?: ContributorQuickPickOptions,
2830
): Promise<GitContributor[] | undefined> {
2931
const deferred = defer<GitContributor[] | undefined>();
3032
const disposables: Disposable[] = [];

src/quickpicks/referencePicker.ts

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,15 @@ import type { BranchQuickPickItem, RefQuickPickItem, TagQuickPickItem } from './
2222
import { createRefQuickPickItem } from './items/gitWizard';
2323

2424
export type ReferencesQuickPickItem = BranchQuickPickItem | TagQuickPickItem | RefQuickPickItem;
25-
26-
export const enum ReferencesQuickPickIncludes {
27-
Branches = 1 << 0,
28-
Tags = 1 << 1,
29-
WorkingTree = 1 << 2,
30-
HEAD = 1 << 3,
31-
32-
AllBranches = 1 << 4,
33-
34-
BranchesAndTags = Branches | Tags,
35-
All = Branches | Tags | WorkingTree | HEAD,
36-
}
25+
export type ReferencesQuickPickIncludes = 'branches' | 'tags' | 'workingTree' | 'HEAD' | 'allBranches';
3726

3827
export interface ReferencesQuickPickOptions {
3928
allowedAdditionalInput?: { range?: boolean; rev?: boolean };
4029
autoPick?: boolean;
4130
picked?: string;
4231
exclude?: string[];
4332
filter?: { branches?(b: GitBranch): boolean; tags?(t: GitTag): boolean };
44-
include?: ReferencesQuickPickIncludes;
33+
include?: ReferencesQuickPickIncludes[];
4534
ignoreFocusOut?: boolean;
4635
keyboard?: {
4736
keys: Keys[];
@@ -50,8 +39,9 @@ export interface ReferencesQuickPickOptions {
5039
sort?: boolean | { branches?: BranchSortOptions; tags?: TagSortOptions };
5140
}
5241

53-
export interface ReferencesQuickPickOptions2 extends ReferencesQuickPickOptions {
42+
export interface ReferencesQuickPickOptions2 extends Omit<ReferencesQuickPickOptions, 'include'> {
5443
allowBack?: boolean;
44+
include?: ReferencesQuickPickIncludes[];
5545
}
5646

5747
export async function showReferencePicker(
@@ -218,13 +208,13 @@ async function getItems(
218208
repoPath: string,
219209
options?: ReferencesQuickPickOptions2,
220210
): Promise<(ReferencesQuickPickItem | DirectiveQuickPickItem)[]> {
221-
const include = options?.include ?? ReferencesQuickPickIncludes.BranchesAndTags;
211+
const include = options?.include ?? ['branches', 'tags'];
222212

223213
const includes: ('branches' | 'tags')[] = [];
224-
if (include & ReferencesQuickPickIncludes.Branches) {
214+
if (include.includes('branches')) {
225215
includes.push('branches');
226216
}
227-
if (include & ReferencesQuickPickIncludes.Tags) {
217+
if (include.includes('tags')) {
228218
includes.push('tags');
229219
}
230220

@@ -248,15 +238,15 @@ async function getItems(
248238
}
249239
}
250240

251-
if (include & ReferencesQuickPickIncludes.HEAD) {
241+
if (include.includes('HEAD')) {
252242
items.unshift(createRefQuickPickItem('HEAD', repoPath, undefined, { icon: true }));
253243
}
254244

255-
if (include & ReferencesQuickPickIncludes.WorkingTree) {
245+
if (include.includes('workingTree')) {
256246
items.unshift(createRefQuickPickItem('', repoPath, undefined, { icon: true }));
257247
}
258248

259-
if (include & ReferencesQuickPickIncludes.AllBranches) {
249+
if (include.includes('allBranches')) {
260250
items.unshift(createQuickPickSeparator());
261251
items.unshift(createDirectiveQuickPickItem(Directive.RefsAllBranches));
262252
}

0 commit comments

Comments
 (0)