3 # This test can give false success if your machine is sufficiently
4 # slow or all trials happened to happen on second boundaries.
6 test_description='racy split index'
10 test_expect_success 'setup' '
11 # Only split the index when the test explicitly says so.
12 sane_unset GIT_TEST_SPLIT_INDEX &&
13 git config splitIndex.maxPercentChange 100 &&
15 echo "cached content" >racy-file &&
17 git commit -m initial &&
19 echo something >other-file &&
20 # No raciness with this file.
21 test-tool chmtime =-20 other-file &&
23 echo "+cached content" >expect
26 check_cached_diff () {
27 git diff-index --patch --cached $EMPTY_TREE racy-file >diff &&
28 tail -1 diff >actual &&
29 test_cmp expect actual
35 test_expect_success "split the index while adding a racily clean file #$trial" '
36 rm -f .git/index .git/sharedindex.* &&
38 # The next three commands must be run within the same
39 # second (so both writes to racy-file result in the same
40 # mtime) to create the interesting racy situation.
41 echo "cached content" >racy-file &&
43 # Update and split the index. The cache entry of
44 # racy-file will be stored only in the shared index.
45 git update-index --split-index --add racy-file &&
47 # File size must stay the same.
48 echo "dirty worktree" >racy-file &&
50 # Subsequent git commands should notice that racy-file
51 # and the split index have the same mtime, and check
52 # the content of the file to see if it is actually
60 test_expect_success "add a racily clean file to an already split index #$trial" '
61 rm -f .git/index .git/sharedindex.* &&
63 git update-index --split-index &&
65 # The next three commands must be run within the same
67 echo "cached content" >racy-file &&
69 # Update the split index. The cache entry of racy-file
70 # will be stored only in the split index.
71 git update-index --add racy-file &&
73 # File size must stay the same.
74 echo "dirty worktree" >racy-file &&
76 # Subsequent git commands should notice that racy-file
77 # and the split index have the same mtime, and check
78 # the content of the file to see if it is actually
86 test_expect_success "split the index when the index contains a racily clean cache entry #$trial" '
87 rm -f .git/index .git/sharedindex.* &&
89 # The next three commands must be run within the same
91 echo "cached content" >racy-file &&
93 git update-index --add racy-file &&
95 # File size must stay the same.
96 echo "dirty worktree" >racy-file &&
98 # Now wait a bit to ensure that the split index written
99 # below will get a more recent mtime than racy-file.
102 # Update and split the index when the index contains
103 # the racily clean cache entry of racy-file.
104 # A corresponding replacement cache entry with smudged
105 # stat data should be added to the new split index.
106 git update-index --split-index --add other-file &&
108 # Subsequent git commands should notice the smudged
109 # stat data in the replacement cache entry and that it
110 # doesnt match with the file the worktree.
117 test_expect_success "update the split index when it contains a new racily clean cache entry #$trial" '
118 rm -f .git/index .git/sharedindex.* &&
120 git update-index --split-index &&
122 # The next three commands must be run within the same
124 echo "cached content" >racy-file &&
126 # Update the split index. The cache entry of racy-file
127 # will be stored only in the split index.
128 git update-index --add racy-file &&
130 # File size must stay the same.
131 echo "dirty worktree" >racy-file &&
133 # Now wait a bit to ensure that the split index written
134 # below will get a more recent mtime than racy-file.
137 # Update the split index when the racily clean cache
138 # entry of racy-file is only stored in the split index.
139 # An updated cache entry with smudged stat data should
140 # be added to the new split index.
141 git update-index --add other-file &&
143 # Subsequent git commands should notice the smudged
151 test_expect_failure "update the split index when a racily clean cache entry is stored only in the shared index $trial" '
152 rm -f .git/index .git/sharedindex.* &&
154 # The next three commands must be run within the same
156 echo "cached content" >racy-file &&
158 # Update and split the index. The cache entry of
159 # racy-file will be stored only in the shared index.
160 git update-index --split-index --add racy-file &&
162 # File size must stay the same.
163 echo "dirty worktree" >racy-file &&
165 # Now wait a bit to ensure that the split index written
166 # below will get a more recent mtime than racy-file.
169 # Update the split index when the racily clean cache
170 # entry of racy-file is only stored in the shared index.
171 # A corresponding replacement cache entry with smudged
172 # stat data should be added to the new split index.
174 # Alas, such a smudged replacement entry is not added!
175 git update-index --add other-file &&
177 # Subsequent git commands should notice the smudged
185 test_expect_failure "update the split index after unpack trees() copied a racily clean cache entry from the shared index $trial" '
186 rm -f .git/index .git/sharedindex.* &&
188 # The next three commands must be run within the same
190 echo "cached content" >racy-file &&
192 # Update and split the index. The cache entry of
193 # racy-file will be stored only in the shared index.
194 git update-index --split-index --add racy-file &&
196 # File size must stay the same.
197 echo "dirty worktree" >racy-file &&
199 # Now wait a bit to ensure that the split index written
200 # below will get a more recent mtime than racy-file.
203 # Update the split index after unpack_trees() copied the
204 # racily clean cache entry of racy-file from the shared
205 # index. A corresponding replacement cache entry
206 # with smudged stat data should be added to the new
209 # Alas, such a smudged replacement entry is not added!
210 git read-tree -m HEAD &&
212 # Subsequent git commands should notice the smudged