Merge branch 'fixes/2.45.1/2.41' into fixes/2.45.1/2.42
[alt-git.git] / t / t2108-update-index-refresh-racy.sh
blobbc5f2886faf8877fc13adecd607b41f46d69b6d1
1 #!/bin/sh
3 test_description='update-index refresh tests related to racy timestamps'
5 TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
8 reset_files () {
9 echo content >file &&
10 echo content >other &&
11 test_set_magic_mtime file &&
12 test_set_magic_mtime other
15 update_assert_changed () {
16 test_set_magic_mtime .git/index &&
17 test_might_fail git update-index "$1" &&
18 ! test_is_magic_mtime .git/index
21 test_expect_success 'setup' '
22 reset_files &&
23 # we are calling reset_files() a couple of times during tests;
24 # test-tool chmtime does not change the ctime; to not weaken
25 # or even break our tests, disable ctime-checks entirely
26 git config core.trustctime false &&
27 git add file other &&
28 git commit -m "initial import"
31 test_expect_success '--refresh has no racy timestamps to fix' '
32 reset_files &&
33 # set the index time far enough to the future;
34 # it must be at least 3 seconds for VFAT
35 test_set_magic_mtime .git/index +60 &&
36 git update-index --refresh &&
37 test_is_magic_mtime .git/index +60
40 test_expect_success '--refresh should fix racy timestamp' '
41 reset_files &&
42 update_assert_changed --refresh
45 test_expect_success '--really-refresh should fix racy timestamp' '
46 reset_files &&
47 update_assert_changed --really-refresh
50 test_expect_success '--refresh should fix racy timestamp if other file needs update' '
51 reset_files &&
52 echo content2 >other &&
53 test_set_magic_mtime other &&
54 update_assert_changed --refresh
57 test_expect_success '--refresh should fix racy timestamp if racy file needs update' '
58 reset_files &&
59 echo content2 >file &&
60 test_set_magic_mtime file &&
61 update_assert_changed --refresh
64 test_done