getModifiedDartFiles method
Finds Dart files modified between baseCommit and HEAD.
Implementation
Future<List<String>> getModifiedDartFiles(
String baseCommit, {
List<String> targetPaths = const [],
}) async {
final repoRoot = await getRepoRoot();
final args = ['diff', '--name-only', '--diff-filter=ACMR', baseCommit];
final res = await _runGit(args);
if (res.exitCode != 0) {
throw ArgumentError(
'Git diff failed against base commit "$baseCommit": '
'${(res.stderr as String).trim()}',
);
}
final output = (res.stdout as String).trim();
if (output.isEmpty) {
return [];
}
final baseDir = workingDirectory ?? Directory.current.path;
final resolvedTargets = [
for (final t in targetPaths) ...[
p.normalize(p.join(baseDir, t)),
p.normalize(p.join(repoRoot, t)),
],
];
final allChanged = output.split('\n').map((l) => l.trim()).toList();
final results = <String>[];
for (final relPath in allChanged) {
if (relPath.isEmpty ||
p.extension(relPath) != '.dart' ||
isExcludedPath(relPath)) {
continue;
}
final absPath = p.normalize(p.join(repoRoot, relPath));
if (resolvedTargets.isNotEmpty &&
!resolvedTargets.any(
(t) => p.isWithin(t, absPath) || p.equals(t, absPath),
)) {
continue;
}
results.add(relPath);
}
return results;
}