1
1
import 'dart:math' ;
2
- import 'package:lint_staged/src/logger.dart' ;
3
- import 'package:lint_staged/src/symbols.dart' ;
4
2
import 'package:path/path.dart' ;
3
+ import 'package:verbose/verbose.dart' ;
5
4
5
+ import 'context.dart' ;
6
6
import 'file.dart' ;
7
7
import 'git.dart' ;
8
- import 'context .dart' ;
8
+ import 'symbols .dart' ;
9
9
10
10
/// In git status machine output, renames are presented as `to` NUL`from`
11
11
/// When diffing, both need to be taken into account, but in some cases on the `to` .
12
12
final _renameRegex = RegExp (r'\x00' );
13
13
14
- final logger = Logger ('lint_staged:GitWorkflow' );
14
+ final verbose = Verbose ('lint_staged:GitWorkflow' );
15
15
16
16
///
17
17
/// From list of files, split renames and flatten into two files `to` NUL`from` .
@@ -120,20 +120,20 @@ class GitWorkflow {
120
120
/// Get a list of unstaged deleted files
121
121
///
122
122
Future <List <String >> getDeletedFiles () async {
123
- logger. debug ('Getting deleted files...' );
123
+ verbose ('Getting deleted files...' );
124
124
final lsFiles = await execGit (['ls-files' , '--deleted' ],
125
125
workingDirectory: workingDirectory);
126
126
final files =
127
127
lsFiles.split ('\n ' ).where ((line) => line.trim ().isNotEmpty).toList ();
128
- logger. debug ('Found deleted files: $files ' );
128
+ verbose ('Found deleted files: $files ' );
129
129
return files;
130
130
}
131
131
132
132
///
133
133
/// Save meta information about ongoing git merge
134
134
///
135
135
Future <void > backupMergeStatus () async {
136
- logger. debug ('Backing up merge state...' );
136
+ verbose ('Backing up merge state...' );
137
137
await Future .wait ([
138
138
readFile (mergeHeadFilename, workingDirectory: workingDirectory)
139
139
.then ((value) => mergeHeadContent = value),
@@ -142,14 +142,14 @@ class GitWorkflow {
142
142
readFile (mergeMsgFilename, workingDirectory: workingDirectory)
143
143
.then ((value) => mergeModeContent = value)
144
144
]);
145
- logger. debug ('Done backing up merge state!' );
145
+ verbose ('Done backing up merge state!' );
146
146
}
147
147
148
148
///
149
149
/// Restore meta information about ongoing git merge
150
150
///
151
151
Future <void > restoreMergeStatus (LintStagedContext ctx) async {
152
- logger. debug ('Restoring merge state...' );
152
+ verbose ('Restoring merge state...' );
153
153
try {
154
154
await Future .wait ([
155
155
if (mergeHeadContent != null )
@@ -162,10 +162,10 @@ class GitWorkflow {
162
162
writeFile (mergeMsgFilename, mergeMsgContent! ,
163
163
workingDirectory: workingDirectory),
164
164
]);
165
- logger. debug ('Done restoring merge state!' );
165
+ verbose ('Done restoring merge state!' );
166
166
} catch (e) {
167
- logger. debug ('Failed restoring merge state with error:' );
168
- logger. debug (e.toString ());
167
+ verbose ('Failed restoring merge state with error:' );
168
+ verbose (e.toString ());
169
169
handleError (
170
170
Exception ('Merge state could not be restored due to an error!' ),
171
171
ctx,
@@ -179,7 +179,7 @@ class GitWorkflow {
179
179
/// both the "from" and "to" filenames, where "from" is no longer on disk.
180
180
///
181
181
Future <List <String >> getPartiallyStagedFiles () async {
182
- logger. debug ('Getting partially staged files...' );
182
+ verbose ('Getting partially staged files...' );
183
183
final status =
184
184
await execGit (['status' , '-z' ], workingDirectory: workingDirectory);
185
185
if (status.isEmpty) {
@@ -215,7 +215,7 @@ class GitWorkflow {
215
215
216
216
/// Filter empty string
217
217
.toList ();
218
- logger. debug ('Found partially staged files: $partiallyStaged ' );
218
+ verbose ('Found partially staged files: $partiallyStaged ' );
219
219
return partiallyStaged;
220
220
}
221
221
@@ -224,7 +224,7 @@ class GitWorkflow {
224
224
///
225
225
Future <void > prepare (LintStagedContext ctx) async {
226
226
try {
227
- logger. debug ('Backing up original state...' );
227
+ verbose ('Backing up original state...' );
228
228
partiallyStagedFiles = await getPartiallyStagedFiles ();
229
229
if (partiallyStagedFiles.isNotEmpty) {
230
230
ctx.hasPartiallyStagedFiles = true ;
@@ -263,7 +263,7 @@ class GitWorkflow {
263
263
await execGit (['stash' , 'store' , '--quiet' , '--message' , kStash, hash],
264
264
workingDirectory: workingDirectory);
265
265
266
- logger. debug ('Done backing up original state!' );
266
+ verbose ('Done backing up original state!' );
267
267
} catch (e) {
268
268
handleError (e, ctx);
269
269
}
@@ -291,7 +291,7 @@ class GitWorkflow {
291
291
/// In case of a merge-conflict retry with 3-way merge.
292
292
///
293
293
Future <void > applyModifications (LintStagedContext ctx) async {
294
- logger. debug ('Adding task modifications to index...' );
294
+ verbose ('Adding task modifications to index...' );
295
295
296
296
/// `matchedFileChunks` includes staged files that lint_staged originally detected and matched against a task.
297
297
/// Add only these files so any 3rd-party edits to other files won't be included in the commit.
@@ -301,7 +301,7 @@ class GitWorkflow {
301
301
await execGit (['add' , '--' , ...files],
302
302
workingDirectory: workingDirectory);
303
303
}
304
- logger. debug ('Done adding task modifications to index!' );
304
+ verbose ('Done adding task modifications to index!' );
305
305
306
306
final stagedFilesAfterAdd = await execGit (
307
307
getDiffArgs (diff: diff, diffFilter: diffFilter),
@@ -318,23 +318,22 @@ class GitWorkflow {
318
318
/// 3-way merge usually fixes this, and in case it doesn't we should just give up and throw.
319
319
///
320
320
Future <void > resotreUnstagedChanges (LintStagedContext ctx) async {
321
- logger. debug ('Restoring unstaged changes...' );
321
+ verbose ('Restoring unstaged changes...' );
322
322
final unstagedPatch = getHiddenFilepath (kPatchUnstaged);
323
323
try {
324
324
await execGit (['apply' , ...kGitApplyArgs, unstagedPatch],
325
325
workingDirectory: workingDirectory);
326
326
} catch (applyError) {
327
- logger. debug ('Error while restoring changes:' );
328
- logger. debug (applyError.toString ());
329
- logger. debug ('Retrying with 3-way merge' );
327
+ verbose ('Error while restoring changes:' );
328
+ verbose (applyError.toString ());
329
+ verbose ('Retrying with 3-way merge' );
330
330
try {
331
331
// Retry with a 3-way merge if normal apply fails
332
332
await execGit (['apply' , ...kGitApplyArgs, '--3way' , unstagedPatch],
333
333
workingDirectory: workingDirectory);
334
334
} catch (threeWayApplyError) {
335
- logger
336
- .debug ('Error while restoring unstaged changes using 3-way merge:' );
337
- logger.debug (threeWayApplyError.toString ());
335
+ verbose ('Error while restoring unstaged changes using 3-way merge:' );
336
+ verbose (threeWayApplyError.toString ());
338
337
handleError (
339
338
Exception (
340
339
'Unstaged changes could not be restored due to a merge conflict!' ),
@@ -349,7 +348,7 @@ class GitWorkflow {
349
348
///
350
349
Future <void > restoreOriginState (LintStagedContext ctx) async {
351
350
try {
352
- logger. debug ('Restoring original state...' );
351
+ verbose ('Restoring original state...' );
353
352
await execGit (['reset' , '--hard' , 'HEAD' ],
354
353
workingDirectory: workingDirectory);
355
354
await execGit (
@@ -367,7 +366,7 @@ class GitWorkflow {
367
366
await removeFile (getHiddenFilepath (kPatchUnstaged),
368
367
workingDirectory: workingDirectory);
369
368
370
- logger. debug ('Done restoring original state!' );
369
+ verbose ('Done restoring original state!' );
371
370
} catch (error) {
372
371
handleError (error, ctx, kRestoreOriginalStateError);
373
372
}
@@ -378,10 +377,10 @@ class GitWorkflow {
378
377
///
379
378
Future <void > cleanup (LintStagedContext ctx) async {
380
379
try {
381
- logger. debug ('Dropping backup stash...' );
380
+ verbose ('Dropping backup stash...' );
382
381
await execGit (['stash' , 'drop' , '--quiet' , await getBackupStash (ctx)],
383
382
workingDirectory: workingDirectory);
384
- logger. debug ('Done dropping backup stash!' );
383
+ verbose ('Done dropping backup stash!' );
385
384
} catch (error) {
386
385
handleError (error, ctx);
387
386
}
0 commit comments