Skip to content

Commit 0cc29f8

Browse files
committed
updated git_remotes_set_https_creds_helpers.sh
1 parent 7c5c954 commit 0cc29f8

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

git/git_remotes_set_https_creds_helpers.sh

+14-8
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ When combined with the adjacent scripts
4040
4141
this allows you to quickly switch many git repo checkouts from SSH to HTTPS and have them all inherit the environment auth tokens
4242
43+
If the GIT_GLOBAL_CONFIG environment variable is set to any value, then sets it at the global user config level instead of in the local repo
44+
4345
If no provider is found, checks for the following environment variables and sets them automatically in the local git repo if they're both found
4446
4547
GitHub:
@@ -73,16 +75,20 @@ max_args 1 "$@"
7375

7476
provider="${1:-all}"
7577

78+
#global="${2:+--global}"
79+
global="${GIT_GLOBAL_CONFIG:+--global}"
80+
7681
github_cred_helper(){
7782
# not needed to authenticate in practice
7883
#if [ -n "${GITHUB_USER:-}" ]; then
7984
# GH_TOKEN is higher precedence in GitHub CLI so do the same here for consistency to avoid non-intuitive auth problems where one works and the other doesn't using different tokens
8085
if [ -n "${GH_TOKEN:-${GITHUB_TOKEN:-}}" ]; then
8186
timestamp "Setting credential helper for GitHub"
8287
# env vars need to be evaluated dynamically not here
83-
# shellcheck disable=SC2016
88+
# $global must not be quoted because when it is empty this will break the command with a '' arg
89+
# shellcheck disable=SC2016,SC2086
8490
#git config credential.https://github.com.helper '!f() { sleep 1; echo "username=${GITHUB_USER}"; echo "password=${GH_TOKEN:-${GITHUB_TOKEN}}"; }; f'
85-
git config credential.https://github.com.helper '!f() { sleep 1; echo "password=${GH_TOKEN:-${GITHUB_TOKEN}}"; }; f'
91+
git config $global credential.https://github.com.helper '!f() { sleep 1; echo "password=${GH_TOKEN:-${GITHUB_TOKEN}}"; }; f'
8692
else
8793
timestamp "NOT setting credential helper for GitHub since \$GH_TOKEN / \$GITHUB_TOKEN not found in environment"
8894
fi
@@ -93,9 +99,9 @@ gitlab_cred_helper(){
9399
#if [ -n "${GITHUB_USER:-}" ]; then
94100
if [ -n "${GITLAB_TOKEN:-}" ]; then
95101
timestamp "Setting credential helper for GitLab"
96-
# shellcheck disable=SC2016
102+
# shellcheck disable=SC2016,SC2086
97103
#git config credential.https://gitlab.com.helper '!f() { sleep 1; echo "username=${GITLAB_USER}"; echo "password=${GITLAB_TOKEN}"; }; f'
98-
git config credential.https://gitlab.com.helper '!f() { sleep 1; echo "password=${GITLAB_TOKEN}"; }; f'
104+
git config $global credential.https://gitlab.com.helper '!f() { sleep 1; echo "password=${GITLAB_TOKEN}"; }; f'
99105
else
100106
timestamp "NOT setting credential helper for GitLab since \$GITLAB_TOKEN not found in environment"
101107
fi
@@ -106,9 +112,9 @@ bitbucket_cred_helper(){
106112
#if [ -n "${GITHUB_USER:-}" ]; then
107113
if [ -n "${BITBUCKET_TOKEN:-}" ]; then
108114
timestamp "Setting credential helper for Bitbucket"
109-
# shellcheck disable=SC2016
115+
# shellcheck disable=SC2016,SC2086
110116
#git config credential.https://bitbucket.org.helper '!f() { sleep 1; echo "username=${BITBUCKET_USER}"; echo "password=${BITBUCKET_TOKEN}"; }; f'
111-
git config credential.https://bitbucket.org.helper '!f() { sleep 1; echo "password=${BITBUCKET_TOKEN}"; }; f'
117+
git config $global credential.https://bitbucket.org.helper '!f() { sleep 1; echo "password=${BITBUCKET_TOKEN}"; }; f'
112118
else
113119
timestamp "NOT setting credential helper for Bitbucket since \$BITBUCKET_TOKEN not found in environment"
114120
fi
@@ -119,9 +125,9 @@ azure_devops_cred_helper(){
119125
#if [ -n "${GITHUB_USER:-}" ]; then
120126
if [ -n "${AZURE_DEVOPS_TOKEN:-}" ]; then
121127
timestamp "Setting credential helper for Azure DevOps"
122-
# shellcheck disable=SC2016
128+
# shellcheck disable=SC2016,SC2086
123129
#git config credential.https://dev.azure.com.helper '!f() { sleep 1; echo "username=${AZURE_DEVOPS_USER}"; echo "password=${AZURE_DEVOPS_TOKEN}"; }; f'
124-
git config credential.https://dev.azure.com.helper '!f() { sleep 1; echo "password=${AZURE_DEVOPS_TOKEN}"; }; f'
130+
git config $global credential.https://dev.azure.com.helper '!f() { sleep 1; echo "password=${AZURE_DEVOPS_TOKEN}"; }; f'
125131
else
126132
timestamp "NOT setting credential helper for Azure DevOps since \$AZURE_DEVOPS_TOKEN not found in environment"
127133
fi

0 commit comments

Comments
 (0)