mkhomedir

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

# test that chezmoi add updates the persistent state
chezmoi add $HOME${/}.file
exists $CHEZMOICONFIGDIR/chezmoistate.boltdb
exists $CHEZMOISOURCEDIR/dot_file
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
chezmoi apply --dry-run $HOME${/}.file
chezmoi state dump
! stdout 2e9dd6a2a8c15b20d4b0882d4c0fb8c7eea4e8ece46818090b387132f9f84c34 # sha256sum of "# contents of .file\n# edited\n"
chezmoi apply $HOME${/}.file
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
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
chezmoi add $HOME${/}.dir/
! exists $CHEZMOISOURCEDIR/dot_dir/dot_dir

-- golden/.file --
# contents of .file
-- home2/user/.local/share/chezmoi/dot_file --
# contents of .file
