runGit function
Run git
with the provided arguments
.
If echoOutput
is true
, the output of the git
command will be echoed.
Note: echoOutput
true
will also cause the returned ProcessResult to
have null
values for ProcessResult.stdout and ProcessResult.stderr.
Use processWorkingDir
to set the working directory for the created Git
process. If omitted or null
, the default (Directory.current) is used.
Implementation
Future<ProcessResult> runGit(
List<String> arguments, {
bool throwOnError = true,
bool echoOutput = false,
String? processWorkingDir,
}) async {
final pr = await Process.start(
'git',
arguments,
workingDirectory: processWorkingDir,
runInShell: true,
mode: echoOutput ? ProcessStartMode.inheritStdio : ProcessStartMode.normal,
);
final results = await Future.wait([
pr.exitCode,
if (!echoOutput) pr.stdout.transform(const SystemEncoding().decoder).join(),
if (!echoOutput) pr.stderr.transform(const SystemEncoding().decoder).join(),
]);
final result = ProcessResult(
pr.pid,
results[0] as int,
echoOutput ? null : results[1] as String,
echoOutput ? null : results[2] as String,
);
if (throwOnError) {
_throwIfProcessFailed(result, 'git', arguments);
}
return result;
}