Files
xavierandClaude Sonnet 5 a787c7ed51 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
2026-09-11 23:42:19 +02:00

71 lines
1.5 KiB
Cheetah

{{- $hostname := output "hostname" | trim -}}
{{- $username := .chezmoi.username -}}
{{- $currentHost := index .hosts $hostname -}}
{{- $currentUser := "" -}}
{{- if $currentHost -}}
{{- if hasKey $currentHost.users $username -}}
{{- $currentUser = index $currentHost.users $username -}}
{{- end -}}
{{- end -}}
{{- $gitConfig := dict -}}
{{- if and $currentUser (hasKey $currentUser "configs") -}}
{{- if hasKey $currentUser.configs "git" -}}
{{- $gitConfig = $currentUser.configs.git -}}
{{- end -}}
{{- end -}}
{{- $gitName := "Xavier Logerais" -}}
{{- $gitEmail := "xavier@logerais.com" -}}
{{- if hasKey $gitConfig "name" -}}
{{- $gitName = $gitConfig.name -}}
{{- end -}}
{{- if hasKey $gitConfig "email" -}}
{{- $gitEmail = $gitConfig.email -}}
{{- end -}}
[core]
excludesfile = ~/.config/git/ignore
attributesfile = ~/.config/git/attributes
pager = delta
[user]
name = {{ $gitName }}
email = {{ $gitEmail }}
[credential]
helper = cache
[credential "https://gitea.logerais.com"]
helper = cache
helper = !tea login helper
[credential "https://gitea.cloud.logerais.com"]
helper = cache
helper = !tea login helper
[init]
defaultBranch = main
[rerere]
enabled = 1
[merge]
conflictstyle = diff3
[page]
diff = delta
show = delta
log = delta
blame = delta
reflog = delta
[delta]
navigate = true
side-by-side = true
dark = true
syntax-theme = Coldark-Dark
[interactive]
diffFilter = delta --color-only
[alias]
tree = !git ls-files | tree --fromfile -C