wayfinderGitEnvironment function

Map<String, String> wayfinderGitEnvironment(
  1. Map<String, String> environment, {
  2. String? sshCommand,
})

environment without the GIT_* variables that would steer a command elsewhere, plus what keeps Git from waiting for a person: no terminal or credential-manager prompt, SSH in batch mode, and no Git LFS download.

A Git hook or linked worktree exports GIT_DIR and its siblings; inherited, they would point every mirror command at the user's own repository. What the user chose for every Git command is kept: which configuration files Git reads (GIT_CONFIG_GLOBAL, GIT_CONFIG_SYSTEM and GIT_CONFIG_NOSYSTEM) and how it runs SSH (GIT_SSH_COMMAND, GIT_SSH and GIT_SSH_VARIANT).

SSH runs wayfinderSshCommand: the command Git itself would choose, with sshCommand as the core.sshCommand of Git's configuration when the caller looked it up (wayfinderConfiguredSshCommand), in batch mode when it is OpenSSH. SSH still reads ~/.ssh/config, and Git still reads the user's configuration and credential helpers.

Implementation

Map<String, String> wayfinderGitEnvironment(
  Map<String, String> environment, {
  String? sshCommand,
}) {
  final ssh = wayfinderSshCommand(environment, configured: sshCommand);
  return {
    for (final MapEntry(:key, :value) in environment.entries)
      if (!key.toUpperCase().startsWith('GIT_') || _kept.contains(key))
        key: value,
    'GIT_TERMINAL_PROMPT': '0',
    'GCM_INTERACTIVE': 'never',
    'GIT_SSH_COMMAND': ?ssh,
    'GIT_LFS_SKIP_SMUDGE': '1',
  };
}