Skip to content

git: stop overwriting the user's identity on every run - #30

Open
presto8 wants to merge 1 commit into
mainfrom
fix/gitconfig-identity
Open

presto8 wants to merge 1 commit into
mainfrom
fix/gitconfig-identity

Conversation

@presto8

@presto8 presto8 commented Aug 29, 2026

Copy link
Copy Markdown
Owner

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
unknown@unknown.com' 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.


🤖 Generated with Claude Code

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
<unknown@unknown.com>' 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) <noreply@anthropic.com>
Copilot AI lite review requested due to automatic review settings August 29, 2026 16:49

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The changes directly address the identity-clobbering behavior with a small, well-contained update that preserves existing settings and avoids reintroducing placeholder values.

Pull request overview

This PR prevents setup_git from clobbering a user’s Git author identity by removing the hard-coded [user] placeholder from the shipped gitconfig and explicitly preserving/restoring user.name / user.email around the ~/.gitconfig overwrite.

Changes:

  • Capture existing user.name / user.email before overwriting ~/.gitconfig, treating the prior placeholder values as “absent”.
  • Allow GIT_USER_NAME / GIT_USER_EMAIL to override the preserved values, then re-apply them via git config --global.
  • Remove the [user] section from the shipped gitconfig and document the identity behavior inline.
File summaries
File Description
setup Preserves/restores Git identity around overwriting ~/.gitconfig, supports env overrides, and prints guidance when identity is missing.
gitconfig Removes hard-coded placeholder identity and documents why the file intentionally lacks a [user] section.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants