wayfinderSshCommand function

String? wayfinderSshCommand(
  1. Map<String, String> environment, {
  2. String? configured,
})

The GIT_SSH_COMMAND under which Git runs the SSH command it would choose in environment: GIT_SSH_COMMAND, then configured, the core.sshCommand of Git's configuration as the command sees it, then GIT_SSH, then ssh. When that is OpenSSH, -o BatchMode=yes is added, so SSH never asks for a password or a host key; another SSH client, such as PuTTY's plink, runs unchanged. GIT_SSH_VARIANT decides whether a program is OpenSSH, and otherwise its name does.

Null when Git should keep running GIT_SSH as it is, because that program is not OpenSSH and takes no options.

Implementation

String? wayfinderSshCommand(
  Map<String, String> environment, {
  String? configured,
}) {
  final variant = environment['GIT_SSH_VARIANT'];
  final command =
      _nonEmpty(environment['GIT_SSH_COMMAND']) ?? _nonEmpty(configured);
  if (command != null) {
    return _isOpenSsh(_firstWord(command), variant)
        ? '$command $_batchMode'
        : command;
  }
  if (_nonEmpty(environment['GIT_SSH']) case final program?) {
    // GIT_SSH names a program, not a shell command, so quote it for one.
    return _isOpenSsh(program, variant)
        ? "'${program.replaceAll("'", r"'\''")}' $_batchMode"
        : null;
  }
  return 'ssh $_batchMode';
}