3 test_description
='post index change hook'
7 test_expect_success
'setup' '
9 touch dir1/file1.txt &&
10 echo testing >dir1/file2.txt &&
12 git commit -m "initial"
15 test_expect_success
'test status, add, commit, others trigger hook without flags set' '
16 mkdir -p .git/hooks &&
17 write_script .git/hooks/post-index-change <<-\EOF &&
18 if test "$1" -eq 1; then
19 echo "Invalid combination of flags passed to hook; updated_workdir is set." >testfailure
22 if test "$2" -eq 1; then
23 echo "Invalid combination of flags passed to hook; updated_skipworktree is set." >testfailure
26 if test -f ".git/index.lock"; then
27 echo ".git/index.lock exists" >testfailure
30 if ! test -f ".git/index"; then
31 echo ".git/index does not exist" >testfailure
34 echo "success" >testsuccess
37 touch dir2/file1.txt &&
38 touch dir2/file2.txt &&
39 : force index to be dirty &&
40 test-tool chmtime +60 dir1/file1.txt &&
42 test_path_is_file testsuccess && rm -f testsuccess &&
43 test_path_is_missing testfailure &&
45 test_path_is_file testsuccess && rm -f testsuccess &&
46 test_path_is_missing testfailure &&
47 git commit -m "second" &&
48 test_path_is_file testsuccess && rm -f testsuccess &&
49 test_path_is_missing testfailure &&
50 git checkout -- dir1/file1.txt &&
51 test_path_is_file testsuccess && rm -f testsuccess &&
52 test_path_is_missing testfailure &&
54 test_path_is_missing testsuccess &&
55 test_path_is_missing testfailure &&
57 test_path_is_missing testsuccess &&
58 test_path_is_missing testfailure
61 test_expect_success
'test checkout and reset trigger the hook' '
62 write_script .git/hooks/post-index-change <<-\EOF &&
63 if test "$1" -eq 1 && test "$2" -eq 1; then
64 echo "Invalid combination of flags passed to hook; updated_workdir and updated_skipworktree are both set." >testfailure
67 if test "$1" -eq 0 && test "$2" -eq 0; then
68 echo "Invalid combination of flags passed to hook; neither updated_workdir or updated_skipworktree are set." >testfailure
71 if test "$1" -eq 1; then
72 if test -f ".git/index.lock"; then
73 echo "updated_workdir set but .git/index.lock exists" >testfailure
76 if ! test -f ".git/index"; then
77 echo "updated_workdir set but .git/index does not exist" >testfailure
81 echo "update_workdir should be set for checkout" >testfailure
84 echo "success" >testsuccess
86 : force index to be dirty &&
87 test-tool chmtime +60 dir1/file1.txt &&
88 git checkout master &&
89 test_path_is_file testsuccess && rm -f testsuccess &&
90 test_path_is_missing testfailure &&
91 test-tool chmtime +60 dir1/file1.txt &&
93 test_path_is_file testsuccess && rm -f testsuccess &&
94 test_path_is_missing testfailure &&
95 test-tool chmtime +60 dir1/file1.txt &&
97 test_path_is_file testsuccess && rm -f testsuccess &&
98 test_path_is_missing testfailure &&
99 git checkout -B test &&
100 test_path_is_file testsuccess && rm -f testsuccess &&
101 test_path_is_missing testfailure
104 test_expect_success
'test reset --mixed and update-index triggers the hook' '
105 write_script .git/hooks/post-index-change <<-\EOF &&
106 if test "$1" -eq 1 && test "$2" -eq 1; then
107 echo "Invalid combination of flags passed to hook; updated_workdir and updated_skipworktree are both set." >testfailure
110 if test "$1" -eq 0 && test "$2" -eq 0; then
111 echo "Invalid combination of flags passed to hook; neither updated_workdir or updated_skipworktree are set." >testfailure
114 if test "$2" -eq 1; then
115 if test -f ".git/index.lock"; then
116 echo "updated_skipworktree set but .git/index.lock exists" >testfailure
119 if ! test -f ".git/index"; then
120 echo "updated_skipworktree set but .git/index does not exist" >testfailure
124 echo "updated_skipworktree should be set for reset --mixed and update-index" >testfailure
127 echo "success" >testsuccess
129 : force index to be dirty &&
130 test-tool chmtime +60 dir1/file1.txt &&
131 git reset --mixed --quiet HEAD~1 &&
132 test_path_is_file testsuccess && rm -f testsuccess &&
133 test_path_is_missing testfailure &&
134 git hash-object -w --stdin <dir1/file2.txt >expect &&
135 git update-index --cacheinfo 100644 "$(cat expect)" dir1/file1.txt &&
136 test_path_is_file testsuccess && rm -f testsuccess &&
137 test_path_is_missing testfailure &&
138 git update-index --skip-worktree dir1/file2.txt &&
139 git update-index --remove dir1/file2.txt &&
140 test_path_is_file testsuccess && rm -f testsuccess &&
141 test_path_is_missing testfailure