getCommits static method
Gets the commits between two refs
If fromRef is null, it gets all commits up to toRef (or HEAD if toRef is null)
Implementation
static Future<List<Commit>> getCommits({
required String root,
String? fromRef,
String? toRef,
}) async {
try {
final gitArgs = ['--no-pager', 'log', '--no-decorate'];
if (fromRef != null) {
gitArgs.add('$fromRef..${toRef ?? 'HEAD'}');
} else if (toRef != null) {
gitArgs.add(toRef);
}
final commitResult = await Process.run(
'git',
gitArgs,
workingDirectory: root,
);
if (commitResult.exitCode == 0) {
return Commit.parseCommits(commitResult.stdout.toString().trim());
}
return [];
} catch (e) {
logger.err('Error retrieving commits: $e');
return [];
}
}