From 9c279664925ba84385d6e783359ff3ae591d808f Mon Sep 17 00:00:00 2001 From: Stephen Kirby Date: Tue, 26 Sep 2023 00:40:26 +0000 Subject: [PATCH] added examples in readme, newlines in run --- git-config/README.md | 23 ++++++++++++++++++++++- git-config/run.sh | 10 +++++----- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/git-config/README.md b/git-config/README.md index cba56d0..f5d9ae4 100644 --- a/git-config/README.md +++ b/git-config/README.md @@ -9,11 +9,32 @@ tags: [helper, git] # git-config -Runs a script that checks for stored Git credentials, populating them with user's Coder credentials when missing. +Runs a script that checks for stored Git credentials `user.name` and `user.email`, populating them with workspace owner's credentials when missing. ## Examples +### Using Workspace owner +The credentials can be populated from the workspace owner's information. + ```hcl +module "git-config" { + source = "git::https://github.com/coder/modules.git//git-config?ref=git-config" + agent_id = coder_agent.main.id + username = data.coder_workspace.me.owner + user_email = data.coder_workspace.me.owner_email +} +``` + +### Custom credentials +Credentials can also be set manually. +```hcl +module "git-config" { + source = "git::https://github.com/coder/modules.git//git-config?ref=git-config" + agent_id = coder_agent.main.id + username = "michael" + user_email = "michael@example.com" +} ``` + diff --git a/git-config/run.sh b/git-config/run.sh index a6da232..06249a3 100644 --- a/git-config/run.sh +++ b/git-config/run.sh @@ -8,20 +8,20 @@ printf "$${BOLD}Checking git-config!\n" # Check if git is installed command -v git >/dev/null 2>&1 || { - echo "git is not installed! Install git to sync username and email." + echo "git is not installed! Install git to sync username and email.\n" exit 1 } # Set git username and email if not set if [ -z $(git config --get user.email) ]; then - printf "git-config: No user.email found, setting to ${CODER_EMAIL}" + printf "git-config: No user.email found, setting to ${CODER_EMAIL}\n" git config --global user.email ${CODER_EMAIL} fi if [ -z $(git config --get user.name) ]; then - printf "git-config: No user.name found, setting to ${CODER_USERNAME}" + printf "git-config: No user.name found, setting to ${CODER_USERNAME}\n" git config --global user.name ${CODER_USERNAME} fi -printf "$${BOLD}git-config: using username: $(git config --get user.name)" -printf "$${BOLD}git-config: using email: $(git config --get user.email)" +printf "\n$${BOLD}git-config: using username: $(git config --get user.name)\n" +printf "$${BOLD}git-config: using email: $(git config --get user.email)\n"