projectGroupsOf function

Set<String> projectGroupsOf(
  1. String projectPath,
  2. String executionRoot
)

The names of the groups the project at projectPath belongs to.

Groups are derived from the directory walk, never listed: every directory from the project itself up to executionRoot (both included) that

  • is a git repository (holds a .git directory, or a .git file as a submodule checkout does) is a group named by its folder name and by its path relative to executionRoot;
  • holds a buildkit_group.yaml is a group named by the file's name:, or by its folder name when the file names none.

A project outside executionRoot belongs to no group.

Implementation

Set<String> projectGroupsOf(String projectPath, String executionRoot) {
  final root = p.normalize(p.absolute(executionRoot));
  var dir = p.normalize(p.absolute(projectPath));
  if (!p.equals(dir, root) && !p.isWithin(root, dir)) return const {};
  final names = <String>{};
  while (true) {
    if (FileSystemEntity.typeSync(p.join(dir, '.git')) !=
        FileSystemEntityType.notFound) {
      names.add(p.basename(dir));
      final relative = p.relative(dir, from: root).replaceAll(r'\', '/');
      names.add(relative);
    }
    final marker = File(p.join(dir, kBuildkitGroupYaml));
    if (marker.existsSync()) names.add(_groupName(marker, dir));
    if (p.equals(dir, root)) return names;
    dir = p.dirname(dir);
  }
}