cjfp-data / scripts /git-credential-dagshub
santicas's picture
Mirror cjfp-data validation artifacts
c7c67ef verified
Raw History Blame Contribute Delete
1.3 kB
#!/usr/bin/env bash
# Git credential helper backed by this checkout's ignored DVC local config.
set -euo pipefail
[[ "${1:-}" == "get" ]] || exit 0
protocol=""
host=""
path=""
while IFS= read -r line; do
[[ -z "$line" ]] && break
key="${line%%=*}"
value="${line#*=}"
case "$key" in
protocol) protocol="$value" ;;
host) host="$value" ;;
path) path="$value" ;;
esac
done
[[ "$protocol" == "https" && "$host" == "dagshub.com" ]] || exit 0
[[ "$path" == "santiagocasas/cjfp-data.git" ]] || exit 0
repo_root="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd)"
if command -v dvc >/dev/null 2>&1; then
dvc_cmd=(dvc)
elif [[ -x "$repo_root/.venv/bin/dvc" ]]; then
dvc_cmd=("$repo_root/.venv/bin/dvc")
elif command -v uvx >/dev/null 2>&1; then
dvc_cmd=(uvx --from dvc dvc)
else
printf 'DVC unavailable; cannot read local DagsHub credentials.\n' >&2
exit 1
fi
username="$(cd "$repo_root" && "${dvc_cmd[@]}" config --local remote.dagshub.user)"
password="$(cd "$repo_root" && "${dvc_cmd[@]}" config --local remote.dagshub.password)"
if [[ -z "$username" || -z "$password" ]]; then
printf 'DagsHub credentials are missing from local DVC config.\n' >&2
exit 1
fi
printf 'username=%s\npassword=%s\n\n' "$username" "$password"