From fb32374bb74ddbbf0bd3bf9fa3ea7387bd21c2dd Mon Sep 17 00:00:00 2001 From: Preston Hunt Date: Sat, 29 Aug 2026 09:45:49 -0700 Subject: [PATCH] git: stop overwriting the user's identity on every run The tracked gitconfig hard-coded a [user] section: [user] email = unknown@unknown.com name = Unknown User setup_git copies that file over ~/.gitconfig on every run, so every provisioned machine silently had its git identity replaced by the placeholder. Commits then get authored as 'Unknown User ' with no error and no prompt -- git only refuses to commit when an identity is absent, not when it is wrong. Drop the [user] section from the shipped file, and have setup_git carry the identity across the overwrite: - read user.name/user.email before the copy and restore them after - treat the old placeholder values as absent, so machines already clobbered by a previous run recover instead of keeping them - let GIT_USER_NAME / GIT_USER_EMAIL override (these can be exported, or set in config.local once that mechanism lands) - print the two commands to run when no identity can be determined, rather than leaving a config that looks populated but is wrong Verified against throwaway HOMEs: a real identity is preserved; the placeholder is discarded; a machine with no identity gets the hint; an explicit GIT_USER_* wins over an existing value; and the aliases from the shipped gitconfig are still installed in every case. Co-Authored-By: Claude Opus 5 (1M context) --- gitconfig | 8 +++++--- setup | 34 +++++++++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/gitconfig b/gitconfig index 44dabc8..facd56a 100644 --- a/gitconfig +++ b/gitconfig @@ -1,6 +1,8 @@ -[user] - email = unknown@unknown.com - name = Unknown User +# NOTE: deliberately no [user] section. This file is copied over +# ~/.gitconfig on every run, so hard-coding an identity here silently +# replaces the real one on every machine it is installed to. setup_git +# preserves whatever identity is already configured, or takes it from +# GIT_USER_NAME / GIT_USER_EMAIL. [color] diff = auto diff --git a/setup b/setup index df939ed..31c3756 100755 --- a/setup +++ b/setup @@ -216,7 +216,39 @@ setup_ssh() { setup_git() { install_package git git-lfs - get_prestobuntu_file gitconfig $HOME/.gitconfig + + # ~/.gitconfig is overwritten wholesale below, so capture any + # identity already configured and put it back afterwards. Ignore the + # old placeholder, which earlier versions of this script installed. + local name email + name=$(git config --global --get user.name || true) + email=$(git config --global --get user.email || true) + if [[ $name == "Unknown User" ]]; then + name="" + fi + if [[ $email == "unknown@unknown.com" ]]; then + email="" + fi + + get_prestobuntu_file gitconfig "$HOME/.gitconfig" + + # An explicit setting wins over whatever was there before. These may + # be exported, or set in config.local once that mechanism lands. + name=${GIT_USER_NAME:-$name} + email=${GIT_USER_EMAIL:-$email} + + if [[ -n $name ]]; then + git config --global user.name "$name" + fi + if [[ -n $email ]]; then + git config --global user.email "$email" + fi + + if [[ -z $name || -z $email ]]; then + info "git identity not set; run:" + info " git config --global user.name 'Your Name'" + info " git config --global user.email 'you@example.com'" + fi } get_internet_file() {