]> git.ipfire.org Git - thirdparty/git.git/blame - t/t2004-checkout-cache-temp.sh
The third batch
[thirdparty/git.git] / t / t2004-checkout-cache-temp.sh
CommitLineData
de84f99c
SP
1#!/bin/sh
2#
3# Copyright (c) 2006 Shawn Pearce
4#
5
5be60078 6test_description='git checkout-index --temp test.
de84f99c 7
5be60078 8With --temp flag, git checkout-index writes to temporary merge files
de84f99c
SP
9rather than the tracked path.'
10
b7bcdbdb 11TEST_PASSES_SANITIZE_LEAK=true
de84f99c
SP
12. ./test-lib.sh
13
9fb7b57f
ES
14test_expect_success 'setup' '
15 mkdir asubdir &&
16 echo tree1path0 >path0 &&
17 echo tree1path1 >path1 &&
18 echo tree1path3 >path3 &&
19 echo tree1path4 >path4 &&
20 echo tree1asubdir/path5 >asubdir/path5 &&
21 git update-index --add path0 path1 path3 path4 asubdir/path5 &&
22 t1=$(git write-tree) &&
23 rm -f path* .merge_* actual .git/index &&
24 echo tree2path0 >path0 &&
25 echo tree2path1 >path1 &&
26 echo tree2path2 >path2 &&
27 echo tree2path4 >path4 &&
28 git update-index --add path0 path1 path2 path4 &&
29 t2=$(git write-tree) &&
30 rm -f path* .merge_* actual .git/index &&
31 echo tree2path0 >path0 &&
32 echo tree3path1 >path1 &&
33 echo tree3path2 >path2 &&
34 echo tree3path3 >path3 &&
35 git update-index --add path0 path1 path2 path3 &&
36 t3=$(git write-tree)
37'
38
39test_expect_success 'checkout one stage 0 to temporary file' '
40 rm -f path* .merge_* actual .git/index &&
41 git read-tree $t1 &&
42 git checkout-index --temp -- path1 >actual &&
43 test_line_count = 1 actual &&
44 test $(cut "-d " -f2 actual) = path1 &&
45 p=$(cut "-d " -f1 actual) &&
de84f99c 46 test -f $p &&
9fb7b57f
ES
47 test $(cat $p) = tree1path1
48'
49
50test_expect_success 'checkout all stage 0 to temporary files' '
51 rm -f path* .merge_* actual .git/index &&
52 git read-tree $t1 &&
53 git checkout-index -a --temp >actual &&
54 test_line_count = 5 actual &&
55 for f in path0 path1 path3 path4 asubdir/path5
56 do
57 test $(grep $f actual | cut "-d " -f2) = $f &&
58 p=$(grep $f actual | cut "-d " -f1) &&
59 test -f $p &&
db5875aa 60 test $(cat $p) = tree1$f || return 1
9fb7b57f
ES
61 done
62'
63
64test_expect_success 'setup 3-way merge' '
65 rm -f path* .merge_* actual .git/index &&
66 git read-tree -m $t1 $t2 $t3
67'
68
69test_expect_success 'checkout one stage 2 to temporary file' '
70 rm -f path* .merge_* actual &&
71 git checkout-index --stage=2 --temp -- path1 >actual &&
72 test_line_count = 1 actual &&
73 test $(cut "-d " -f2 actual) = path1 &&
74 p=$(cut "-d " -f1 actual) &&
de84f99c 75 test -f $p &&
9fb7b57f
ES
76 test $(cat $p) = tree2path1
77'
78
79test_expect_success 'checkout all stage 2 to temporary files' '
80 rm -f path* .merge_* actual &&
81 git checkout-index --all --stage=2 --temp >actual &&
82 test_line_count = 3 actual &&
83 for f in path1 path2 path4
84 do
85 test $(grep $f actual | cut "-d " -f2) = $f &&
86 p=$(grep $f actual | cut "-d " -f1) &&
87 test -f $p &&
db5875aa 88 test $(cat $p) = tree2$f || return 1
9fb7b57f
ES
89 done
90'
91
7e410615 92test_expect_success 'checkout all stages of unknown path' '
0b809c82
JK
93 rm -f path* .merge_* actual &&
94 test_must_fail git checkout-index --stage=all --temp \
95 -- does-not-exist 2>stderr &&
6789275d 96 test_grep not.in.the.cache stderr
0b809c82
JK
97'
98
9fb7b57f
ES
99test_expect_success 'checkout all stages/one file to nothing' '
100 rm -f path* .merge_* actual &&
0b809c82
JK
101 git checkout-index --stage=all --temp -- path0 >actual 2>stderr &&
102 test_must_be_empty stderr &&
9fb7b57f
ES
103 test_line_count = 0 actual
104'
105
106test_expect_success 'checkout all stages/one file to temporary files' '
107 rm -f path* .merge_* actual &&
108 git checkout-index --stage=all --temp -- path1 >actual &&
109 test_line_count = 1 actual &&
110 test $(cut "-d " -f2 actual) = path1 &&
111 cut "-d " -f1 actual | (read s1 s2 s3 &&
112 test -f $s1 &&
113 test -f $s2 &&
114 test -f $s3 &&
115 test $(cat $s1) = tree1path1 &&
116 test $(cat $s2) = tree2path1 &&
117 test $(cat $s3) = tree3path1)
118'
119
9b403865
JK
120test_expect_success '--stage=all implies --temp' '
121 rm -f path* .merge_* actual &&
122 git checkout-index --stage=all -- path1 &&
123 test_path_is_missing path1
124'
125
126test_expect_success 'overriding --stage=all resets implied --temp' '
127 rm -f path* .merge_* actual &&
128 git checkout-index --stage=all --stage=2 -- path1 &&
129 echo tree2path1 >expect &&
130 test_cmp expect path1
131'
132
133test_expect_success '--stage=all --no-temp is rejected' '
134 rm -f path* .merge_* actual &&
135 test_must_fail git checkout-index --stage=all --no-temp -- path1 2>err &&
136 grep -v "already exists" err &&
137 grep "options .--stage=all. and .--no-temp. cannot be used together" err
138'
139
9fb7b57f
ES
140test_expect_success 'checkout some stages/one file to temporary files' '
141 rm -f path* .merge_* actual &&
142 git checkout-index --stage=all --temp -- path2 >actual &&
143 test_line_count = 1 actual &&
144 test $(cut "-d " -f2 actual) = path2 &&
145 cut "-d " -f1 actual | (read s1 s2 s3 &&
146 test $s1 = . &&
147 test -f $s2 &&
148 test -f $s3 &&
149 test $(cat $s2) = tree2path2 &&
150 test $(cat $s3) = tree3path2)
151'
152
153test_expect_success 'checkout all stages/all files to temporary files' '
154 rm -f path* .merge_* actual &&
155 git checkout-index -a --stage=all --temp >actual &&
156 test_line_count = 5 actual
157'
158
159test_expect_success '-- path0: no entry' '
160 test x$(grep path0 actual | cut "-d " -f2) = x
161'
162
163test_expect_success '-- path1: all 3 stages' '
164 test $(grep path1 actual | cut "-d " -f2) = path1 &&
165 grep path1 actual | cut "-d " -f1 | (read s1 s2 s3 &&
166 test -f $s1 &&
167 test -f $s2 &&
168 test -f $s3 &&
169 test $(cat $s1) = tree1path1 &&
170 test $(cat $s2) = tree2path1 &&
171 test $(cat $s3) = tree3path1)
172'
173
174test_expect_success '-- path2: no stage 1, have stage 2 and 3' '
175 test $(grep path2 actual | cut "-d " -f2) = path2 &&
176 grep path2 actual | cut "-d " -f1 | (read s1 s2 s3 &&
177 test $s1 = . &&
178 test -f $s2 &&
179 test -f $s3 &&
180 test $(cat $s2) = tree2path2 &&
181 test $(cat $s3) = tree3path2)
182'
183
184test_expect_success '-- path3: no stage 2, have stage 1 and 3' '
185 test $(grep path3 actual | cut "-d " -f2) = path3 &&
186 grep path3 actual | cut "-d " -f1 | (read s1 s2 s3 &&
187 test -f $s1 &&
188 test $s2 = . &&
189 test -f $s3 &&
190 test $(cat $s1) = tree1path3 &&
191 test $(cat $s3) = tree3path3)
192'
193
194test_expect_success '-- path4: no stage 3, have stage 1 and 3' '
195 test $(grep path4 actual | cut "-d " -f2) = path4 &&
196 grep path4 actual | cut "-d " -f1 | (read s1 s2 s3 &&
197 test -f $s1 &&
198 test -f $s2 &&
199 test $s3 = . &&
200 test $(cat $s1) = tree1path4 &&
201 test $(cat $s2) = tree2path4)
202'
203
204test_expect_success '-- asubdir/path5: no stage 2 and 3 have stage 1' '
205 test $(grep asubdir/path5 actual | cut "-d " -f2) = asubdir/path5 &&
206 grep asubdir/path5 actual | cut "-d " -f1 | (read s1 s2 s3 &&
207 test -f $s1 &&
208 test $s2 = . &&
209 test $s3 = . &&
210 test $(cat $s1) = tree1asubdir/path5)
211'
212
213test_expect_success 'checkout --temp within subdir' '
214 (
215 cd asubdir &&
216 git checkout-index -a --stage=all >actual &&
217 test_line_count = 1 actual &&
218 test $(grep path5 actual | cut "-d " -f2) = path5 &&
219 grep path5 actual | cut "-d " -f1 | (read s1 s2 s3 &&
220 test -f ../$s1 &&
221 test $s2 = . &&
222 test $s3 = . &&
223 test $(cat ../$s1) = tree1asubdir/path5)
224 )
225'
226
227test_expect_success 'checkout --temp symlink' '
228 rm -f path* .merge_* actual .git/index &&
66e28e93 229 test_ln_s_add path7 path6 &&
9fb7b57f
ES
230 git checkout-index --temp -a >actual &&
231 test_line_count = 1 actual &&
66e28e93 232 test $(cut "-d " -f2 actual) = path6 &&
9fb7b57f
ES
233 p=$(cut "-d " -f1 actual) &&
234 test -f $p &&
66e28e93 235 test $(cat $p) = path7
9fb7b57f 236'
de84f99c 237
74c4de58 238test_expect_success 'emit well-formed relative path' '
052b2551
ES
239 rm -f path* .merge_* actual .git/index &&
240 >path0123456789 &&
241 git update-index --add path0123456789 &&
242 (
243 cd asubdir &&
244 git checkout-index --temp -- ../path0123456789 >actual &&
245 test_line_count = 1 actual &&
246 test $(cut "-d " -f2 actual) = ../path0123456789
247 )
248'
249
de84f99c 250test_done