Skip to content

Instantly share code, notes, and snippets.

@deas
Created February 16, 2026 06:55
Show Gist options
  • Select an option

  • Save deas/210b3e5ec72fdaf212bb9d1fc7c0ad72 to your computer and use it in GitHub Desktop.

Select an option

Save deas/210b3e5ec72fdaf212bb9d1fc7c0ad72 to your computer and use it in GitHub Desktop.
#!/bin/bash
set -euo pipefail
# hades-git-clone - Git clone wrapper for FQDN rewriting and username injection
# Configuration
SOURCE_FQDN="github.com"
TARGET_FQDN="internal.github.com"
# Function to transform HTTPS URL
transform_url() {
local url="$1"
# Only process HTTPS URLs
if [[ ! "$url" =~ ^https:// ]]; then
echo "$url"
return 0
fi
local actual_url="$url"
# Check if URL contains the source FQDN
if [[ "$url" =~ ^https://${SOURCE_FQDN}/ ]]; then
# Replace FQDN
actual_url="${url/${SOURCE_FQDN}/${TARGET_FQDN}}"
fi
# Prepend username if environment variable is set (for all HTTPS URLs)
if [[ -n "${GIT_USER:-}" ]]; then
local username="${GIT_USER}"
actual_url="${actual_url/https:\/\//https:\/\/${username}@}"
fi
echo "$actual_url"
}
# Main function
main() {
local git_args=()
local url_found=false
# Parse arguments to find the URL
for arg in "$@"; do
if [[ "$url_found" == false ]] && [[ "$arg" =~ ^https?:// ]] || [[ "$arg" =~ ^[^-].*:// ]]; then
# original_url="$arg"
url_found=true
# Transform the URL
git_args+=("$(transform_url "$arg")")
else
git_args+=("$arg")
fi
done
# If no URL found, pass through to git clone as-is
if [[ "$url_found" == false ]]; then
echo exec git clone "$@"
fi
# Execute git clone with actual_url URL
echo exec git clone "${git_args[@]}"
}
main "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment