mkhomedir

# test that chezmoi add --dry-run does not modify anything
exec chezmoi add --dry-run $HOME${/}.file
! exists $CHEZMOICONFIGDIR/chezmoistate.boltdb
! exists $CHEZMOISOURCEDIR/dot_file

# test that chezmoi add updates the persistent state
exec chezmoi add $HOME${/}.file
exists $CHEZMOICONFIGDIR/chezmoistate.boltdb
exists $CHEZMOISOURCEDIR/dot_file
exec chezmoi state dump
stdout 634a4dd193c7b3b926d2e08026aa81a416fd41cec52854863b974af422495663 # sha256sum of "# contents of .file\n"

# test that chezmoi apply updates the state if the target and destination states match, even if the last written state does not
edit $CHEZMOISOURCEDIR/dot_file
edit $HOME/.file
cmp $HOME/.file $CHEZMOISOURCEDIR/dot_file
exec chezmoi apply --dry-run $HOME${/}.file
exec chezmoi state dump
! stdout 2e9dd6a2a8c15b20d4b0882d4c0fb8c7eea4e8ece46818090b387132f9f84c34 # sha256sum of "# contents of .file\n# edited\n"
exec chezmoi apply $HOME${/}.file
exec chezmoi state dump
stdout 2e9dd6a2a8c15b20d4b0882d4c0fb8c7eea4e8ece46818090b387132f9f84c34 # sha256sum of "# contents of .file\n# edited\n"

chhome home2/user

# test that the source directory can be a symlink to another directory
symlink $HOME/.chezmoi -> $CHEZMOISOURCEDIR
exec chezmoi apply --source=$HOME${/}.chezmoi
cmp $HOME/.file golden/.file

# test that adding a directory ending in a slash only adds the directory once
mkdir $HOME/.dir
exec chezmoi add $HOME${/}.dir/
! exists $CHEZMOISOURCEDIR/dot_dir/dot_dir

chhome home3/user

# test that chezmoi reports an inconsistent state error when a file should be both removed and present
! exec chezmoi apply
stderr 'chezmoi: \.file: inconsistent state'

chhome home4/user

# test that chezmoi reports an error if there is a .chezmoi* file in the .chezmoitemplates directory
! exec chezmoi status
! stderr 'not allowed in \.chezmoitemplates directory'

# test that chezmoi data returns an error if an unknown read format is specified
! exec chezmoi init --config-format=yml
stderr 'invalid or unsupported data format'

# test that chezmoi data returns an error if an unknown write format is specified
! exec chezmoi data --format=yml
stderr 'invalid or unsupported data format'

skip 'FIXME make the following test pass'
chhome home6/user

# test that chezmoi reports an inconsistent state error when a file should be both removed and present, even if the file is not already present
! exec chezmoi apply
stderr 'chezmoi: \.file: inconsistent state

-- golden/.file --
# contents of .file
-- home2/user/.local/share/chezmoi/dot_file --
# contents of .file
-- home3/user/.file --
# contents of .file
-- home3/user/.local/share/chezmoi/.chezmoiremove --
.file
-- home3/user/.local/share/chezmoi/dot_file --
# contents of .file
-- home4/user/.local/share/chezmoi/.chezmoitemplates/.chezmoiignore --
-- home5/user/.local/share/chezmoi/.chezmoiremove --
.file
-- home6/user/.local/share/chezmoi/dot_file --
# contents of .file
