run method
Implementation
Future<int> run() async {
final allFilesResult = await this.allFiles;
if (allFilesResult case (_, final int code)) {
return code;
}
final (allFiles, _) = allFilesResult;
logger.detail('Found ${allFiles.length} files');
for (final file in allFiles) {
logger.detail(' - $file');
}
await _wait(durations.short);
logger.detail('Resolving files');
final pendingHook = PendingHook(hook.resolve(allFiles), logger: logger);
if (!hook.shouldRunOnEmpty &&
!pendingHook.topLevelTasks.any((e) => e.shouldAlwaysRun)) {
if (pendingHook.topLevelTasks.every((e) => e.files.isEmpty)) {
logger.info(
darkGray.wrap('Skipping $hookName hook, no files match any tasks'),
);
return 0;
}
}
final context = await git.prepareFiles();
// Snapshot before the first task touches a file, so any exit other than a
// clean success can put the repository back exactly as it was found.
final backup = hook.backup ? await git.createBackup() : null;
var succeeded = false;
try {
final code = await _runTasks(pendingHook, context);
succeeded = code == 0;
return code;
} finally {
await releaseBackup(backup, succeeded: succeeded);
}
}