fix(git): Guard $gitConfig.name/email lookup against missing map keys

Accessing a missing key on a map value in text/template raises an
error before `default` can run, so `configs.git` without `name`/`email`
(or hosts without a `configs` key, e.g. termux-*) broke `chezmoi diff`
with "map has no entry for key". Use `hasKey` before accessing each
field instead.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0145M6KGu5gQ3brTPzqs8NwG
This commit is contained in:
2026-09-11 23:42:19 +02:00
co-authored by Claude Sonnet 5
parent e17a18d7c5
commit a787c7ed51
+8 -2
View File
@@ -13,8 +13,14 @@
{{- $gitConfig = $currentUser.configs.git -}} {{- $gitConfig = $currentUser.configs.git -}}
{{- end -}} {{- end -}}
{{- end -}} {{- end -}}
{{- $gitName := $gitConfig.name | default "Xavier Logerais" -}} {{- $gitName := "Xavier Logerais" -}}
{{- $gitEmail := $gitConfig.email | default "xavier@logerais.com" -}} {{- $gitEmail := "xavier@logerais.com" -}}
{{- if hasKey $gitConfig "name" -}}
{{- $gitName = $gitConfig.name -}}
{{- end -}}
{{- if hasKey $gitConfig "email" -}}
{{- $gitEmail = $gitConfig.email -}}
{{- end -}}
[core] [core]
excludesfile = ~/.config/git/ignore excludesfile = ~/.config/git/ignore
attributesfile = ~/.config/git/attributes attributesfile = ~/.config/git/attributes