[windows] skip 'UNIX only'
[!exec:gpg] skip 'gpg not found in $PATH'

chmod 755 bin/edit-source
mkgpgconfig
appendline $CHEZMOICONFIGDIR/chezmoi.toml '[merge]'
appendline $CHEZMOICONFIGDIR/chezmoi.toml '    command = "cat"'

# test that chezmoi merge transparently decrypts the source
cp golden/source $HOME/.file
chezmoi add --encrypt $HOME${/}.file
chezmoi chattr +template $HOME${/}.file
cp golden/destination $HOME/.file
chezmoi merge $HOME${/}.file
cmp stdout golden/expected

chhome home2/user

mkgpgconfig
appendline $CHEZMOICONFIGDIR/chezmoi.toml '[merge]'
appendline $CHEZMOICONFIGDIR/chezmoi.toml '    command = "edit-source"'

# test that chezmoi merge transparently re-encrypts the source if it is edited
cp golden/source $HOME/.file
chezmoi add --encrypt $HOME${/}.file
chezmoi chattr +template $HOME${/}.file
cp golden/destination $HOME/.file
chezmoi merge $HOME${/}.file
chezmoi cat $HOME${/}.file
cmp stdout golden/edited-target

-- bin/edit-source --
#!/bin/sh

echo "# edited" >> $2
-- golden/destination --
destination
-- golden/expected --
destination
{{ "target" }}
target
-- golden/source --
{{ "target" }}
-- golden/edited-target --
target
# edited
