#!/bin/sh
#
# Git-SSH Wrapper for Tower.
#
# This will wrap all SSH commands coming from Git by setting the environment variable `GIT_SSH`
# to the path of this file (see `man git`).
#
# Tower requires to wrap all SSH commands for the following things:
#
# - Disable SSH connection reuse configured by the user with `ControlMaster` and friends (see
#   `man ssh_config`) as this breaks remote command calls from Tower
# - Use specific Private Key files for a connection – this will also automatically invoke Keychain
#   to add missing SSH keys to the SSH Agent (otherwise we would have to use another ASKPASS call)
#

if [ ! -z "$TOWER_PRIVATE_KEY_PATH" ]; then
    exec ssh -o "ControlMaster=no" -o "ControlPath=none" -i "$TOWER_PRIVATE_KEY_PATH" "$@"
else
    exec ssh -o "ControlMaster=no" -o "ControlPath=none" "$@"
fi
