mkhomedir golden
mksourcedir

# test that chezmoi apply --dry-run does not create any files
chezmoi apply --dry-run --force
! exists $HOME/.absent
! exists $HOME/.dir
! exists $HOME/.dir/file
! exists $HOME/.dir/subdir
! exists $HOME/.dir/subdir/file
! exists $HOME/.empty
! exists $HOME/.executable
! exists $HOME/.exists
! exists $HOME/.file
! exists $HOME/.private
! exists $HOME/.template

# test that chezmoi apply file creates a single file only
chezmoi apply --force $HOME${/}.file
! exists $HOME/.absent
! exists $HOME/.dir
! exists $HOME/.dir/file
! exists $HOME/.dir/subdir
! exists $HOME/.dir/subdir/file
! exists $HOME/.empty
! exists $HOME/.executable
! exists $HOME/.exists
exists $HOME/.file
! exists $HOME/.private
! exists $HOME/.template

# test that chezmoi apply dir --recursive=false creates only the directory
chezmoi apply --force --recursive=false $HOME${/}.dir
exists $HOME/.dir
! exists $HOME/.dir/file
! exists $HOME/.dir/subdir
! exists $HOME/.dir/subdir/file

# test that chezmoi apply dir creates all files in the directory
chezmoi apply --force $HOME${/}.dir
exists $HOME/.dir
exists $HOME/.dir/file
exists $HOME/.dir/subdir
exists $HOME/.dir/subdir/file

# test that chezmoi apply creates all files
chezmoi apply --force
! exists $HOME/.absent
exists $HOME/.dir
exists $HOME/.dir/file
exists $HOME/.dir/subdir
exists $HOME/.dir/subdir/file
exists $HOME/.empty
exists $HOME/.executable
exists $HOME/.exists
exists $HOME/.file
exists $HOME/.private
exists $HOME/.template

# test apply after edit
edit $CHEZMOISOURCEDIR/dot_file
chezmoi apply --force
cmp $HOME/.file $CHEZMOISOURCEDIR/dot_file

# test that chezmoi apply --source-path applies a file based on its source path
edit $CHEZMOISOURCEDIR/dot_file
chezmoi apply --force --source-path $CHEZMOISOURCEDIR/dot_file
grep -count=2 '# edited' $HOME/.file

# test that chezmoi apply --source-path fails when called with a targetDirAbsPath
! chezmoi apply --force --source-path ${HOME}${/}.file
