updateAll method

Future<void> updateAll({
  1. required GgLog ggLog,
  2. required Iterable<Directory> directories,
  3. String? workspacePath,
  4. int maxParallel = 4,
  5. bool dryRun = false,
})

Fast-forwards every repository in directories, at most maxParallel at a time, and throws a RepoFreshnessException naming each one that holds local work. A folder with nothing to update from is skipped silently.

Paths are reported relative to workspacePath when it is given, so the report reads ggdna/dna_dart instead of an absolute path.

With dryRun nothing is changed and nothing is thrown: the repositories that would stop a real run are logged instead, so a dry run does not promise a run that then aborts.

Implementation

Future<void> updateAll({
  required GgLog ggLog,
  required Iterable<Directory> directories,
  String? workspacePath,
  int maxParallel = 4,
  bool dryRun = false,
}) async {
  final repos = directories.toList();
  final blockers = List<RepoBlocker?>.filled(repos.length, null);

  await _runWithLimit(repos.length, maxParallel, (index) async {
    blockers[index] = await get(
      ggLog: ggLog,
      directory: repos[index],
      dryRun: dryRun,
    );
  });

  final blocked = <String, RepoBlocker>{};
  for (var i = 0; i < repos.length; i++) {
    final blocker = blockers[i];
    if (blocker != null && blocker.blocksTheRun) {
      blocked[_label(repos[i], workspacePath)] = blocker;
    }
  }

  if (blocked.isEmpty) {
    return;
  }

  if (dryRun) {
    ggLog(RepoFreshnessException(blocked).toString());
    return;
  }

  throw RepoFreshnessException(blocked);
}