fix(forge): use real identity for git user.name, not the hostname #167
No reviewers
Labels
No labels
prio_critical
prio_low
type_bug
type_contact
type_issue
type_lead
type_question
type_story
type_task
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
lhumina_code/hero_skills!167
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "development_git_identity_fix"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What
forge_git_ensure_identityfell back to the box's hostname whenever git's globaluser.namewas empty. Every commit pushed from kristof1/3/4/6 (or any other Hero box) ended up authored as the hostname rather than the operator — confusing in Forgejo's author column and worse on shared boxes where multiple users push from the same machine.Noticed today: commits from remote servers all read as
kristof4/kristof6/etc.Fix
Two files:
tools/modules/secrets_lib.nu— addgit_name = ""to the[cfg]section of the secrets template, with a one-line comment.tools/modules/forge.nu— pull the hand-rolled toml-get intoforge_secrets_toml_get(reusable), then resolveuser.namethrough:Detect
current name == hostnameas a still-placeholder state so existing installs that already picked up the hostname get re-derived on the nextforge_gitcall (mirrors the existingemail == hero@localhostcheck).Rollout
No action required from users in normal login sessions —
$USERalready resolves to the right thing, and the existing-install detection rewritesuser.nameautomatically on the nextforge_gitcall.For users who want a specific display name (e.g. "Mahmoud Hassanein" instead of
mahmoud), setgit_namein~/hero/code/secrets/secrets.toml's[cfg]section.forge_git_ensure_identity fell back to the box's hostname whenever git's global user.name was empty. Result: every commit pushed from kristof1/3/4/6 (or any other Hero box) showed up in Forgejo as the hostname instead of the operator. Confusing for code review and audit, and worse on shared boxes where multiple users push from the same machine. Two fixes: 1. tools/modules/secrets_lib.nu — add `git_name = ""` to the [cfg] section of the secrets template, with a comment explaining what it controls. 2. tools/modules/forge.nu — refactor toml-get into a reusable forge_secrets_toml_get helper, then resolve user.name via the chain: secrets.toml git_name → $USER → whoami → hostname Hostname is the absolute last resort, not the only source. Also: detect "current name == hostname" as a still-placeholder state so existing installs that picked up the hostname before this fix get re-derived on the next forge_git call. Same idea as the existing "email == hero@localhost" check. To roll out across the fleet: each user sets git_name in their own ~/hero/code/secrets/secrets.toml, or relies on $USER (which is already correct for any normal login session). The next forge_git invocation rewrites user.name globally.scripts/test_forge_identity.nu — 15 black-box cases for the two helpers introduced in this PR: forge_secrets_toml_get T1 missing file → "" T2 key absent → "" T3 quoted value → unquoted T4 empty-quotes → "" T5 case-insensitive on the key name T6 key in any section, not just [cfg] forge_git_ensure_identity (user.name) T7 git_name in secrets → wins T8 no secrets git_name + USER set → use $USER T9 no secrets git_name + no USER → whoami T10 name == hostname (the actual bug) → re-derived from chain T11 name == hostname + no git_name → $USER (still rewrites) T12 real pre-existing name (not hostname, not empty) → preserved forge_git_ensure_identity (user.email) T13 mail_username in secrets → use it T14 email == hero@localhost (placeholder) → re-derived T15 real pre-existing email → preserved Each case runs in a fresh `mktemp -d` HOME so the operator's real ~/.gitconfig is never touched. The two helpers are inlined verbatim (rather than sourced) because forge.nu has `export def main` which collides with this script's structure when sourced; comment in the test reminds the maintainer to keep them in sync. Verified locally on macOS (Mahmouds-Laptop.local, hostname≠whoami) and on kristof4 Linux (hostname == "kristof4", reproduces the original bug exactly via T10). 15/15 pass on both.Tests added (commit
f178033)scripts/test_forge_identity.nu— 15 black-box cases, run withnu scripts/test_forge_identity.nu. Every case runs in a freshmktemp -dHOME so the operator's real~/.gitconfigis never touched.Coverage
forge_secrets_toml_get(6 cases)""""""GIT_NAMEfindsgit_name = ...)[cfg]forge_git_ensure_identityuser.name chain (6 cases — covers each branch + the auto-correct)git_name→ use itgit_name+$USERset → use$USERgit_name+ no$USER→ fall back towhoamigit_name→ re-derivedgit_name→$USER(still rewrites)forge_git_ensure_identityuser.email (3 cases)mail_username→ use ithero@localhostplaceholder → re-derivedVerified on both platforms
T10 on kristof4 reproduces the exact original bug: starting
git config user.name = "kristof4", the function rewrites it to the secretsgit_name. That's the auto-correct that fixes already-misconfigured installs on the nextforge_gitcall.One implementation note in the test
The two helpers are inlined verbatim in the test (rather than
source-ingtools/modules/forge.nu) becauseforge.nuhasexport def mainand that collides with the test script's structure on source. There's a comment in the test reminding maintainers to keep the inlined copies in sync. Net cost: ~35 lines duplicated in the test; benefit: the test runs cleanly with no module side-effects.