@@ -68,6 +68,7 @@ class GitWorkflow {
68
68
69
69
late List <String > partiallyStagedFiles;
70
70
late List <String > deletedFiles;
71
+ late bool nothingToStash;
71
72
72
73
String ? workingDirectory;
73
74
@@ -108,10 +109,6 @@ class GitWorkflow {
108
109
Future <String > getBackupStash (LintStagedContext ctx) async {
109
110
final stashes =
110
111
await execGit (['stash' , 'list' ], workingDirectory: workingDirectory);
111
-
112
- if (stashes.isEmpty) {
113
- return '' ;
114
- }
115
112
final index =
116
113
stashes.split ('\n ' ).indexWhere ((line) => line.contains (kStashMessage));
117
114
if (index == - 1 ) {
@@ -265,16 +262,16 @@ class GitWorkflow {
265
262
/// and `stash store` saves it as an actual stash.
266
263
final stash = await execGit (['stash' , 'create' ],
267
264
workingDirectory: workingDirectory);
265
+ nothingToStash = stash.isEmpty;
268
266
269
- /// When there's nothing to stash, just skip.
270
- if (stash.isNotEmpty) {
267
+ /// Whether there's nothing to stash.
268
+ if (nothingToStash) {
269
+ verbose ('Nothing to stash.' );
270
+ } else {
271
271
await execGit (
272
272
['stash' , 'store' , '--quiet' , '--message' , kStashMessage, stash],
273
273
workingDirectory: workingDirectory);
274
- } else {
275
- verbose ('Nothing to stash.' );
276
274
}
277
-
278
275
verbose ('Done backing up original state!' );
279
276
} catch (e) {
280
277
handleError (e, ctx);
@@ -391,16 +388,14 @@ class GitWorkflow {
391
388
/// Drop the created stashes after everything has run
392
389
///
393
390
Future <void > cleanup (LintStagedContext ctx) async {
391
+ if (nothingToStash) {
392
+ verbose ('Nothing has been stashed' );
393
+ return ;
394
+ }
394
395
try {
395
396
verbose ('Dropping backup stash...' );
396
- final stash = await getBackupStash (ctx);
397
- if (stash.isNotEmpty) {
398
- await execGit ([
399
- 'stash' ,
400
- 'drop' ,
401
- '--quiet' ,
402
- ], workingDirectory: workingDirectory);
403
- }
397
+ await execGit (['stash' , 'drop' , '--quiet' , await getBackupStash (ctx)],
398
+ workingDirectory: workingDirectory);
404
399
verbose ('Done dropping backup stash!' );
405
400
} catch (error) {
406
401
handleError (error, ctx);
0 commit comments