File size: 1,436 Bytes
c7c67ef
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/env bash
set -euo pipefail

script_dir="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
repo_root="$(cd -- "$script_dir/.." && 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 'Error: DVC/uvx unavailable; install DVC before configuring Git auth.\n' >&2
    exit 2
fi

if ! username="$(cd "$repo_root" && "${dvc_cmd[@]}" config --local remote.dagshub.user 2>/dev/null)" \
    || ! password="$(cd "$repo_root" && "${dvc_cmd[@]}" config --local remote.dagshub.password 2>/dev/null)" \
    || [[ -z "$username" || -z "$password" ]]; then
    printf 'Error: configure DagsHub credentials in ignored .dvc/config.local first.\n' >&2
    exit 2
fi

# Do not leave the secret in this setup process's environment or output.
unset password
helper="$repo_root/scripts/git-credential-dagshub"
git -C "$repo_root" config --local --replace-all credential.https://dagshub.com.helper ""
git -C "$repo_root" config --local --add credential.https://dagshub.com.helper "$helper"
git -C "$repo_root" config --local credential.https://dagshub.com.useHttpPath true

printf 'Configured repo-local Git auth for https://dagshub.com/santiagacasas/cjfp-data.git\n'
printf 'Git will reuse the account username and token from ignored DVC local config.\n'