wayfinderConfiguredSshCommand function

Future<String?> wayfinderConfiguredSshCommand(
  1. List<String> arguments, {
  2. String? workingDirectory,
  3. required Map<String, String> environment,
  4. required Future<GitResult> run(
    1. List<String> arguments
    ),
})

core.sshCommand as the Git command arguments, run in workingDirectory, would see it, for wayfinderGitEnvironment's sshCommand; null when there is none to read.

It runs one more git config command through run, and only when arguments may reach a remote (gitMayReachRemote) and environment sets no GIT_SSH_COMMAND, which overrides the configuration. Outside a working directory the command, such as clone, reads no repository's configuration, so neither does the lookup. run runs Git as any of Wayfinder's commands runs: with wayfinderGitOptions, in wayfinderGitEnvironment of environment, in workingDirectory, and without a lookup of its own.

Implementation

Future<String?> wayfinderConfiguredSshCommand(
  List<String> arguments, {
  String? workingDirectory,
  required Map<String, String> environment,
  required Future<GitResult> Function(List<String> arguments) run,
}) async {
  if (_nonEmpty(environment['GIT_SSH_COMMAND']) != null ||
      !gitMayReachRemote(arguments)) {
    return null;
  }
  final configured = await run([
    // A path that is no repository keeps the lookup from reading the one
    // around the current directory.
    if (workingDirectory == null) '--git-dir=/dev/null',
    'config',
    '--get',
    'core.sshCommand',
  ]);
  if (configured.exitCode != 0) return null;
  return utf8
      .decode(configured.stdout, allowMalformed: true)
      .replaceFirst(RegExp(r'\r?\n$'), '');
}