From 69d029542b636f79c75ec0c4a04a0e8de1c7733a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=A5=E6=B5=A9?= Date: Sun, 8 Mar 2026 17:15:48 +0800 Subject: [PATCH] Add container Git helper integration Wire Git inside containers to the host proxy so HTTPS remotes can reuse host credentials automatically. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus --- configure-container.sh | 46 ++++++++++++++++++++++++++++++++++++++++ git-credential-hostproxy | 19 +++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100755 configure-container.sh create mode 100755 git-credential-hostproxy diff --git a/configure-container.sh b/configure-container.sh new file mode 100755 index 0000000..d08c7f3 --- /dev/null +++ b/configure-container.sh @@ -0,0 +1,46 @@ +#!/bin/sh +set -eu + +script_dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd) +helper_path="$script_dir/git-credential-hostproxy" +scope='global' +target_repo=$(pwd) + +while [ "$#" -gt 0 ]; do + case "$1" in + --global) + scope='global' + ;; + --local) + scope='local' + ;; + --repo) + shift + if [ "$#" -eq 0 ]; then + printf 'Missing value for --repo\n' >&2 + exit 1 + fi + target_repo="$1" + ;; + *) + printf 'Usage: %s [--global|--local] [--repo PATH]\n' "$0" >&2 + exit 1 + ;; + esac + shift +done + +if [ "$scope" = 'global' ]; then + git config --global --replace-all credential.helper '' + git config --global --add credential.helper "$helper_path" + git config --global credential.useHttpPath true + printf 'Configured global Git credential helper: %s\n' "$helper_path" +else + git -C "$target_repo" config --local --replace-all credential.helper '' + git -C "$target_repo" config --local --add credential.helper "$helper_path" + git -C "$target_repo" config --local credential.useHttpPath true + printf 'Configured local Git credential helper for %s\n' "$target_repo" +fi + +printf 'Proxy URL default: %s\n' "${GIT_CRED_PROXY_URL:-http://host.docker.internal:18765}" +printf 'Protocol filter is configured on the host side\n' diff --git a/git-credential-hostproxy b/git-credential-hostproxy new file mode 100755 index 0000000..ebb8bba --- /dev/null +++ b/git-credential-hostproxy @@ -0,0 +1,19 @@ +#!/bin/sh +set -eu + +script_dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd) + +if [ -n "${GIT_CRED_PROXY_RUNTIME:-}" ]; then + exec "$GIT_CRED_PROXY_RUNTIME" "$script_dir/helper.mjs" "$@" +fi + +if command -v bun >/dev/null 2>&1; then + exec bun "$script_dir/helper.mjs" "$@" +fi + +if command -v node >/dev/null 2>&1; then + exec node "$script_dir/helper.mjs" "$@" +fi + +printf 'Either bun or node is required to run git-credential-hostproxy\n' >&2 +exit 1