resolveExecutionRoot function
Determine the execution root based on navigation args.
In workspace mode with bare -R, returns the detected workspace root.
In workspace mode with -R <path>, validates and returns that path.
With -T/--top-repo, finds topmost git repo (requires -i or -o).
In project mode, returns the current directory.
Implementation
String resolveExecutionRoot(
WorkspaceNavigationArgs navArgs, {
required String currentDir,
}) {
if (navArgs.topRepo) {
if (!navArgs.innerFirstGit && !navArgs.outerFirstGit) {
throw ArgumentError(
'-T/--top-repo requires git traversal mode '
'(-i/--inner-first-git or -o/--outer-first-git)',
);
}
final finder = GitRepoFinder();
final topRepo = finder.findTopRepo(currentDir);
if (topRepo == null) {
throw ArgumentError(
'No git repository found in directory tree above: $currentDir',
);
}
return topRepo;
}
if (navArgs.bareRoot) {
return findWorkspaceRoot(currentDir);
} else if (navArgs.root != null) {
final specifiedPath = p.isAbsolute(navArgs.root!)
? navArgs.root!
: p.join(currentDir, navArgs.root!);
final resolved = p.normalize(p.absolute(specifiedPath));
if (!Directory(resolved).existsSync()) {
throw ArgumentError(
'Specified workspace does not exist: ${navArgs.root}',
);
}
if (!isWorkspaceBoundary(resolved)) {
throw ArgumentError(
'Specified path is not a workspace '
'(no $kBuildkitMasterYaml): ${navArgs.root}',
);
}
return resolved;
}
return currentDir;
}