Skip to content

Commit

Permalink
updated git_remotes_set_https_creds_helpers.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
HariSekhon committed Feb 9, 2024
1 parent 7c5c954 commit 0cc29f8
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions git/git_remotes_set_https_creds_helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ When combined with the adjacent scripts
this allows you to quickly switch many git repo checkouts from SSH to HTTPS and have them all inherit the environment auth tokens
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
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
GitHub:
Expand Down Expand Up @@ -73,16 +75,20 @@ max_args 1 "$@"

provider="${1:-all}"

#global="${2:+--global}"
global="${GIT_GLOBAL_CONFIG:+--global}"

github_cred_helper(){
# not needed to authenticate in practice
#if [ -n "${GITHUB_USER:-}" ]; then
# 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
if [ -n "${GH_TOKEN:-${GITHUB_TOKEN:-}}" ]; then
timestamp "Setting credential helper for GitHub"
# env vars need to be evaluated dynamically not here
# shellcheck disable=SC2016
# $global must not be quoted because when it is empty this will break the command with a '' arg
# shellcheck disable=SC2016,SC2086
#git config credential.https://github.com.helper '!f() { sleep 1; echo "username=${GITHUB_USER}"; echo "password=${GH_TOKEN:-${GITHUB_TOKEN}}"; }; f'
git config credential.https://github.com.helper '!f() { sleep 1; echo "password=${GH_TOKEN:-${GITHUB_TOKEN}}"; }; f'
git config $global credential.https://github.com.helper '!f() { sleep 1; echo "password=${GH_TOKEN:-${GITHUB_TOKEN}}"; }; f'
else
timestamp "NOT setting credential helper for GitHub since \$GH_TOKEN / \$GITHUB_TOKEN not found in environment"
fi
Expand All @@ -93,9 +99,9 @@ gitlab_cred_helper(){
#if [ -n "${GITHUB_USER:-}" ]; then
if [ -n "${GITLAB_TOKEN:-}" ]; then
timestamp "Setting credential helper for GitLab"
# shellcheck disable=SC2016
# shellcheck disable=SC2016,SC2086
#git config credential.https://gitlab.com.helper '!f() { sleep 1; echo "username=${GITLAB_USER}"; echo "password=${GITLAB_TOKEN}"; }; f'
git config credential.https://gitlab.com.helper '!f() { sleep 1; echo "password=${GITLAB_TOKEN}"; }; f'
git config $global credential.https://gitlab.com.helper '!f() { sleep 1; echo "password=${GITLAB_TOKEN}"; }; f'
else
timestamp "NOT setting credential helper for GitLab since \$GITLAB_TOKEN not found in environment"
fi
Expand All @@ -106,9 +112,9 @@ bitbucket_cred_helper(){
#if [ -n "${GITHUB_USER:-}" ]; then
if [ -n "${BITBUCKET_TOKEN:-}" ]; then
timestamp "Setting credential helper for Bitbucket"
# shellcheck disable=SC2016
# shellcheck disable=SC2016,SC2086
#git config credential.https://bitbucket.org.helper '!f() { sleep 1; echo "username=${BITBUCKET_USER}"; echo "password=${BITBUCKET_TOKEN}"; }; f'
git config credential.https://bitbucket.org.helper '!f() { sleep 1; echo "password=${BITBUCKET_TOKEN}"; }; f'
git config $global credential.https://bitbucket.org.helper '!f() { sleep 1; echo "password=${BITBUCKET_TOKEN}"; }; f'
else
timestamp "NOT setting credential helper for Bitbucket since \$BITBUCKET_TOKEN not found in environment"
fi
Expand All @@ -119,9 +125,9 @@ azure_devops_cred_helper(){
#if [ -n "${GITHUB_USER:-}" ]; then
if [ -n "${AZURE_DEVOPS_TOKEN:-}" ]; then
timestamp "Setting credential helper for Azure DevOps"
# shellcheck disable=SC2016
# shellcheck disable=SC2016,SC2086
#git config credential.https://dev.azure.com.helper '!f() { sleep 1; echo "username=${AZURE_DEVOPS_USER}"; echo "password=${AZURE_DEVOPS_TOKEN}"; }; f'
git config credential.https://dev.azure.com.helper '!f() { sleep 1; echo "password=${AZURE_DEVOPS_TOKEN}"; }; f'
git config $global credential.https://dev.azure.com.helper '!f() { sleep 1; echo "password=${AZURE_DEVOPS_TOKEN}"; }; f'
else
timestamp "NOT setting credential helper for Azure DevOps since \$AZURE_DEVOPS_TOKEN not found in environment"
fi
Expand Down

0 comments on commit 0cc29f8

Please sign in to comment.