Skip to content

Commit

Permalink
Move Git config in bootstrap.sh into a function
Browse files Browse the repository at this point in the history
SSH can be used to sign Git commits (a38644d), but the related settings
in `.gitconfig` are not compatible with all Git installations.

In GitHub Actions macOS workflows, a Git error message is seen after
`bootstrap.sh` clones the dotfiles repo and installs the dotfiles:

```text
error: unsupported value for gpg.format: ssh
```

This commit will consolidate the Git config steps in `bootstrap.sh` into
a function, and will add GPG configuration steps to avoid errors in CI.
  • Loading branch information
br3ndonland committed Dec 28, 2022
1 parent 6fb9d09 commit c054239
Showing 1 changed file with 38 additions and 31 deletions.
69 changes: 38 additions & 31 deletions bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -269,39 +269,44 @@ else
log "Not macOS. Xcode CLT install and license check skipped."
fi

logn "Configuring Git:"
if [ -n "$STRAP_GIT_NAME" ] && ! git config user.name >/dev/null; then
git config --global user.name "$STRAP_GIT_NAME"
fi

if [ -n "$STRAP_GIT_EMAIL" ] && ! git config user.email >/dev/null; then
git config --global user.email "$STRAP_GIT_EMAIL"
fi

if [ -n "$STRAP_GITHUB_USER" ] &&
[ "$(git config github.user)" != "$STRAP_GITHUB_USER" ]; then
git config --global github.user "$STRAP_GITHUB_USER"
fi

# Set up GitHub HTTPS credentials
# shellcheck disable=SC2086
if git credential-osxkeychain 2>&1 | grep $Q "git.credential-osxkeychain"; then
# Execute credential in case it's a wrapper script for credential-osxkeychain
if git "credential-$(git config --global credential.helper 2>/dev/null)" 2>&1 |
grep -v $Q "git.credential-osxkeychain"; then
git config --global credential.helper osxkeychain
configure_git() {
logn "Configuring Git:"
if [ "$STRAP_CI" -gt 0 ]; then
git config --global commit.gpgsign false
git config --global gpg.format openpgp
fi
if [ -n "$STRAP_GITHUB_USER" ] && [ -n "$STRAP_GITHUB_TOKEN" ]; then
PROTOCOL="protocol=https\\nhost=github.com"
printf "%s\\n" "$PROTOCOL" | git credential reject
printf "%s\\nusername=%s\\npassword=%s\\n" \
"$PROTOCOL" "$STRAP_GITHUB_USER" "$STRAP_GITHUB_TOKEN" |
git credential approve
else
log "Skipping Git credential setup."
if [ -n "$STRAP_GIT_NAME" ] && ! git config user.name >/dev/null; then
git config --global user.name "$STRAP_GIT_NAME"
fi
logk
fi
if [ -n "$STRAP_GIT_EMAIL" ] && ! git config user.email >/dev/null; then
git config --global user.email "$STRAP_GIT_EMAIL"
fi
if [ -n "$STRAP_GITHUB_USER" ] &&
[ "$(git config github.user)" != "$STRAP_GITHUB_USER" ]; then
git config --global github.user "$STRAP_GITHUB_USER"
fi
# Set up GitHub HTTPS credentials
# shellcheck disable=SC2086
if git credential-osxkeychain 2>&1 | grep $Q "git.credential-osxkeychain"; then
# Execute credential in case it's a wrapper script for credential-osxkeychain
if git "credential-$(git config --global credential.helper 2>/dev/null)" 2>&1 |
grep -v $Q "git.credential-osxkeychain"; then
git config --global credential.helper osxkeychain
fi
if [ -n "$STRAP_GITHUB_USER" ] && [ -n "$STRAP_GITHUB_TOKEN" ]; then
PROTOCOL="protocol=https\\nhost=github.com"
printf "%s\\n" "$PROTOCOL" | git credential reject
printf "%s\\nusername=%s\\npassword=%s\\n" \
"$PROTOCOL" "$STRAP_GITHUB_USER" "$STRAP_GITHUB_TOKEN" |
git credential approve
else
log "Skipping Git credential setup."
fi
logk
fi
}

configure_git

# Check for and install any remaining software updates
logn "Checking for software updates:"
Expand Down Expand Up @@ -342,6 +347,8 @@ log "Checking out $strap_dotfiles_branch_name in ~/.dotfiles."
run_dotfile_scripts scripts/symlink.sh
logk

configure_git

# shellcheck disable=SC2086
install_homebrew() {
logn "Installing Homebrew:"
Expand Down

0 comments on commit c054239

Please sign in to comment.