Skip to content

Commit 6ab7426

Browse files
committed
Consolidates to a single stash picker
Adds inline buttons to stash & commit picker Ensures stash view & pickers show proper empty state
1 parent 24a6a13 commit 6ab7426

File tree

12 files changed

+206
-255
lines changed

12 files changed

+206
-255
lines changed

src/commands/diffWithRevisionFrom.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import { GitUri } from '../git/gitUri';
66
import { isBranchReference } from '../git/utils/reference.utils';
77
import { shortenRevision } from '../git/utils/revision.utils';
88
import { showNoRepositoryWarningMessage } from '../messages';
9-
import { showStashPicker } from '../quickpicks/commitPicker';
109
import { showReferencePicker } from '../quickpicks/referencePicker';
10+
import { showStashPicker } from '../quickpicks/stashPicker';
1111
import { command, executeCommand } from '../system/-webview/command';
1212
import { selectionToDiffRange } from '../system/-webview/vscode/editors';
1313
import { basename } from '../system/path';

src/commands/explainStash.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,11 @@ export class ExplainStashCommand extends GlCommandBase {
6363
try {
6464
let commit: GitCommit | undefined;
6565
if (args.rev == null) {
66-
const pick = await showStashPicker('Explain Stash Changes', 'Choose a stash to explain', repository);
66+
const pick = await showStashPicker(
67+
repository.git.stash?.getStash(),
68+
'Explain Stash Changes',
69+
'Choose a stash to explain',
70+
);
6771
if (pick?.ref == null) return;
6872
args.rev = pick.ref;
6973
commit = pick;

src/commands/git/stash.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ export class StashGitCommand extends QuickCommand<State> {
324324
while (this.canStepsContinue(state)) {
325325
if (state.counter < 3 || state.reference == null) {
326326
const result: StepResult<GitStashReference> = yield* pickStashStep(state, context, {
327-
gitStash: await state.repo.git.stash?.getStash(),
327+
stash: await state.repo.git.stash?.getStash(),
328328
placeholder: (_context, stash) =>
329329
stash == null
330330
? `No stashes found in ${state.repo.formattedName}`
@@ -429,7 +429,7 @@ export class StashGitCommand extends QuickCommand<State> {
429429
while (this.canStepsContinue(state)) {
430430
if (state.counter < 3 || !state.references?.length) {
431431
const result: StepResult<GitStashReference[]> = yield* pickStashesStep(state, context, {
432-
gitStash: await state.repo.git.stash?.getStash(),
432+
stash: await state.repo.git.stash?.getStash(),
433433
placeholder: (_context, stash) =>
434434
stash == null ? `No stashes found in ${state.repo.formattedName}` : 'Choose stashes to delete',
435435
picked: state.references?.map(r => r.ref),
@@ -488,7 +488,7 @@ export class StashGitCommand extends QuickCommand<State> {
488488
while (this.canStepsContinue(state)) {
489489
if (state.counter < 3 || state.reference == null) {
490490
const result: StepResult<GitStashCommit> = yield* pickStashStep(state, context, {
491-
gitStash: await state.repo.git.stash?.getStash(),
491+
stash: await state.repo.git.stash?.getStash(),
492492
placeholder: (_context, stash) =>
493493
stash == null ? `No stashes found in ${state.repo.formattedName}` : 'Choose a stash',
494494
picked: state.reference?.ref,
@@ -790,7 +790,7 @@ export class StashGitCommand extends QuickCommand<State> {
790790
while (this.canStepsContinue(state)) {
791791
if (state.counter < 3 || state.reference == null) {
792792
const result: StepResult<GitStashReference> = yield* pickStashStep(state, context, {
793-
gitStash: await state.repo.git.stash?.getStash(),
793+
stash: await state.repo.git.stash?.getStash(),
794794
placeholder: (_context, stash) =>
795795
stash == null ? `No stashes found in ${state.repo.formattedName}` : 'Choose a stash to rename',
796796
picked: state.reference?.ref,

src/commands/openFileAtRevisionFrom.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import { openFileAtRevision } from '../git/actions/commit';
66
import { GitUri } from '../git/gitUri';
77
import type { GitReference } from '../git/models/reference';
88
import { showNoRepositoryWarningMessage } from '../messages';
9-
import { showStashPicker } from '../quickpicks/commitPicker';
109
import { showReferencePicker } from '../quickpicks/referencePicker';
10+
import { showStashPicker } from '../quickpicks/stashPicker';
1111
import { command } from '../system/-webview/command';
1212
import { pad } from '../system/string';
1313
import { ActiveEditorCommand } from './commandBase';

src/commands/quickCommand.steps.ts

Lines changed: 36 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1764,41 +1764,40 @@ export function* pickStashStep<
17641764
context: Context,
17651765
{
17661766
ignoreFocusOut,
1767-
gitStash,
1767+
stash,
17681768
picked,
17691769
placeholder,
17701770
title,
17711771
}: {
17721772
ignoreFocusOut?: boolean;
1773-
gitStash: GitStash | undefined;
1773+
stash: GitStash | undefined;
17741774
picked: string | string[] | undefined;
17751775
placeholder: string | ((context: Context, stash: GitStash | undefined) => string);
17761776
title?: string;
17771777
},
17781778
): StepResultGenerator<GitStashCommit> {
17791779
const step = createPickStep<CommitQuickPickItem<GitStashCommit>>({
17801780
title: appendReposToTitle(title ?? context.title, state, context),
1781-
placeholder: typeof placeholder === 'string' ? placeholder : placeholder(context, gitStash),
1781+
placeholder: typeof placeholder === 'string' ? placeholder : placeholder(context, stash),
17821782
ignoreFocusOut: ignoreFocusOut,
17831783
matchOnDescription: true,
17841784
matchOnDetail: true,
1785-
items:
1786-
gitStash == null
1787-
? [createDirectiveQuickPickItem(Directive.Back, true), createDirectiveQuickPickItem(Directive.Cancel)]
1788-
: [
1789-
...map(gitStash.stashes.values(), stash =>
1790-
createStashQuickPickItem(
1791-
stash,
1792-
picked != null &&
1793-
(typeof picked === 'string' ? stash.ref === picked : picked.includes(stash.ref)),
1794-
{
1795-
buttons: [ShowDetailsViewQuickInputButton],
1796-
compact: true,
1797-
icon: true,
1798-
},
1799-
),
1785+
items: !stash?.stashes.size
1786+
? [createDirectiveQuickPickItem(Directive.Back, true), createDirectiveQuickPickItem(Directive.Cancel)]
1787+
: [
1788+
...map(stash.stashes.values(), stash =>
1789+
createStashQuickPickItem(
1790+
stash,
1791+
picked != null &&
1792+
(typeof picked === 'string' ? stash.ref === picked : picked.includes(stash.ref)),
1793+
{
1794+
buttons: [ShowDetailsViewQuickInputButton],
1795+
compact: true,
1796+
icon: true,
1797+
},
18001798
),
1801-
],
1799+
),
1800+
],
18021801
onDidClickItemButton: (_quickpick, button, { item }) => {
18031802
if (button === ShowDetailsViewQuickInputButton) {
18041803
void StashActions.showDetailsView(item, { pin: false, preserveFocus: true });
@@ -1822,13 +1821,13 @@ export function* pickStashesStep<
18221821
context: Context,
18231822
{
18241823
ignoreFocusOut,
1825-
gitStash,
1824+
stash,
18261825
picked,
18271826
placeholder,
18281827
title,
18291828
}: {
18301829
ignoreFocusOut?: boolean;
1831-
gitStash: GitStash | undefined;
1830+
stash: GitStash | undefined;
18321831
picked: string | string[] | undefined;
18331832
placeholder: string | ((context: Context, stash: GitStash | undefined) => string);
18341833
title?: string;
@@ -1837,27 +1836,26 @@ export function* pickStashesStep<
18371836
const step = createPickStep<CommitQuickPickItem<GitStashCommit>>({
18381837
title: appendReposToTitle(title ?? context.title, state, context),
18391838
multiselect: true,
1840-
placeholder: typeof placeholder === 'string' ? placeholder : placeholder(context, gitStash),
1839+
placeholder: typeof placeholder === 'string' ? placeholder : placeholder(context, stash),
18411840
ignoreFocusOut: ignoreFocusOut,
18421841
matchOnDescription: true,
18431842
matchOnDetail: true,
1844-
items:
1845-
gitStash == null
1846-
? [createDirectiveQuickPickItem(Directive.Back, true), createDirectiveQuickPickItem(Directive.Cancel)]
1847-
: [
1848-
...map(gitStash.stashes.values(), stash =>
1849-
createStashQuickPickItem(
1850-
stash,
1851-
picked != null &&
1852-
(typeof picked === 'string' ? stash.ref === picked : picked.includes(stash.ref)),
1853-
{
1854-
buttons: [ShowDetailsViewQuickInputButton],
1855-
compact: true,
1856-
icon: true,
1857-
},
1858-
),
1843+
items: !stash?.stashes.size
1844+
? [createDirectiveQuickPickItem(Directive.Back, true), createDirectiveQuickPickItem(Directive.Cancel)]
1845+
: [
1846+
...map(stash.stashes.values(), stash =>
1847+
createStashQuickPickItem(
1848+
stash,
1849+
picked != null &&
1850+
(typeof picked === 'string' ? stash.ref === picked : picked.includes(stash.ref)),
1851+
{
1852+
buttons: [ShowDetailsViewQuickInputButton],
1853+
compact: true,
1854+
icon: true,
1855+
},
18591856
),
1860-
],
1857+
),
1858+
],
18611859
onDidClickItemButton: (_quickpick, button, { item }) => {
18621860
if (button === ShowDetailsViewQuickInputButton) {
18631861
void StashActions.showDetailsView(item, { pin: false, preserveFocus: true });

src/env/node/git/sub-providers/stash.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ export class StashGitSubProvider implements GitStashSubProvider {
7373
): Promise<GitStash | undefined> {
7474
if (repoPath == null) return undefined;
7575

76-
let gitStash = this.cache.stashes?.get(repoPath);
77-
if (gitStash == null) {
76+
let stash = this.cache.stashes?.get(repoPath);
77+
if (stash == null) {
7878
const parser = getStashLogParser();
7979
const args = [...parser.arguments];
8080

@@ -89,17 +89,17 @@ export class StashGitSubProvider implements GitStashSubProvider {
8989
stashes.set(s.sha, createStash(this.container, s, repoPath));
9090
}
9191

92-
gitStash = { repoPath: repoPath, stashes: stashes };
92+
stash = { repoPath: repoPath, stashes: stashes };
9393

94-
this.cache.stashes?.set(repoPath, gitStash);
94+
this.cache.stashes?.set(repoPath, stash);
9595
}
9696

9797
// Return only reachable stashes from the given ref
98-
if (options?.reachableFrom && gitStash?.stashes.size) {
98+
if (options?.reachableFrom && stash?.stashes.size) {
9999
// Create a copy because we are going to modify it and we don't want to mutate the cache
100-
gitStash = { ...gitStash, stashes: new Map(gitStash.stashes) };
100+
stash = { ...stash, stashes: new Map(stash.stashes) };
101101

102-
const oldestStashDate = new Date(min(gitStash.stashes.values(), c => c.date.getTime())).toISOString();
102+
const oldestStashDate = new Date(min(stash.stashes.values(), c => c.date.getTime())).toISOString();
103103

104104
const result = await this.git.exec(
105105
{ cwd: repoPath, cancellation: cancellation, errors: GitErrorHandling.Ignore },
@@ -118,8 +118,8 @@ export class StashGitSubProvider implements GitStashSubProvider {
118118
const reachableStashes = new Set<string>();
119119

120120
// First pass: mark directly reachable stashes
121-
for (const [sha, stash] of gitStash.stashes) {
122-
if (stash.parents.some(p => p === options.reachableFrom || reachableCommits.has(p))) {
121+
for (const [sha, s] of stash.stashes) {
122+
if (s.parents.some(p => p === options.reachableFrom || reachableCommits.has(p))) {
123123
reachableStashes.add(sha);
124124
}
125125
}
@@ -128,27 +128,27 @@ export class StashGitSubProvider implements GitStashSubProvider {
128128
let changed;
129129
do {
130130
changed = false;
131-
for (const [sha, stash] of gitStash.stashes) {
132-
if (!reachableStashes.has(sha) && stash.parents.some(p => reachableStashes.has(p))) {
131+
for (const [sha, s] of stash.stashes) {
132+
if (!reachableStashes.has(sha) && s.parents.some(p => reachableStashes.has(p))) {
133133
reachableStashes.add(sha);
134134
changed = true;
135135
}
136136
}
137137
} while (changed);
138138

139139
// Remove unreachable stashes
140-
for (const [sha] of gitStash.stashes) {
140+
for (const [sha] of stash.stashes) {
141141
if (!reachableStashes.has(sha)) {
142-
gitStash.stashes.delete(sha);
142+
stash.stashes.delete(sha);
143143
}
144144
}
145145
} else {
146-
gitStash.stashes.clear();
146+
stash.stashes.clear();
147147
}
148148
}
149149
}
150150

151-
return gitStash;
151+
return stash;
152152
}
153153

154154
@log()

0 commit comments

Comments
 (0)