projectGroupsOf function
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
.gitdirectory, or a.gitfile as a submodule checkout does) is a group named by its folder name and by its path relative toexecutionRoot; - holds a
buildkit_group.yamlis a group named by the file'sname:, 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);
}
}