Skip to content

Commit 239dbbc

Browse files
authored
feat: add multi drop support (#132)
1 parent 3ceb943 commit 239dbbc

File tree

6 files changed

+95
-20
lines changed

6 files changed

+95
-20
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ You don't need to use the explorer buttons, just type `gitstash` in the command
4242
- gitstash: Branch...
4343
- gitstash: Clear...
4444
- gitstash: Drop...
45+
- gitstash: Drop Multiple...
4546
- gitstash: Pop...
4647
- gitstash: Refresh explorer
4748
- gitstash: Toggle explorer

package.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,12 @@
344344
"category": "GitStash",
345345
"icon": "$(trash)"
346346
},
347+
{
348+
"command": "gitstash.multiDrop",
349+
"title": "Drop multiple...",
350+
"category": "GitStash",
351+
"icon": "$(trash)"
352+
},
347353
{
348354
"command": "gitstash.branch",
349355
"title": "Branch...",
@@ -491,6 +497,10 @@
491497
"command": "gitstash.drop",
492498
"when": "hasGitRepository"
493499
},
500+
{
501+
"command": "gitstash.multiDrop",
502+
"when": "hasGitRepository"
503+
},
494504
{
495505
"command": "gitstash.applySingle",
496506
"when": "false"
@@ -593,6 +603,11 @@
593603
"when": "view == gitstash.explorer && viewItem == repository",
594604
"group": "menu@1"
595605
},
606+
{
607+
"command": "gitstash.multiDrop",
608+
"when": "view == gitstash.explorer && viewItem == repository",
609+
"group": "menu@2"
610+
},
596611
{
597612
"command": "gitstash.apply",
598613
"when": "view == gitstash.explorer && viewItem == stash && config.gitstash.explorer.items.stash.popAndApply == apply",
6.04 KB
Loading

src/Commands.ts

Lines changed: 77 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ export class Commands {
113113
void this.runOnRepository(
114114
repositoryNode,
115115
(repositoryNode: RepositoryNode) => { this.stashPerform(repositoryNode) },
116-
'Create stash',
116+
'Create Stash',
117117
)
118118
}
119119

@@ -126,7 +126,7 @@ export class Commands {
126126
void this.runOnRepository(
127127
repositoryNode,
128128
(repositoryNode: RepositoryNode) => { this.clearPerform(repositoryNode) },
129-
'Clear stashes',
129+
'Drop All Stashes',
130130
)
131131
}
132132

@@ -139,7 +139,7 @@ export class Commands {
139139
this.runOnStash(
140140
stashNode,
141141
(stashNode: StashNode) => { this.popPerform(stashNode) },
142-
'Stash pop',
142+
'Pop Stash',
143143
)
144144
}
145145

@@ -152,7 +152,7 @@ export class Commands {
152152
this.runOnStash(
153153
stashNode,
154154
(stashNode: StashNode) => { this.applyPerform(stashNode) },
155-
'Stash apply',
155+
'Apply Stash',
156156
)
157157
}
158158

@@ -165,7 +165,7 @@ export class Commands {
165165
this.runOnStash(
166166
stashNode,
167167
(stashNode: StashNode) => { this.branchPerform(stashNode) },
168-
'Stash branch',
168+
'Branch Stash',
169169
)
170170
}
171171

@@ -178,7 +178,21 @@ export class Commands {
178178
this.runOnStash(
179179
stashNode,
180180
(stashNode: StashNode) => { this.dropPerform(stashNode) },
181-
'Stash drop',
181+
'Drop stash',
182+
)
183+
}
184+
185+
/**
186+
* Drops the currently selected stash or selects one and continue.
187+
*
188+
* @param stashNode the involved node
189+
*/
190+
public multiDrop = (): void => {
191+
this.runOnStash(
192+
undefined,
193+
(...nodes: StashNode[]) => { this.multiDropPerform(...nodes) },
194+
'Drop Multiple Stashes',
195+
true,
182196
)
183197
}
184198

@@ -229,12 +243,16 @@ export class Commands {
229243
]
230244

231245
void vscode.window
232-
.showQuickPick(opts, { placeHolder: `Create stash › ${repositoryLabel} › ...` })
246+
.showQuickPick(opts, {
247+
title: 'Create Stash',
248+
placeHolder: `${repositoryLabel} › ...`,
249+
})
233250
.then((option) => {
234251
if (typeof option !== 'undefined') {
235252
void vscode.window
236253
.showInputBox({
237-
placeHolder: `Create stash › ${repositoryLabel}${option.label} › ...`,
254+
title: 'Create Stash',
255+
placeHolder: `${repositoryLabel}${option.label} › ...`,
238256
prompt: 'Optionally provide a stash message',
239257
})
240258
.then((stashMessage) => {
@@ -293,13 +311,15 @@ export class Commands {
293311
withIndex: true,
294312
},
295313
],
296-
{ placeHolder: `Stash pop › ${repositoryLabel}${stashLabel} › ...` },
297-
)
298-
.then((option) => {
299-
if (typeof option !== 'undefined') {
300-
this.stashCommands.pop(stashNode, option.withIndex)
301-
}
302-
})
314+
{
315+
title: 'Pop Stash',
316+
placeHolder: `${repositoryLabel}${stashLabel} › ...`,
317+
},
318+
).then((option) => {
319+
if (typeof option !== 'undefined') {
320+
this.stashCommands.pop(stashNode, option.withIndex)
321+
}
322+
})
303323
}
304324

305325
/**
@@ -324,7 +344,10 @@ export class Commands {
324344
withIndex: true,
325345
},
326346
],
327-
{ placeHolder: `Stash apply › ${repositoryLabel}${stashLabel} › ...` },
347+
{
348+
title: 'Apply Stash',
349+
placeHolder: `${repositoryLabel}${stashLabel} › ...`,
350+
},
328351
)
329352
.then((option) => {
330353
if (typeof option !== 'undefined') {
@@ -344,7 +367,8 @@ export class Commands {
344367

345368
void vscode.window
346369
.showInputBox({
347-
placeHolder: `Stash apply › ${repositoryLabel}${stashLabel} › ...`,
370+
title: 'Apply Stash',
371+
placeHolder: `${repositoryLabel}${stashLabel} › ...`,
348372
prompt: 'Write a name',
349373
})
350374
.then((branchName) => {
@@ -380,6 +404,35 @@ export class Commands {
380404
})
381405
}
382406

407+
private multiDropPerform = (...nodes: StashNode[]): void => {
408+
if (!nodes.length) {
409+
vscode.window.showInformationMessage('Nothing to drop.')
410+
return
411+
}
412+
413+
const textList = nodes
414+
.map((node) => this.stashLabels.getName(node))
415+
.join('\n')
416+
417+
const msg = `Are you sure you want to drop the stashes?\n${textList}`
418+
419+
void vscode.window.showWarningMessage<vscode.MessageItem>(
420+
msg,
421+
{ modal: true },
422+
{ title: 'Yes' },
423+
).then((option) => {
424+
if (typeof option !== 'undefined') {
425+
nodes
426+
// Higher index first.
427+
.sort((a, b) => a.index > b.index ? -1 : (a.index < b.index ? 1 : 0))
428+
.forEach((node) => {
429+
console.log(`Multi-dropping ${node.atIndex}`)
430+
this.stashCommands.drop(node)
431+
})
432+
}
433+
})
434+
}
435+
383436
/**
384437
* Applies the changes on the stashed file.
385438
*
@@ -500,7 +553,11 @@ export class Commands {
500553

501554
const selection = await vscode.window.showQuickPick<QuickPickRepositoryNodeItem>(
502555
items,
503-
{ placeHolder: `${pickerPlaceholder} › ...`, canPickMany: false },
556+
{
557+
title: pickerPlaceholder,
558+
placeHolder: '› Select Repository',
559+
canPickMany: false,
560+
},
504561
)
505562

506563
if (selection) {
@@ -557,7 +614,8 @@ export class Commands {
557614
}
558615

559616
const options = {
560-
placeHolder: `${placeholder}${repositoryLabel} › ...`,
617+
title: placeholder,
618+
placeHolder: `${repositoryLabel} › ...`,
561619
canPickMany,
562620
}
563621

src/StashCommands.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export class StashCommands {
5959

6060
switch (type) {
6161
case StashType.Staged:
62-
params.push('--staged')
62+
params.push('--staged') // requires git v2.35
6363
break
6464
case StashType.KeepIndex:
6565
params.push('--keep-index')

src/extension.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ export function activate(context: ExtensionContext): void {
7979
commands.registerCommand('gitstash.apply', stashCommands.apply),
8080
commands.registerCommand('gitstash.branch', stashCommands.branch),
8181
commands.registerCommand('gitstash.drop', stashCommands.drop),
82+
commands.registerCommand('gitstash.multiDrop', stashCommands.multiDrop),
8283

8384
commands.registerCommand('gitstash.applySingle', stashCommands.applySingle),
8485
commands.registerCommand('gitstash.createSingle', stashCommands.createSingle),

0 commit comments

Comments
 (0)