twpayne / chezmoi

Manage your dotfiles across multiple diverse machines, securely.
https://www.chezmoi.io/
MIT License
12.9k stars 478 forks source link

`fromIni` reads a `DEFAULT` key even if there is none in the input #2768

Closed felipecrs closed 1 year ago

felipecrs commented 1 year ago

Describe the bug

I'm trying to refactor my wsl.conf file into a chezmoi modify template using the fromIni and toIni functions. However, every time fromIni runs, it appears to read some data that doesn't exist.

To reproduce

$ chezmoi execute-template '{{ printf "%s\n%s" "[boot]" "systemd=true" | fromIni | toIni}}'

[DEFAULT]

[boot]
systemd = "true"

$ chezmoi execute-template '{{ printf "%s\n%s" "[boot]" "systemd=true" | fromIni | toYaml }}'
DEFAULT: {}
boot:
    systemd: "true"

Expected behavior

To not have this key added to the dict.

halostatue commented 1 year ago

With #2770

$ go run . execute-template '{{ printf "%s\n%s" "[boot]" "systemd=true" | fromIni | toIni}}'

[boot]
systemd = "true"

$ go run . execute-template '{{ printf "%s\n%s" "[boot]" "systemd=true" | fromIni | toYaml }}'
boot:
    systemd: "true"