Raw
1 #!/bin/sh
2
3 test_description='update-index refresh tests related to racy timestamps'
4
5 . ./test-lib.sh
6
7 reset_files () {
8 echo content >file &&
9 echo content >other &&
10 test_set_magic_mtime file &&
11 test_set_magic_mtime other
12 }
13
14 update_assert_changed () {
15 test_set_magic_mtime .git/index &&
16 test_might_fail git update-index "$1" &&
17 ! test_is_magic_mtime .git/index
18 }
19
20 test_expect_success 'setup' '
21 reset_files &&
22 # we are calling reset_files() a couple of times during tests;
23 # test-tool chmtime does not change the ctime; to not weaken
24 # or even break our tests, disable ctime-checks entirely
25 git config core.trustctime false &&
26 git add file other &&
27 git commit -m "initial import"
28 '
29
30 test_expect_success '--refresh has no racy timestamps to fix' '
31 reset_files &&
32 # set the index time far enough to the future;
33 # it must be at least 3 seconds for VFAT
34 test_set_magic_mtime .git/index +60 &&
35 git update-index --refresh &&
36 test_is_magic_mtime .git/index +60
37 '
38
39 test_expect_success '--refresh should fix racy timestamp' '
40 reset_files &&
41 update_assert_changed --refresh
42 '
43
44 test_expect_success '--really-refresh should fix racy timestamp' '
45 reset_files &&
46 update_assert_changed --really-refresh
47 '
48
49 test_expect_success '--refresh should fix racy timestamp if other file needs update' '
50 reset_files &&
51 echo content2 >other &&
52 test_set_magic_mtime other &&
53 update_assert_changed --refresh
54 '
55
56 test_expect_success '--refresh should fix racy timestamp if racy file needs update' '
57 reset_files &&
58 echo content2 >file &&
59 test_set_magic_mtime file &&
60 update_assert_changed --refresh
61 '
62
63 test_done