Skip to content

Commit 8dd9502

Browse files
committed
fix: nothing to stash but stash list exists
1 parent 01451fa commit 8dd9502

File tree

2 files changed

+13
-18
lines changed

2 files changed

+13
-18
lines changed

lib/src/git.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ Future<String> execGit(
4949
final result =
5050
await Process.run('git', gitArgs, workingDirectory: workingDirectory);
5151
if (result.exitCode != 0) {
52-
throw Exception('execGit ${result.stderr}');
52+
throw Exception('execGit exit ${result.exitCode}, ${result.stderr}');
5353
}
5454
String output = result.stdout as String;
5555
if (output.endsWith('\n')) {

lib/src/git_workflow.dart

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class GitWorkflow {
6868

6969
late List<String> partiallyStagedFiles;
7070
late List<String> deletedFiles;
71+
late bool nothingToStash;
7172

7273
String? workingDirectory;
7374

@@ -108,10 +109,6 @@ class GitWorkflow {
108109
Future<String> getBackupStash(LintStagedContext ctx) async {
109110
final stashes =
110111
await execGit(['stash', 'list'], workingDirectory: workingDirectory);
111-
112-
if (stashes.isEmpty) {
113-
return '';
114-
}
115112
final index =
116113
stashes.split('\n').indexWhere((line) => line.contains(kStashMessage));
117114
if (index == -1) {
@@ -265,16 +262,16 @@ class GitWorkflow {
265262
/// and `stash store` saves it as an actual stash.
266263
final stash = await execGit(['stash', 'create'],
267264
workingDirectory: workingDirectory);
265+
nothingToStash = stash.isEmpty;
268266

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 {
271271
await execGit(
272272
['stash', 'store', '--quiet', '--message', kStashMessage, stash],
273273
workingDirectory: workingDirectory);
274-
} else {
275-
verbose('Nothing to stash.');
276274
}
277-
278275
verbose('Done backing up original state!');
279276
} catch (e) {
280277
handleError(e, ctx);
@@ -391,16 +388,14 @@ class GitWorkflow {
391388
/// Drop the created stashes after everything has run
392389
///
393390
Future<void> cleanup(LintStagedContext ctx) async {
391+
if (nothingToStash) {
392+
verbose('Nothing has been stashed');
393+
return;
394+
}
394395
try {
395396
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);
404399
verbose('Done dropping backup stash!');
405400
} catch (error) {
406401
handleError(error, ctx);

0 commit comments

Comments
 (0)