# 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 = "user@home.org"
-- golden/state-dump.yaml --
configState:
    configState:
        configTemplateContentsSHA256: f79e9af9aab3822d28ba929391ebc14882169abd8613aec85c5a60d46d58ee32
entryState: {}
scriptState: {}
-- home/user/.local/share/chezmoi/.chezmoi.toml.tmpl --
[data]
  email = "user@home.org"
-- home/user/.local/share/chezmoi/.git/.keep --
-- home2/user/.local/share/chezmoi/.keep --

