I have several helper functions to call into git through Subprocess like this
func getCurrentCommitHash(
at repoPath: FilePath
) async throws -> String {
let gitResult = try await Subprocess.run(
.at("/usr/local/bin/git"),
arguments: ["rev-parse", "HEAD"],
workingDirectory: repoPath
)
guard gitResult.terminationStatus.isSuccess else {
let stderr = String(data: gitResult.standardError, encoding: .utf8)
throw MyError.commandFailed(
"git rev-parse HEAD",
stderr
)
}
return String(decoding: gitResult.standardOutput, as: UTF8.self).trimmingCharacters(in: .whitespacesAndNewlines)
}
For each of these I am manually constructing an Error to throw when the underlying git command fails. The main body of the error is the actual command that's being run, git rev-parse HEAD in this case.
It would be nice if I can get the underlying command populated up through Subprocess.run. This function already knows the exact command being executed, so it should be possible to also surface this up to the caller.
I have several helper functions to call into
gitthrough Subprocess like thisFor each of these I am manually constructing an
Errorto throw when the underlyinggitcommand fails. The main body of the error is the actual command that's being run,git rev-parse HEADin this case.It would be nice if I can get the underlying command populated up through
Subprocess.run. This function already knows the exact command being executed, so it should be possible to also surface this up to the caller.