Skip to content

Commit f97e34d

Browse files
tarebyteCopilot
andcommitted
Render git config on Codespaces without identity
Instead of skipping git config entirely on Codespaces, render the template with aliases, colors, filters, and pager settings — just strip the identity placeholders (EMAIL, SIGNINGKEY) and disable gpgsign since Codespaces injects identity via ~/.gitconfig. Update the test to verify the Codespaces path renders the config with placeholders removed and gpgsign disabled. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 2c193ff commit f97e34d

2 files changed

Lines changed: 31 additions & 8 deletions

File tree

script/setup-git-config

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,29 @@
2323

2424
set -euo pipefail
2525

26-
if [ -n "${CODESPACES:-}" ]; then
27-
echo "Skipping git config setup on Codespaces"
28-
exit 0
29-
fi
30-
3126
REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)"
3227
GIT_TEMPLATE="$REPO_ROOT/templates/git-config.tmpl"
3328
GIT_CONFIG="$HOME/.config/git/config"
3429
IDENTITY_DIR="$HOME/.config/dotfiles"
3530
IDENTITY_FILE="$IDENTITY_DIR/identity.env"
3631

32+
if [ -n "${CODESPACES:-}" ]; then
33+
# Codespaces injects identity (name, email, credential helper) into
34+
# ~/.gitconfig, so we only need the template for aliases, colors,
35+
# filters, etc. Strip the identity/signing lines and render as-is.
36+
mkdir -p "$HOME/.config/git"
37+
tmp=$(mktemp "$GIT_CONFIG.XXXXXX")
38+
trap 'rm -f "$tmp"' EXIT
39+
sed -e '/{{EMAIL}}/d' \
40+
-e '/{{SIGNINGKEY}}/d' \
41+
-e 's/gpgsign = true/gpgsign = false/' \
42+
"$GIT_TEMPLATE" > "$tmp"
43+
mv "$tmp" "$GIT_CONFIG"
44+
trap - EXIT
45+
echo "Wrote $GIT_CONFIG (Codespaces mode — identity from ~/.gitconfig)"
46+
exit 0
47+
fi
48+
3749
mkdir -p "$HOME/.config/git"
3850
mkdir -p "$IDENTITY_DIR"
3951
chmod 700 "$IDENTITY_DIR"

script/test

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,19 @@ test_git_config_codespaces_skip() {
215215
set -e
216216
mkdir -p "$sandbox/home"
217217
CODESPACES=1 HOME="$sandbox/home" "$REPO_ROOT/script/setup-git-config" > /dev/null
218-
[ ! -f "$sandbox/home/.config/git/config" ] \
219-
|| { echo "codespaces path should skip rendering"; exit 1; }
218+
[ -f "$sandbox/home/.config/git/config" ] \
219+
|| { echo "codespaces path should render config"; exit 1; }
220+
# identity lines should be stripped
221+
! grep -q '{{EMAIL}}' "$sandbox/home/.config/git/config" \
222+
|| { echo "template placeholder {{EMAIL}} should be removed"; exit 1; }
223+
! grep -q '{{SIGNINGKEY}}' "$sandbox/home/.config/git/config" \
224+
|| { echo "template placeholder {{SIGNINGKEY}} should be removed"; exit 1; }
225+
# gpgsign should be disabled
226+
grep -q 'gpgsign = false' "$sandbox/home/.config/git/config" \
227+
|| { echo "gpgsign should be false in codespaces mode"; exit 1; }
228+
# aliases should still be present
229+
grep -q '\[alias\]' "$sandbox/home/.config/git/config" \
230+
|| { echo "aliases should be present in codespaces config"; exit 1; }
220231
}
221232

222233
test_git_config_missing_email() {
@@ -255,7 +266,7 @@ echo
255266
echo "=== setup-git-config ==="
256267
run_test "basic template render" test_git_config_basic_render
257268
run_test "sed metacharacter escaping" test_git_config_sed_metachars
258-
run_test "codespaces skip" test_git_config_codespaces_skip
269+
run_test "codespaces render" test_git_config_codespaces_skip
259270
run_test "missing EMAIL errors" test_git_config_missing_email
260271
run_test "missing SIGNINGKEY errors" test_git_config_missing_signingkey
261272

0 commit comments

Comments
 (0)