[!umask:022] skip

mkhomedir golden
mkhomedir
mksourcedir

# test that chezmoi diff generates no output when the source and destination states are equal
chezmoi diff
! stdout .

# test that chezmoi diff generates a diff when a file is added to the source state
cp golden/dot_newfile $CHEZMOISOURCEDIR/dot_newfile
chezmoi diff
[!windows] cmp stdout golden/add-newfile-diff-unix
[windows] cmp stdout golden/add-newfile-diff-windows
rm $CHEZMOISOURCEDIR/dot_newfile

# test that chezmoi diff generates a diff when a file is edited
edit $HOME/.file
chezmoi diff
[!windows] cmp stdout golden/modify-file-diff-unix
[windows] cmp stdout golden/modify-file-diff-windows
chezmoi apply --force $HOME${/}.file

# test chezmoi diff --reverse
edit $HOME/.file
chezmoi diff --reverse
[!windows] cmp stdout golden/modify-file-diff-reverse-unix
[windows] cmp stdout golden/modify-file-diff-reverse-windows
chezmoi apply --force $HOME${/}.file

# test that chezmoi diff generates a diff when a file is removed from the destination directory
rm $HOME/.file
chezmoi diff
[!windows] cmp stdout golden/restore-file-diff-unix
[windows] cmp stdout golden/restore-file-diff-windows
chezmoi apply --force $HOME${/}.file

# test that chezmoi diff generates a diff when a directory is removed from the destination directory
rm $HOME/.dir
chezmoi diff --recursive=false $HOME${/}.dir
[!windows] cmp stdout golden/restore-dir-diff-unix
[windows] cmp stdout golden/restore-dir-diff-windows
chezmoi apply --force $HOME${/}.dir

# test that chezmoi diff generates a diff when the actual state is a file and the target state is a symlink
rm $HOME/.symlink
cp golden/.file $HOME/.symlink
chezmoi diff
[!windows] cmp stdout golden/symlink-file-diff-unix
# [windows] cmp stdout golden/symlink-file-diff-windows # FIXME
chezmoi apply --force $HOME${/}.symlink

[windows] stop 'remaining tests use file modes'

# test that chezmoi diff generates a diff when a file's permissions are changed
chmod 777 $HOME/.file
chezmoi diff
cmp stdout golden/chmod-file-diff
chezmoi apply --force $HOME${/}.file

# test that chezmoi diff generates a diff when a directory's permissions are changed
chmod 700 $HOME/.dir
chezmoi diff
cmp stdout golden/chmod-dir-diff
chezmoi apply --force --recursive=false $HOME${/}.dir

-- golden/add-newfile-diff-unix --
diff --git a/.newfile b/.newfile
new file mode 100644
index 0000000000000000000000000000000000000000..06e05235fdd12fd5c367b6d629fef94536c85525
--- /dev/null
+++ b/.newfile
@@ -0,0 +1 @@
+# contents of .newfile
-- golden/add-newfile-diff-windows --
diff --git a/.newfile b/.newfile
new file mode 100666
index 0000000000000000000000000000000000000000..06e05235fdd12fd5c367b6d629fef94536c85525
--- /dev/null
+++ b/.newfile
@@ -0,0 +1 @@
+# contents of .newfile
-- golden/modify-file-diff-unix --
diff --git a/.file b/.file
index 5d2730a8850a2db479af83de87cc8345437aef06..8a52cb9ce9551221716a53786ad74104c5902362 100644
--- a/.file
+++ b/.file
@@ -1,2 +1 @@
 # contents of .file
-# edited
-- golden/modify-file-diff-windows --
diff --git a/.file b/.file
index 5d2730a8850a2db479af83de87cc8345437aef06..8a52cb9ce9551221716a53786ad74104c5902362 100666
--- a/.file
+++ b/.file
@@ -1,2 +1 @@
 # contents of .file
-# edited
-- golden/modify-file-diff-reverse-unix --
diff --git a/.file b/.file
index 8a52cb9ce9551221716a53786ad74104c5902362..5d2730a8850a2db479af83de87cc8345437aef06 100644
--- a/.file
+++ b/.file
@@ -1 +1,2 @@
 # contents of .file
+# edited
-- golden/modify-file-diff-reverse-windows --
diff --git a/.file b/.file
index 8a52cb9ce9551221716a53786ad74104c5902362..5d2730a8850a2db479af83de87cc8345437aef06 100666
--- a/.file
+++ b/.file
@@ -1 +1,2 @@
 # contents of .file
+# edited
-- golden/restore-file-diff-unix --
diff --git a/.file b/.file
new file mode 100644
index 0000000000000000000000000000000000000000..8a52cb9ce9551221716a53786ad74104c5902362
--- /dev/null
+++ b/.file
@@ -0,0 +1 @@
+# contents of .file
-- golden/restore-file-diff-windows --
diff --git a/.file b/.file
new file mode 100666
index 0000000000000000000000000000000000000000..8a52cb9ce9551221716a53786ad74104c5902362
--- /dev/null
+++ b/.file
@@ -0,0 +1 @@
+# contents of .file
-- golden/restore-dir-diff-unix --
diff --git a/.dir b/.dir
new file mode 40755
index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
--- /dev/null
+++ b/.dir
-- golden/restore-dir-diff-windows --
diff --git a/.dir b/.dir
new file mode 40777
index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
--- /dev/null
+++ b/.dir
-- golden/symlink-file-diff-unix --
diff --git a/.symlink b/.symlink
deleted file mode 100644
index 8a52cb9ce9551221716a53786ad74104c5902362..0000000000000000000000000000000000000000
--- a/.symlink
+++ /dev/null
@@ -1 +0,0 @@
-# contents of .file
diff --git a/.symlink b/.symlink
old mode 100644
new mode 120000
index 8a52cb9ce9551221716a53786ad74104c5902362..9b91fdbb83798a67fbbc5cc4f120c3f7726c0d70
--- a/.symlink
+++ b/.symlink
@@ -1 +1 @@
-# contents of .file
+.dir/subdir/file
-- golden/dot_newfile --
# contents of .newfile
-- golden/chmod-file-diff --
diff --git a/.file b/.file
old mode 100777
new mode 100644
-- golden/chmod-dir-diff --
diff --git a/.dir b/.dir
old mode 40700
new mode 40755
-- golden/dot_newfile --
# contents of .newfile
