[windows] stop 'UNIX only' # FIXME
[!exec:sed] stop
[!umask:022] skip

cp golden/.modify home/user

# test that chezmoi cat prints the modified contents without modifying the file
chezmoi cat $HOME${/}.modify
cmp stdout golden/.modified
cmp home/user/.modify golden/.modify

# test that chezmoi diff prints the diff without modifying the file
chezmoi diff
cmp stdout golden/diff
cmp home/user/.modify golden/.modify

# test that chezmoi archive includes the modified file
chezmoi archive --output=archive.tar
[exec:tar] exec tar xf archive.tar
[exec:tar] cmp .modify golden/.modified
cmp home/user/.modify golden/.modify

# test that chezmoi apply modifies the file
chezmoi apply --force
cmp home/user/.modify golden/.modified

chhome home2/user

# test that chezmoi cat does not fail or generate output when the target does not exist
chezmoi cat $HOME${/}.not_exist
! stdout .

# test that chezmoi cat exits with an error when the modify script fails
! chezmoi cat $HOME${/}.error
stderr error

# test that chezmoi apply updates file permissions
cmpmod 666 $HOME/.file
chezmoi apply $HOME${/}.file
cmpmod 700 $HOME/.file

-- golden/.modified --
beginning
modified-middle
end
-- golden/.modify --
beginning
middle
end
-- golden/diff --
diff --git a/.modify b/.modify
index f91830d4ecd80adfe9a6aea9dca579397aa86921..6b6d41aae5e8d64a54afd8b8ad5a38a3de1e1e35 100644
--- a/.modify
+++ b/.modify
@@ -1,3 +1,3 @@
 beginning
-middle
+modified-middle
 end
-- home/user/.local/share/chezmoi/modify_dot_modify --
#!/bin/sh

sed 's/middle/modified-middle/g'
-- home2/user/.file --
# contents of .file
-- home2/user/.local/share/chezmoi/modify_dot_not_exist --
#!/bin/sh

cat
-- home2/user/.local/share/chezmoi/modify_dot_error --
#!/bin/sh

echo error >2
exit 1
-- home2/user/.local/share/chezmoi/modify_private_executable_dot_file --
#!/bin/sh

cat
