1#!/bin/sh
2
3test_description='split index mode tests'
4
5. ./test-lib.sh
6
7# We need total control of index splitting here
8sane_unset GIT_TEST_SPLIT_INDEX
9
10test_expect_success 'enable split index' '
11 git update-index --split-index &&
12 test-dump-split-index .git/index >actual &&
13 cat >expect <<EOF &&
14own 8299b0bcd1ac364e5f1d7768efb62fa2da79a339
15base 39d890139ee5356c7ef572216cebcd27aa41f9df
16replacements:
17deletions:
18EOF
19 test_cmp expect actual
20'
21
22test_expect_success 'add one file' '
23 : >one &&
24 git update-index --add one &&
25 git ls-files --stage >ls-files.actual &&
26 cat >ls-files.expect <<EOF &&
27100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 one
28EOF
29 test_cmp ls-files.expect ls-files.actual &&
30
31 test-dump-split-index .git/index | sed "/^own/d" >actual &&
32 cat >expect <<EOF &&
33base 39d890139ee5356c7ef572216cebcd27aa41f9df
34100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 one
35replacements:
36deletions:
37EOF
38 test_cmp expect actual
39'
40
41test_expect_success 'disable split index' '
42 git update-index --no-split-index &&
43 git ls-files --stage >ls-files.actual &&
44 cat >ls-files.expect <<EOF &&
45100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 one
46EOF
47 test_cmp ls-files.expect ls-files.actual &&
48
49 BASE=`test-dump-split-index .git/index | grep "^own" | sed "s/own/base/"` &&
50 test-dump-split-index .git/index | sed "/^own/d" >actual &&
51 cat >expect <<EOF &&
52not a split index
53EOF
54 test_cmp expect actual
55'
56
57test_expect_success 'enable split index again, "one" now belongs to base index"' '
58 git update-index --split-index &&
59 git ls-files --stage >ls-files.actual &&
60 cat >ls-files.expect <<EOF &&
61100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 one
62EOF
63 test_cmp ls-files.expect ls-files.actual &&
64
65 test-dump-split-index .git/index | sed "/^own/d" >actual &&
66 cat >expect <<EOF &&
67$BASE
68replacements:
69deletions:
70EOF
71 test_cmp expect actual
72'
73
74test_expect_success 'modify original file, base index untouched' '
75 echo modified >one &&
76 git update-index one &&
77 git ls-files --stage >ls-files.actual &&
78 cat >ls-files.expect <<EOF &&
79100644 2e0996000b7e9019eabcad29391bf0f5c7702f0b 0 one
80EOF
81 test_cmp ls-files.expect ls-files.actual &&
82
83 test-dump-split-index .git/index | sed "/^own/d" >actual &&
84 q_to_tab >expect <<EOF &&
85$BASE
86100644 2e0996000b7e9019eabcad29391bf0f5c7702f0b 0Q
87replacements: 0
88deletions:
89EOF
90 test_cmp expect actual
91'
92
93test_expect_success 'add another file, which stays index' '
94 : >two &&
95 git update-index --add two &&
96 git ls-files --stage >ls-files.actual &&
97 cat >ls-files.expect <<EOF &&
98100644 2e0996000b7e9019eabcad29391bf0f5c7702f0b 0 one
99100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 two
100EOF
101 test_cmp ls-files.expect ls-files.actual &&
102
103 test-dump-split-index .git/index | sed "/^own/d" >actual &&
104 q_to_tab >expect <<EOF &&
105$BASE
106100644 2e0996000b7e9019eabcad29391bf0f5c7702f0b 0Q
107100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 two
108replacements: 0
109deletions:
110EOF
111 test_cmp expect actual
112'
113
114test_expect_success 'remove file not in base index' '
115 git update-index --force-remove two &&
116 git ls-files --stage >ls-files.actual &&
117 cat >ls-files.expect <<EOF &&
118100644 2e0996000b7e9019eabcad29391bf0f5c7702f0b 0 one
119EOF
120 test_cmp ls-files.expect ls-files.actual &&
121
122 test-dump-split-index .git/index | sed "/^own/d" >actual &&
123 q_to_tab >expect <<EOF &&
124$BASE
125100644 2e0996000b7e9019eabcad29391bf0f5c7702f0b 0Q
126replacements: 0
127deletions:
128EOF
129 test_cmp expect actual
130'
131
132test_expect_success 'remove file in base index' '
133 git update-index --force-remove one &&
134 git ls-files --stage >ls-files.actual &&
135 cat >ls-files.expect <<EOF &&
136EOF
137 test_cmp ls-files.expect ls-files.actual &&
138
139 test-dump-split-index .git/index | sed "/^own/d" >actual &&
140 cat >expect <<EOF &&
141$BASE
142replacements:
143deletions: 0
144EOF
145 test_cmp expect actual
146'
147
148test_expect_success 'add original file back' '
149 : >one &&
150 git update-index --add one &&
151 git ls-files --stage >ls-files.actual &&
152 cat >ls-files.expect <<EOF &&
153100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 one
154EOF
155 test_cmp ls-files.expect ls-files.actual &&
156
157 test-dump-split-index .git/index | sed "/^own/d" >actual &&
158 cat >expect <<EOF &&
159$BASE
160100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 one
161replacements:
162deletions: 0
163EOF
164 test_cmp expect actual
165'
166
167test_expect_success 'add new file' '
168 : >two &&
169 git update-index --add two &&
170 git ls-files --stage >actual &&
171 cat >expect <<EOF &&
172100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 one
173100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 two
174EOF
175 test_cmp expect actual
176'
177
178test_expect_success 'unify index, two files remain' '
179 git update-index --no-split-index &&
180 git ls-files --stage >ls-files.actual &&
181 cat >ls-files.expect <<EOF &&
182100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 one
183100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 two
184EOF
185 test_cmp ls-files.expect ls-files.actual
186
187 test-dump-split-index .git/index | sed "/^own/d" >actual &&
188 cat >expect <<EOF &&
189not a split index
190EOF
191 test_cmp expect actual
192'
193
194test_done