mkhomedir
mksourcedir

# test that chezmoi remove file removes a file
chezmoi apply --force
exists $HOME/.file
chezmoi remove --force $HOME${/}.file
! exists $HOME/.file
chezmoi state get --bucket=entryState --key=$WORK/home/user/.file
! stdout .

# test that chezmoi remove dir removes a directory
exists $HOME/.dir
chezmoi remove --force $HOME${/}.dir
! exists $HOME/.dir

# test that if any chezmoi remove stops on any error
exists $HOME/.executable
! chezmoi remove --force $HOME${/}.newfile $HOME${/}.executable
stderr 'not in source state'
exists $HOME/.executable

chhome home2/user

# test that chezmoi apply removes a file and a directory
exists $HOME/.file
exists $HOME/.dir
chezmoi apply
! exists $HOME/.file
! exists $HOME/.dir

chhome home3/user

# test that chezmoi apply with .chezmoiremove with star works on destination dir with trailing slash
exists $HOME/.star-file
exists $HOME/.star-dir
chezmoi apply --destination=$HOME/
! exists $HOME/.star-file
! exists $HOME/.star-dir

-- home2/user/.dir/.keep --
-- home2/user/.file --
# contents of .file
-- home2/user/.local/share/chezmoi/remove_dot_file --
-- home2/user/.local/share/chezmoi/remove_dot_dir --

-- home3/user/.star-dir/.keep --
-- home3/user/.star-file --
# contents of .star-file
-- home3/user/.local/share/chezmoi/.chezmoiremove --
.*-dir/
.*-file
