git-remote-gits (1078B)
1 #!/bin/sh 2 set -eu 3 4 fail() { 5 echo "$0: $1" >&2 6 exit 1 7 } 8 9 [ $# -eq 2 ] || fail "invalid usage; see gitremote-helpers(7)" 10 REMOTE="$1" 11 URL="$2" 12 13 command -v ncat >/dev/null 2>&1 || fail "ncat must be installed" 14 15 # Parse the URL 16 IFS=',' read -r GITS_HOST GITS_PORT GITS_PATH <<EOF 17 $(echo "$URL" | sed -En ' 18 # |proto||addr-----------------------------------------------||port------||path----------| 19 # | |||IPv6 addr-------------------------| |other addr--||| || | 20 s@^gits://(\[[a-fA-F0-9:]+(%[a-zA-Z0-9._-]+)?\]|[a-zA-Z0-9.-]+)(:([0-9]+))?(/[[:graph:]]*)?$@\1,\4,\5@; 21 tp; # Goto p if the s did match 22 bq; # Goto q if the s did not match 23 :p; p; 24 :q; q; 25 ') 26 EOF 27 28 # GITS_HOST is empty iff the URL didn't match the regex 29 [ -n "$GITS_HOST" ] || fail "invalid address" 30 : "${GITS_PORT:=9419}" 31 : "${GITS_PATH:=/}" 32 33 # The suicide (kill $$) is a kludge to circumvent an apparent git remote-ext 34 # bug, namely that it doesn't exit when the command fails. 35 exec git remote-ext "$REMOTE" "sh -c ncat% --ssl-verify% $GITS_HOST% $GITS_PORT% ||% kill% $$ %G$GITS_PATH"