getCommitShasForFile method
Get a chronologically sorted list of all commits from the file
at relativeFilepath
in the git repository at gitDirpath
.
The first element in the list is the most recent commit.
Implementation
Future<List<String>> getCommitShasForFile({
required String gitDirpath,
required String relativeFilepath,
bool followName = true,
Map<String, String>? environment,
bool includeParentEnvironment = true,
}) async {
final dir = checkDirectoryExists(gitDirpath, "gitDirpath");
final file = checkFileExists(lib_path.join(dir.path, relativeFilepath));
final res = await runAsync(
[
"log",
"--follow",
"--format=%H",
"--",
lib_path.relative(file.path, from: dir.path),
],
workingDirectory: dir.path,
environment: environment,
includeParentEnvironment: includeParentEnvironment,
);
if (0 != res.exitCode) {
throw CliResultException(
exitCode: res.exitCode,
stderr: res.stderr,
message: "Failed to get the commit shas from "
"the git directory at '$gitDirpath'",
);
}
return res.stdout
.toString()
.split("\n")
.where((e) => e.isNotEmpty)
.toList();
}