# test that chezmoi init creates a config file and updates the state
chezmoi init
cmp $CHEZMOICONFIGDIR/chezmoi.toml golden/chezmoi.toml
chezmoi state dump --format=yaml
cmp stdout golden/state-dump.yaml
! stderr .

# test that chezmoi apply succeeds
chezmoi apply
! stderr .

# test that chezmoi apply prints a warning if the config file template has been changed
cp golden/.chezmoi.toml.tmpl $CHEZMOISOURCEDIR/.chezmoi.toml.tmpl
chezmoi apply
stderr 'warning: config file template has changed'

# test that chezmoi init re-generates the config file
chezmoi init
cmp $CHEZMOICONFIGDIR/chezmoi.toml golden/chezmoi.toml
! stderr .

# test that chezmoi apply no longer prints a warning after the config file is regenerated
chezmoi apply
! stderr .

# test that chezmoi apply --force ignores config file changes and updates the state
edit $CHEZMOISOURCEDIR/.chezmoi.toml.tmpl
grep '# edited' $CHEZMOISOURCEDIR/.chezmoi.toml.tmpl
chezmoi apply --force
! stderr .
! grep '# edited' $CHEZMOICONFIGDIR/chezmoi.toml

chhome home2/user

# test that chezmoi diff prints a warning when a config file template is added
chezmoi diff
! stderr .
cp golden/chezmoi.toml $CHEZMOISOURCEDIR/.chezmoi.toml.tmpl
chezmoi diff
stderr 'warning: config file template has changed'

# test that chezmoi diff does not print a warning when the config file template is removed
rm $CHEZMOISOURCEDIR/.chezmoi.toml.tmpl
chezmoi diff
! stderr .

-- golden/.chezmoi.toml.tmpl --
{{ $email := get . "email" -}}
{{ if not $email -}}
{{   $email = promptString "email" -}}
{{ end -}}
[data]
    email = {{ $email | quote }}
-- golden/chezmoi.toml --
[data]
    email = "me@home.org"
-- golden/state-dump.yaml --
configState:
    configState:
        configTemplateContentsSHA256: af43121a524340707b84e390f510c949731177e6f2a25b3b6b11b2fc656cf8f2
entryState: {}
scriptState: {}
-- home/user/.local/share/chezmoi/.chezmoi.toml.tmpl --
[data]
    email = "me@home.org"
-- home/user/.local/share/chezmoi/.git/.keep --
-- home2/user/.local/share/chezmoi/.keep --

