Ben Peart | 5c8cdcf | 2017-09-22 12:35:46 -0400 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='git status with file system watcher' |
| 4 | |
| 5 | . ./test-lib.sh |
| 6 | |
Ben Peart | 5c8cdcf | 2017-09-22 12:35:46 -0400 | [diff] [blame] | 7 | # Note, after "git reset --hard HEAD" no extensions exist other than 'TREE' |
| 8 | # "git update-index --fsmonitor" can be used to get the extension written |
| 9 | # before testing the results. |
| 10 | |
| 11 | clean_repo () { |
| 12 | git reset --hard HEAD && |
| 13 | git clean -fd |
| 14 | } |
| 15 | |
| 16 | dirty_repo () { |
| 17 | : >untracked && |
| 18 | : >dir1/untracked && |
| 19 | : >dir2/untracked && |
| 20 | echo 1 >modified && |
| 21 | echo 2 >dir1/modified && |
| 22 | echo 3 >dir2/modified && |
| 23 | echo 4 >new && |
| 24 | echo 5 >dir1/new && |
| 25 | echo 6 >dir2/new |
| 26 | } |
| 27 | |
| 28 | write_integration_script () { |
Ævar Arnfjörð Bjarmason | 7da7f63 | 2022-03-17 11:13:06 +0100 | [diff] [blame] | 29 | test_hook --setup --clobber fsmonitor-test<<-\EOF |
Ben Peart | 5c8cdcf | 2017-09-22 12:35:46 -0400 | [diff] [blame] | 30 | if test "$#" -ne 2 |
| 31 | then |
| 32 | echo "$0: exactly 2 arguments expected" |
| 33 | exit 2 |
| 34 | fi |
Kevin Willford | 8da2c57 | 2020-01-07 19:04:29 +0000 | [diff] [blame] | 35 | if test "$1" != 2 |
Ben Peart | 5c8cdcf | 2017-09-22 12:35:46 -0400 | [diff] [blame] | 36 | then |
| 37 | echo "Unsupported core.fsmonitor hook version." >&2 |
| 38 | exit 1 |
| 39 | fi |
Kevin Willford | 8da2c57 | 2020-01-07 19:04:29 +0000 | [diff] [blame] | 40 | printf "last_update_token\0" |
Ben Peart | 5c8cdcf | 2017-09-22 12:35:46 -0400 | [diff] [blame] | 41 | printf "untracked\0" |
| 42 | printf "dir1/untracked\0" |
| 43 | printf "dir2/untracked\0" |
| 44 | printf "modified\0" |
| 45 | printf "dir1/modified\0" |
| 46 | printf "dir2/modified\0" |
| 47 | printf "new\0" |
| 48 | printf "dir1/new\0" |
| 49 | printf "dir2/new\0" |
| 50 | EOF |
| 51 | } |
| 52 | |
| 53 | test_lazy_prereq UNTRACKED_CACHE ' |
| 54 | { git update-index --test-untracked-cache; ret=$?; } && |
| 55 | test $ret -ne 1 |
| 56 | ' |
| 57 | |
Jeff Hostetler | 62a62a2 | 2022-05-26 21:46:58 +0000 | [diff] [blame] | 58 | # Test that we detect and disallow repos that are incompatible with FSMonitor. |
| 59 | test_expect_success 'incompatible bare repo' ' |
| 60 | test_when_finished "rm -rf ./bare-clone actual expect" && |
| 61 | git init --bare bare-clone && |
| 62 | |
| 63 | test_must_fail \ |
| 64 | git -C ./bare-clone -c core.fsmonitor=foo \ |
| 65 | update-index --fsmonitor 2>actual && |
| 66 | grep "bare repository .* is incompatible with fsmonitor" actual && |
| 67 | |
| 68 | test_must_fail \ |
| 69 | git -C ./bare-clone -c core.fsmonitor=true \ |
| 70 | update-index --fsmonitor 2>actual && |
| 71 | grep "bare repository .* is incompatible with fsmonitor" actual |
| 72 | ' |
| 73 | |
| 74 | test_expect_success FSMONITOR_DAEMON 'run fsmonitor-daemon in bare repo' ' |
| 75 | test_when_finished "rm -rf ./bare-clone actual" && |
| 76 | git init --bare bare-clone && |
| 77 | test_must_fail git -C ./bare-clone fsmonitor--daemon run 2>actual && |
| 78 | grep "bare repository .* is incompatible with fsmonitor" actual |
| 79 | ' |
| 80 | |
Jeff Hostetler | 5c58fbd | 2022-05-26 21:47:00 +0000 | [diff] [blame] | 81 | test_expect_success MINGW,FSMONITOR_DAEMON 'run fsmonitor-daemon in virtual repo' ' |
| 82 | test_when_finished "rm -rf ./fake-virtual-clone actual" && |
| 83 | git init fake-virtual-clone && |
| 84 | test_must_fail git -C ./fake-virtual-clone \ |
| 85 | -c core.virtualfilesystem=true \ |
| 86 | fsmonitor--daemon run 2>actual && |
| 87 | grep "virtual repository .* is incompatible with fsmonitor" actual |
| 88 | ' |
| 89 | |
Ben Peart | 5c8cdcf | 2017-09-22 12:35:46 -0400 | [diff] [blame] | 90 | test_expect_success 'setup' ' |
Ben Peart | 5c8cdcf | 2017-09-22 12:35:46 -0400 | [diff] [blame] | 91 | : >tracked && |
| 92 | : >modified && |
| 93 | mkdir dir1 && |
| 94 | : >dir1/tracked && |
| 95 | : >dir1/modified && |
| 96 | mkdir dir2 && |
| 97 | : >dir2/tracked && |
| 98 | : >dir2/modified && |
| 99 | git -c core.fsmonitor= add . && |
| 100 | git -c core.fsmonitor= commit -m initial && |
| 101 | git config core.fsmonitor .git/hooks/fsmonitor-test && |
| 102 | cat >.gitignore <<-\EOF |
| 103 | .gitignore |
| 104 | expect* |
| 105 | actual* |
| 106 | marker* |
Derrick Stolee | f8fe49e | 2021-07-14 13:12:39 +0000 | [diff] [blame] | 107 | trace2* |
Ben Peart | 5c8cdcf | 2017-09-22 12:35:46 -0400 | [diff] [blame] | 108 | EOF |
| 109 | ' |
| 110 | |
| 111 | # test that the fsmonitor extension is off by default |
| 112 | test_expect_success 'fsmonitor extension is off by default' ' |
Nguyễn Thái Ngọc Duy | f1ef0b0 | 2018-09-09 19:36:30 +0200 | [diff] [blame] | 113 | test-tool dump-fsmonitor >actual && |
Ben Peart | 5c8cdcf | 2017-09-22 12:35:46 -0400 | [diff] [blame] | 114 | grep "^no fsmonitor" actual |
| 115 | ' |
| 116 | |
| 117 | # test that "update-index --fsmonitor" adds the fsmonitor extension |
| 118 | test_expect_success 'update-index --fsmonitor" adds the fsmonitor extension' ' |
| 119 | git update-index --fsmonitor && |
Nguyễn Thái Ngọc Duy | f1ef0b0 | 2018-09-09 19:36:30 +0200 | [diff] [blame] | 120 | test-tool dump-fsmonitor >actual && |
Ben Peart | 5c8cdcf | 2017-09-22 12:35:46 -0400 | [diff] [blame] | 121 | grep "^fsmonitor last update" actual |
| 122 | ' |
| 123 | |
| 124 | # test that "update-index --no-fsmonitor" removes the fsmonitor extension |
| 125 | test_expect_success 'update-index --no-fsmonitor" removes the fsmonitor extension' ' |
| 126 | git update-index --no-fsmonitor && |
Nguyễn Thái Ngọc Duy | f1ef0b0 | 2018-09-09 19:36:30 +0200 | [diff] [blame] | 127 | test-tool dump-fsmonitor >actual && |
Ben Peart | 5c8cdcf | 2017-09-22 12:35:46 -0400 | [diff] [blame] | 128 | grep "^no fsmonitor" actual |
| 129 | ' |
| 130 | |
| 131 | cat >expect <<EOF && |
| 132 | h dir1/modified |
| 133 | H dir1/tracked |
| 134 | h dir2/modified |
| 135 | H dir2/tracked |
| 136 | h modified |
| 137 | H tracked |
| 138 | EOF |
| 139 | |
| 140 | # test that "update-index --fsmonitor-valid" sets the fsmonitor valid bit |
| 141 | test_expect_success 'update-index --fsmonitor-valid" sets the fsmonitor valid bit' ' |
Ævar Arnfjörð Bjarmason | 7da7f63 | 2022-03-17 11:13:06 +0100 | [diff] [blame] | 142 | test_hook fsmonitor-test<<-\EOF && |
Kevin Willford | 8da2c57 | 2020-01-07 19:04:29 +0000 | [diff] [blame] | 143 | printf "last_update_token\0" |
Utsav Shah | 679f2f9 | 2019-11-20 08:32:17 +0000 | [diff] [blame] | 144 | EOF |
Ben Peart | 5c8cdcf | 2017-09-22 12:35:46 -0400 | [diff] [blame] | 145 | git update-index --fsmonitor && |
| 146 | git update-index --fsmonitor-valid dir1/modified && |
| 147 | git update-index --fsmonitor-valid dir2/modified && |
| 148 | git update-index --fsmonitor-valid modified && |
| 149 | git ls-files -f >actual && |
| 150 | test_cmp expect actual |
| 151 | ' |
| 152 | |
| 153 | cat >expect <<EOF && |
| 154 | H dir1/modified |
| 155 | H dir1/tracked |
| 156 | H dir2/modified |
| 157 | H dir2/tracked |
| 158 | H modified |
| 159 | H tracked |
| 160 | EOF |
| 161 | |
| 162 | # test that "update-index --no-fsmonitor-valid" clears the fsmonitor valid bit |
| 163 | test_expect_success 'update-index --no-fsmonitor-valid" clears the fsmonitor valid bit' ' |
| 164 | git update-index --no-fsmonitor-valid dir1/modified && |
| 165 | git update-index --no-fsmonitor-valid dir2/modified && |
| 166 | git update-index --no-fsmonitor-valid modified && |
| 167 | git ls-files -f >actual && |
| 168 | test_cmp expect actual |
| 169 | ' |
| 170 | |
| 171 | cat >expect <<EOF && |
| 172 | H dir1/modified |
| 173 | H dir1/tracked |
| 174 | H dir2/modified |
| 175 | H dir2/tracked |
| 176 | H modified |
| 177 | H tracked |
| 178 | EOF |
| 179 | |
| 180 | # test that all files returned by the script get flagged as invalid |
| 181 | test_expect_success 'all files returned by integration script get flagged as invalid' ' |
| 182 | write_integration_script && |
| 183 | dirty_repo && |
| 184 | git update-index --fsmonitor && |
| 185 | git ls-files -f >actual && |
| 186 | test_cmp expect actual |
| 187 | ' |
| 188 | |
| 189 | cat >expect <<EOF && |
| 190 | H dir1/modified |
| 191 | h dir1/new |
| 192 | H dir1/tracked |
| 193 | H dir2/modified |
| 194 | h dir2/new |
| 195 | H dir2/tracked |
| 196 | H modified |
| 197 | h new |
| 198 | H tracked |
| 199 | EOF |
| 200 | |
| 201 | # test that newly added files are marked valid |
| 202 | test_expect_success 'newly added files are marked valid' ' |
Ævar Arnfjörð Bjarmason | 7da7f63 | 2022-03-17 11:13:06 +0100 | [diff] [blame] | 203 | test_hook --setup --clobber fsmonitor-test<<-\EOF && |
Kevin Willford | 8da2c57 | 2020-01-07 19:04:29 +0000 | [diff] [blame] | 204 | printf "last_update_token\0" |
Utsav Shah | 679f2f9 | 2019-11-20 08:32:17 +0000 | [diff] [blame] | 205 | EOF |
Ben Peart | 5c8cdcf | 2017-09-22 12:35:46 -0400 | [diff] [blame] | 206 | git add new && |
| 207 | git add dir1/new && |
| 208 | git add dir2/new && |
| 209 | git ls-files -f >actual && |
| 210 | test_cmp expect actual |
| 211 | ' |
| 212 | |
| 213 | cat >expect <<EOF && |
| 214 | H dir1/modified |
| 215 | h dir1/new |
| 216 | h dir1/tracked |
| 217 | H dir2/modified |
| 218 | h dir2/new |
| 219 | h dir2/tracked |
| 220 | H modified |
| 221 | h new |
| 222 | h tracked |
| 223 | EOF |
| 224 | |
| 225 | # test that all unmodified files get marked valid |
| 226 | test_expect_success 'all unmodified files get marked valid' ' |
| 227 | # modified files result in update-index returning 1 |
| 228 | test_must_fail git update-index --refresh --force-write-index && |
| 229 | git ls-files -f >actual && |
| 230 | test_cmp expect actual |
| 231 | ' |
| 232 | |
| 233 | cat >expect <<EOF && |
| 234 | H dir1/modified |
| 235 | h dir1/tracked |
| 236 | h dir2/modified |
| 237 | h dir2/tracked |
| 238 | h modified |
| 239 | h tracked |
| 240 | EOF |
| 241 | |
| 242 | # test that *only* files returned by the integration script get flagged as invalid |
| 243 | test_expect_success '*only* files returned by the integration script get flagged as invalid' ' |
Ævar Arnfjörð Bjarmason | 7da7f63 | 2022-03-17 11:13:06 +0100 | [diff] [blame] | 244 | test_hook --clobber fsmonitor-test<<-\EOF && |
Kevin Willford | 8da2c57 | 2020-01-07 19:04:29 +0000 | [diff] [blame] | 245 | printf "last_update_token\0" |
Ben Peart | 5c8cdcf | 2017-09-22 12:35:46 -0400 | [diff] [blame] | 246 | printf "dir1/modified\0" |
| 247 | EOF |
| 248 | clean_repo && |
| 249 | git update-index --refresh --force-write-index && |
| 250 | echo 1 >modified && |
| 251 | echo 2 >dir1/modified && |
| 252 | echo 3 >dir2/modified && |
| 253 | test_must_fail git update-index --refresh --force-write-index && |
| 254 | git ls-files -f >actual && |
| 255 | test_cmp expect actual |
| 256 | ' |
| 257 | |
| 258 | # Ensure commands that call refresh_index() to move the index back in time |
| 259 | # properly invalidate the fsmonitor cache |
| 260 | test_expect_success 'refresh_index() invalidates fsmonitor cache' ' |
Ben Peart | 5c8cdcf | 2017-09-22 12:35:46 -0400 | [diff] [blame] | 261 | clean_repo && |
| 262 | dirty_repo && |
Utsav Shah | 679f2f9 | 2019-11-20 08:32:17 +0000 | [diff] [blame] | 263 | write_integration_script && |
Ben Peart | 5c8cdcf | 2017-09-22 12:35:46 -0400 | [diff] [blame] | 264 | git add . && |
Ævar Arnfjörð Bjarmason | 7da7f63 | 2022-03-17 11:13:06 +0100 | [diff] [blame] | 265 | test_hook --clobber fsmonitor-test<<-\EOF && |
Utsav Shah | 679f2f9 | 2019-11-20 08:32:17 +0000 | [diff] [blame] | 266 | EOF |
Ben Peart | 5c8cdcf | 2017-09-22 12:35:46 -0400 | [diff] [blame] | 267 | git commit -m "to reset" && |
| 268 | git reset HEAD~1 && |
| 269 | git status >actual && |
| 270 | git -c core.fsmonitor= status >expect && |
Ævar Arnfjörð Bjarmason | 1108cea | 2021-02-11 02:53:53 +0100 | [diff] [blame] | 271 | test_cmp expect actual |
Ben Peart | 5c8cdcf | 2017-09-22 12:35:46 -0400 | [diff] [blame] | 272 | ' |
| 273 | |
| 274 | # test fsmonitor with and without preloadIndex |
| 275 | preload_values="false true" |
| 276 | for preload_val in $preload_values |
| 277 | do |
| 278 | test_expect_success "setup preloadIndex to $preload_val" ' |
| 279 | git config core.preloadIndex $preload_val && |
| 280 | if test $preload_val = true |
| 281 | then |
Eric Sunshine | 74d2f56 | 2021-12-09 00:11:06 -0500 | [diff] [blame] | 282 | GIT_TEST_PRELOAD_INDEX=$preload_val && export GIT_TEST_PRELOAD_INDEX |
Ben Peart | 5c8cdcf | 2017-09-22 12:35:46 -0400 | [diff] [blame] | 283 | else |
Ben Peart | 5765d97 | 2018-09-18 23:29:37 +0000 | [diff] [blame] | 284 | sane_unset GIT_TEST_PRELOAD_INDEX |
Ben Peart | 5c8cdcf | 2017-09-22 12:35:46 -0400 | [diff] [blame] | 285 | fi |
| 286 | ' |
| 287 | |
| 288 | # test fsmonitor with and without the untracked cache (if available) |
| 289 | uc_values="false" |
| 290 | test_have_prereq UNTRACKED_CACHE && uc_values="false true" |
| 291 | for uc_val in $uc_values |
| 292 | do |
| 293 | test_expect_success "setup untracked cache to $uc_val" ' |
| 294 | git config core.untrackedcache $uc_val |
| 295 | ' |
| 296 | |
| 297 | # Status is well tested elsewhere so we'll just ensure that the results are |
| 298 | # the same when using core.fsmonitor. |
| 299 | test_expect_success 'compare status with and without fsmonitor' ' |
| 300 | write_integration_script && |
| 301 | clean_repo && |
| 302 | dirty_repo && |
| 303 | git add new && |
| 304 | git add dir1/new && |
| 305 | git add dir2/new && |
| 306 | git status >actual && |
| 307 | git -c core.fsmonitor= status >expect && |
Ævar Arnfjörð Bjarmason | 1108cea | 2021-02-11 02:53:53 +0100 | [diff] [blame] | 308 | test_cmp expect actual |
Ben Peart | 5c8cdcf | 2017-09-22 12:35:46 -0400 | [diff] [blame] | 309 | ' |
| 310 | |
| 311 | # Make sure it's actually skipping the check for modified and untracked |
| 312 | # (if enabled) files unless it is told about them. |
| 313 | test_expect_success "status doesn't detect unreported modifications" ' |
Ævar Arnfjörð Bjarmason | 7da7f63 | 2022-03-17 11:13:06 +0100 | [diff] [blame] | 314 | test_hook --clobber fsmonitor-test<<-\EOF && |
Kevin Willford | 8da2c57 | 2020-01-07 19:04:29 +0000 | [diff] [blame] | 315 | printf "last_update_token\0" |
Ben Peart | 5c8cdcf | 2017-09-22 12:35:46 -0400 | [diff] [blame] | 316 | :>marker |
| 317 | EOF |
| 318 | clean_repo && |
| 319 | git status && |
| 320 | test_path_is_file marker && |
| 321 | dirty_repo && |
| 322 | rm -f marker && |
| 323 | git status >actual && |
| 324 | test_path_is_file marker && |
Junio C Hamano | 6789275 | 2023-10-31 14:23:30 +0900 | [diff] [blame] | 325 | test_grep ! "Changes not staged for commit:" actual && |
Ben Peart | 5c8cdcf | 2017-09-22 12:35:46 -0400 | [diff] [blame] | 326 | if test $uc_val = true |
| 327 | then |
Junio C Hamano | 6789275 | 2023-10-31 14:23:30 +0900 | [diff] [blame] | 328 | test_grep ! "Untracked files:" actual |
Ben Peart | 5c8cdcf | 2017-09-22 12:35:46 -0400 | [diff] [blame] | 329 | fi && |
| 330 | if test $uc_val = false |
| 331 | then |
Junio C Hamano | 6789275 | 2023-10-31 14:23:30 +0900 | [diff] [blame] | 332 | test_grep "Untracked files:" actual |
Ben Peart | 5c8cdcf | 2017-09-22 12:35:46 -0400 | [diff] [blame] | 333 | fi && |
| 334 | rm -f marker |
| 335 | ' |
| 336 | done |
| 337 | done |
| 338 | |
Elijah Newren | 7a40cf1 | 2019-11-05 17:07:24 +0000 | [diff] [blame] | 339 | # test that splitting the index doesn't interfere |
Alex Vandiver | 3bd28eb | 2017-11-09 11:58:10 -0800 | [diff] [blame] | 340 | test_expect_success 'splitting the index results in the same state' ' |
| 341 | write_integration_script && |
| 342 | dirty_repo && |
| 343 | git update-index --fsmonitor && |
| 344 | git ls-files -f >expect && |
Nguyễn Thái Ngọc Duy | f1ef0b0 | 2018-09-09 19:36:30 +0200 | [diff] [blame] | 345 | test-tool dump-fsmonitor >&2 && echo && |
Alex Vandiver | 3bd28eb | 2017-11-09 11:58:10 -0800 | [diff] [blame] | 346 | git update-index --fsmonitor --split-index && |
Nguyễn Thái Ngọc Duy | f1ef0b0 | 2018-09-09 19:36:30 +0200 | [diff] [blame] | 347 | test-tool dump-fsmonitor >&2 && echo && |
Alex Vandiver | 3bd28eb | 2017-11-09 11:58:10 -0800 | [diff] [blame] | 348 | git ls-files -f >actual && |
| 349 | test_cmp expect actual |
| 350 | ' |
| 351 | |
Nguyễn Thái Ngọc Duy | 0cacebf | 2018-02-07 16:21:40 +0700 | [diff] [blame] | 352 | test_expect_success UNTRACKED_CACHE 'ignore .git changes when invalidating UNTR' ' |
| 353 | test_create_repo dot-git && |
| 354 | ( |
| 355 | cd dot-git && |
Nguyễn Thái Ngọc Duy | 0cacebf | 2018-02-07 16:21:40 +0700 | [diff] [blame] | 356 | : >tracked && |
Tao Klerks | a67d178 | 2022-02-27 21:56:59 +0000 | [diff] [blame] | 357 | test-tool chmtime =-60 tracked && |
Nguyễn Thái Ngọc Duy | 0cacebf | 2018-02-07 16:21:40 +0700 | [diff] [blame] | 358 | : >modified && |
Tao Klerks | a67d178 | 2022-02-27 21:56:59 +0000 | [diff] [blame] | 359 | test-tool chmtime =-60 modified && |
Nguyễn Thái Ngọc Duy | 0cacebf | 2018-02-07 16:21:40 +0700 | [diff] [blame] | 360 | mkdir dir1 && |
| 361 | : >dir1/tracked && |
Tao Klerks | a67d178 | 2022-02-27 21:56:59 +0000 | [diff] [blame] | 362 | test-tool chmtime =-60 dir1/tracked && |
Nguyễn Thái Ngọc Duy | 0cacebf | 2018-02-07 16:21:40 +0700 | [diff] [blame] | 363 | : >dir1/modified && |
Tao Klerks | a67d178 | 2022-02-27 21:56:59 +0000 | [diff] [blame] | 364 | test-tool chmtime =-60 dir1/modified && |
Nguyễn Thái Ngọc Duy | 0cacebf | 2018-02-07 16:21:40 +0700 | [diff] [blame] | 365 | mkdir dir2 && |
| 366 | : >dir2/tracked && |
Tao Klerks | a67d178 | 2022-02-27 21:56:59 +0000 | [diff] [blame] | 367 | test-tool chmtime =-60 dir2/tracked && |
Nguyễn Thái Ngọc Duy | 0cacebf | 2018-02-07 16:21:40 +0700 | [diff] [blame] | 368 | : >dir2/modified && |
Tao Klerks | a67d178 | 2022-02-27 21:56:59 +0000 | [diff] [blame] | 369 | test-tool chmtime =-60 dir2/modified && |
Nguyễn Thái Ngọc Duy | 0cacebf | 2018-02-07 16:21:40 +0700 | [diff] [blame] | 370 | write_integration_script && |
| 371 | git config core.fsmonitor .git/hooks/fsmonitor-test && |
| 372 | git update-index --untracked-cache && |
| 373 | git update-index --fsmonitor && |
Tao Klerks | 37482b4 | 2022-02-27 21:57:00 +0000 | [diff] [blame] | 374 | git status && |
Elijah Newren | 7f9dd87 | 2021-05-12 17:28:14 +0000 | [diff] [blame] | 375 | GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace-before" \ |
Nguyễn Thái Ngọc Duy | 0cacebf | 2018-02-07 16:21:40 +0700 | [diff] [blame] | 376 | git status && |
Nguyễn Thái Ngọc Duy | cd780f0 | 2018-09-09 19:36:27 +0200 | [diff] [blame] | 377 | test-tool dump-untracked-cache >../before |
Nguyễn Thái Ngọc Duy | 0cacebf | 2018-02-07 16:21:40 +0700 | [diff] [blame] | 378 | ) && |
| 379 | cat >>dot-git/.git/hooks/fsmonitor-test <<-\EOF && |
| 380 | printf ".git\0" |
| 381 | printf ".git/index\0" |
| 382 | printf "dir1/.git\0" |
| 383 | printf "dir1/.git/index\0" |
| 384 | EOF |
| 385 | ( |
| 386 | cd dot-git && |
Elijah Newren | 7f9dd87 | 2021-05-12 17:28:14 +0000 | [diff] [blame] | 387 | GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace-after" \ |
Nguyễn Thái Ngọc Duy | 0cacebf | 2018-02-07 16:21:40 +0700 | [diff] [blame] | 388 | git status && |
Nguyễn Thái Ngọc Duy | cd780f0 | 2018-09-09 19:36:27 +0200 | [diff] [blame] | 389 | test-tool dump-untracked-cache >../after |
Nguyễn Thái Ngọc Duy | 0cacebf | 2018-02-07 16:21:40 +0700 | [diff] [blame] | 390 | ) && |
Elijah Newren | 7f9dd87 | 2021-05-12 17:28:14 +0000 | [diff] [blame] | 391 | grep "directory-invalidation" trace-before | cut -d"|" -f 9 >>before && |
| 392 | grep "directory-invalidation" trace-after | cut -d"|" -f 9 >>after && |
Nguyễn Thái Ngọc Duy | 0cacebf | 2018-02-07 16:21:40 +0700 | [diff] [blame] | 393 | # UNTR extension unchanged, dir invalidation count unchanged |
| 394 | test_cmp before after |
| 395 | ' |
| 396 | |
Johannes Schindelin | 398a3b0 | 2019-05-07 13:10:21 +0200 | [diff] [blame] | 397 | test_expect_success 'discard_index() also discards fsmonitor info' ' |
Johannes Schindelin | dc76852 | 2019-05-07 13:10:20 +0200 | [diff] [blame] | 398 | test_config core.fsmonitor "$TEST_DIRECTORY/t7519/fsmonitor-all" && |
| 399 | test_might_fail git update-index --refresh && |
| 400 | test-tool read-cache --print-and-refresh=tracked 2 >actual && |
| 401 | printf "tracked is%s up to date\n" "" " not" >expect && |
| 402 | test_cmp expect actual |
| 403 | ' |
| 404 | |
William Baker | 460782b | 2019-10-16 19:35:47 +0000 | [diff] [blame] | 405 | # Test unstaging entries that: |
| 406 | # - Are not flagged with CE_FSMONITOR_VALID |
| 407 | # - Have a position in the index >= the number of entries present in the index |
| 408 | # after unstaging. |
| 409 | test_expect_success 'status succeeds after staging/unstaging' ' |
William Baker | 3444ec2 | 2019-10-11 13:11:23 -0700 | [diff] [blame] | 410 | test_create_repo fsmonitor-stage-unstage && |
| 411 | ( |
| 412 | cd fsmonitor-stage-unstage && |
| 413 | test_commit initial && |
| 414 | git update-index --fsmonitor && |
| 415 | removed=$(test_seq 1 100 | sed "s/^/z/") && |
| 416 | touch $removed && |
| 417 | git add $removed && |
| 418 | git config core.fsmonitor "$TEST_DIRECTORY/t7519/fsmonitor-env" && |
| 419 | FSMONITOR_LIST="$removed" git restore -S $removed && |
| 420 | FSMONITOR_LIST="$removed" git status |
| 421 | ) |
| 422 | ' |
| 423 | |
Derrick Stolee | f8fe49e | 2021-07-14 13:12:39 +0000 | [diff] [blame] | 424 | # Usage: |
| 425 | # check_sparse_index_behavior [!] |
| 426 | # If "!" is supplied, then we verify that we do not call ensure_full_index |
| 427 | # during a call to 'git status'. Otherwise, we verify that we _do_ call it. |
| 428 | check_sparse_index_behavior () { |
Derrick Stolee | 522d3ce | 2021-09-08 01:42:25 +0000 | [diff] [blame] | 429 | git -C full status --porcelain=v2 >expect && |
Derrick Stolee | 8c4cbad | 2021-11-29 13:47:46 +0000 | [diff] [blame] | 430 | GIT_TRACE2_EVENT="$(pwd)/trace2.txt" \ |
Derrick Stolee | 522d3ce | 2021-09-08 01:42:25 +0000 | [diff] [blame] | 431 | git -C sparse status --porcelain=v2 >actual && |
Derrick Stolee | f8fe49e | 2021-07-14 13:12:39 +0000 | [diff] [blame] | 432 | test_region $1 index ensure_full_index trace2.txt && |
| 433 | test_region fsm_hook query trace2.txt && |
| 434 | test_cmp expect actual && |
Derrick Stolee | 522d3ce | 2021-09-08 01:42:25 +0000 | [diff] [blame] | 435 | rm trace2.txt |
Derrick Stolee | f8fe49e | 2021-07-14 13:12:39 +0000 | [diff] [blame] | 436 | } |
| 437 | |
| 438 | test_expect_success 'status succeeds with sparse index' ' |
SZEDER Gábor | 61feddc | 2021-08-26 23:00:03 +0200 | [diff] [blame] | 439 | ( |
| 440 | sane_unset GIT_TEST_SPLIT_INDEX && |
Derrick Stolee | f8fe49e | 2021-07-14 13:12:39 +0000 | [diff] [blame] | 441 | |
SZEDER Gábor | 61feddc | 2021-08-26 23:00:03 +0200 | [diff] [blame] | 442 | git clone . full && |
| 443 | git clone --sparse . sparse && |
| 444 | git -C sparse sparse-checkout init --cone --sparse-index && |
| 445 | git -C sparse sparse-checkout set dir1 dir2 && |
Derrick Stolee | f8fe49e | 2021-07-14 13:12:39 +0000 | [diff] [blame] | 446 | |
Ævar Arnfjörð Bjarmason | 7da7f63 | 2022-03-17 11:13:06 +0100 | [diff] [blame] | 447 | test_hook --clobber fsmonitor-test <<-\EOF && |
SZEDER Gábor | 61feddc | 2021-08-26 23:00:03 +0200 | [diff] [blame] | 448 | printf "last_update_token\0" |
| 449 | EOF |
| 450 | git -C full config core.fsmonitor ../.git/hooks/fsmonitor-test && |
| 451 | git -C sparse config core.fsmonitor ../.git/hooks/fsmonitor-test && |
| 452 | check_sparse_index_behavior ! && |
Derrick Stolee | f8fe49e | 2021-07-14 13:12:39 +0000 | [diff] [blame] | 453 | |
Ævar Arnfjörð Bjarmason | 7da7f63 | 2022-03-17 11:13:06 +0100 | [diff] [blame] | 454 | test_hook --clobber fsmonitor-test <<-\EOF && |
SZEDER Gábor | 61feddc | 2021-08-26 23:00:03 +0200 | [diff] [blame] | 455 | printf "last_update_token\0" |
| 456 | printf "dir1/modified\0" |
| 457 | EOF |
| 458 | check_sparse_index_behavior ! && |
Derrick Stolee | 522d3ce | 2021-09-08 01:42:25 +0000 | [diff] [blame] | 459 | |
SZEDER Gábor | 61feddc | 2021-08-26 23:00:03 +0200 | [diff] [blame] | 460 | git -C sparse sparse-checkout add dir1a && |
Derrick Stolee | f8fe49e | 2021-07-14 13:12:39 +0000 | [diff] [blame] | 461 | |
SZEDER Gábor | 61feddc | 2021-08-26 23:00:03 +0200 | [diff] [blame] | 462 | for repo in full sparse |
| 463 | do |
| 464 | cp -r $repo/dir1 $repo/dir1a && |
| 465 | git -C $repo add dir1a && |
| 466 | git -C $repo commit -m "add dir1a" || return 1 |
| 467 | done && |
| 468 | git -C sparse sparse-checkout set dir1 dir2 && |
| 469 | |
| 470 | # This one modifies outside the sparse-checkout definition |
| 471 | # and hence we expect to expand the sparse-index. |
Ævar Arnfjörð Bjarmason | 7da7f63 | 2022-03-17 11:13:06 +0100 | [diff] [blame] | 472 | test_hook --clobber fsmonitor-test <<-\EOF && |
SZEDER Gábor | 61feddc | 2021-08-26 23:00:03 +0200 | [diff] [blame] | 473 | printf "last_update_token\0" |
| 474 | printf "dir1a/modified\0" |
| 475 | EOF |
| 476 | check_sparse_index_behavior |
| 477 | ) |
Derrick Stolee | f8fe49e | 2021-07-14 13:12:39 +0000 | [diff] [blame] | 478 | ' |
| 479 | |
Ben Peart | 5c8cdcf | 2017-09-22 12:35:46 -0400 | [diff] [blame] | 480 | test_done |