]>
Commit | Line | Data |
---|---|---|
74e8addf SG |
1 | #!/bin/sh |
2 | ||
3 | # This test can give false success if your machine is sufficiently | |
4 | # slow or all trials happened to happen on second boundaries. | |
5 | ||
6 | test_description='racy split index' | |
7 | ||
3e3b9321 | 8 | TEST_PASSES_SANITIZE_LEAK=true |
74e8addf SG |
9 | . ./test-lib.sh |
10 | ||
11 | test_expect_success 'setup' ' | |
12 | # Only split the index when the test explicitly says so. | |
13 | sane_unset GIT_TEST_SPLIT_INDEX && | |
14 | git config splitIndex.maxPercentChange 100 && | |
15 | ||
16 | echo "cached content" >racy-file && | |
17 | git add racy-file && | |
18 | git commit -m initial && | |
19 | ||
20 | echo something >other-file && | |
21 | # No raciness with this file. | |
22 | test-tool chmtime =-20 other-file && | |
23 | ||
24 | echo "+cached content" >expect | |
25 | ' | |
26 | ||
27 | check_cached_diff () { | |
28 | git diff-index --patch --cached $EMPTY_TREE racy-file >diff && | |
29 | tail -1 diff >actual && | |
30 | test_cmp expect actual | |
31 | } | |
32 | ||
33 | trials="0 1 2 3 4" | |
34 | for trial in $trials | |
35 | do | |
36 | test_expect_success "split the index while adding a racily clean file #$trial" ' | |
37 | rm -f .git/index .git/sharedindex.* && | |
38 | ||
39 | # The next three commands must be run within the same | |
40 | # second (so both writes to racy-file result in the same | |
41 | # mtime) to create the interesting racy situation. | |
42 | echo "cached content" >racy-file && | |
43 | ||
44 | # Update and split the index. The cache entry of | |
45 | # racy-file will be stored only in the shared index. | |
46 | git update-index --split-index --add racy-file && | |
47 | ||
48 | # File size must stay the same. | |
49 | echo "dirty worktree" >racy-file && | |
50 | ||
51 | # Subsequent git commands should notice that racy-file | |
52 | # and the split index have the same mtime, and check | |
53 | # the content of the file to see if it is actually | |
54 | # clean. | |
55 | check_cached_diff | |
56 | ' | |
57 | done | |
58 | ||
59 | for trial in $trials | |
60 | do | |
61 | test_expect_success "add a racily clean file to an already split index #$trial" ' | |
62 | rm -f .git/index .git/sharedindex.* && | |
63 | ||
64 | git update-index --split-index && | |
65 | ||
66 | # The next three commands must be run within the same | |
67 | # second. | |
68 | echo "cached content" >racy-file && | |
69 | ||
70 | # Update the split index. The cache entry of racy-file | |
71 | # will be stored only in the split index. | |
72 | git update-index --add racy-file && | |
73 | ||
74 | # File size must stay the same. | |
75 | echo "dirty worktree" >racy-file && | |
76 | ||
77 | # Subsequent git commands should notice that racy-file | |
78 | # and the split index have the same mtime, and check | |
79 | # the content of the file to see if it is actually | |
80 | # clean. | |
81 | check_cached_diff | |
82 | ' | |
83 | done | |
84 | ||
85 | for trial in $trials | |
86 | do | |
87 | test_expect_success "split the index when the index contains a racily clean cache entry #$trial" ' | |
88 | rm -f .git/index .git/sharedindex.* && | |
89 | ||
90 | # The next three commands must be run within the same | |
91 | # second. | |
92 | echo "cached content" >racy-file && | |
93 | ||
94 | git update-index --add racy-file && | |
95 | ||
96 | # File size must stay the same. | |
97 | echo "dirty worktree" >racy-file && | |
98 | ||
99 | # Now wait a bit to ensure that the split index written | |
100 | # below will get a more recent mtime than racy-file. | |
101 | sleep 1 && | |
102 | ||
103 | # Update and split the index when the index contains | |
104 | # the racily clean cache entry of racy-file. | |
105 | # A corresponding replacement cache entry with smudged | |
106 | # stat data should be added to the new split index. | |
107 | git update-index --split-index --add other-file && | |
108 | ||
109 | # Subsequent git commands should notice the smudged | |
110 | # stat data in the replacement cache entry and that it | |
111 | # doesnt match with the file the worktree. | |
112 | check_cached_diff | |
113 | ' | |
114 | done | |
115 | ||
116 | for trial in $trials | |
117 | do | |
118 | test_expect_success "update the split index when it contains a new racily clean cache entry #$trial" ' | |
119 | rm -f .git/index .git/sharedindex.* && | |
120 | ||
121 | git update-index --split-index && | |
122 | ||
123 | # The next three commands must be run within the same | |
124 | # second. | |
125 | echo "cached content" >racy-file && | |
126 | ||
127 | # Update the split index. The cache entry of racy-file | |
128 | # will be stored only in the split index. | |
129 | git update-index --add racy-file && | |
130 | ||
131 | # File size must stay the same. | |
132 | echo "dirty worktree" >racy-file && | |
133 | ||
134 | # Now wait a bit to ensure that the split index written | |
135 | # below will get a more recent mtime than racy-file. | |
136 | sleep 1 && | |
137 | ||
138 | # Update the split index when the racily clean cache | |
139 | # entry of racy-file is only stored in the split index. | |
140 | # An updated cache entry with smudged stat data should | |
141 | # be added to the new split index. | |
142 | git update-index --add other-file && | |
143 | ||
144 | # Subsequent git commands should notice the smudged | |
145 | # stat data. | |
146 | check_cached_diff | |
147 | ' | |
148 | done | |
149 | ||
150 | for trial in $trials | |
151 | do | |
5581a019 | 152 | test_expect_success "update the split index when a racily clean cache entry is stored only in the shared index #$trial" ' |
74e8addf SG |
153 | rm -f .git/index .git/sharedindex.* && |
154 | ||
155 | # The next three commands must be run within the same | |
156 | # second. | |
157 | echo "cached content" >racy-file && | |
158 | ||
159 | # Update and split the index. The cache entry of | |
160 | # racy-file will be stored only in the shared index. | |
161 | git update-index --split-index --add racy-file && | |
162 | ||
163 | # File size must stay the same. | |
164 | echo "dirty worktree" >racy-file && | |
165 | ||
166 | # Now wait a bit to ensure that the split index written | |
167 | # below will get a more recent mtime than racy-file. | |
168 | sleep 1 && | |
169 | ||
170 | # Update the split index when the racily clean cache | |
171 | # entry of racy-file is only stored in the shared index. | |
172 | # A corresponding replacement cache entry with smudged | |
173 | # stat data should be added to the new split index. | |
74e8addf SG |
174 | git update-index --add other-file && |
175 | ||
176 | # Subsequent git commands should notice the smudged | |
177 | # stat data. | |
178 | check_cached_diff | |
179 | ' | |
180 | done | |
181 | ||
182 | for trial in $trials | |
183 | do | |
5581a019 | 184 | test_expect_success "update the split index after unpack trees() copied a racily clean cache entry from the shared index #$trial" ' |
74e8addf SG |
185 | rm -f .git/index .git/sharedindex.* && |
186 | ||
187 | # The next three commands must be run within the same | |
188 | # second. | |
189 | echo "cached content" >racy-file && | |
190 | ||
191 | # Update and split the index. The cache entry of | |
192 | # racy-file will be stored only in the shared index. | |
193 | git update-index --split-index --add racy-file && | |
194 | ||
195 | # File size must stay the same. | |
196 | echo "dirty worktree" >racy-file && | |
197 | ||
198 | # Now wait a bit to ensure that the split index written | |
199 | # below will get a more recent mtime than racy-file. | |
200 | sleep 1 && | |
201 | ||
202 | # Update the split index after unpack_trees() copied the | |
203 | # racily clean cache entry of racy-file from the shared | |
204 | # index. A corresponding replacement cache entry | |
205 | # with smudged stat data should be added to the new | |
206 | # split index. | |
74e8addf SG |
207 | git read-tree -m HEAD && |
208 | ||
209 | # Subsequent git commands should notice the smudged | |
210 | # stat data. | |
211 | check_cached_diff | |
212 | ' | |
213 | done | |
214 | ||
215 | test_done |