git-archive: convert archive entries like checkouts do
[git/repo.git] / t / t2004-checkout-cache-temp.sh
blobc100959cad3f017ec282c10bbc31bdc4982d5fbc
1 #!/bin/sh
3 # Copyright (c) 2006 Shawn Pearce
6 test_description='git-checkout-index --temp test.
8 With --temp flag, git-checkout-index writes to temporary merge files
9 rather than the tracked path.'
11 . ./test-lib.sh
13 test_expect_success \
14 'preparation' '
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_* out .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_* out .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)'
38 test_expect_success \
39 'checkout one stage 0 to temporary file' '
40 rm -f path* .merge_* out .git/index &&
41 git-read-tree $t1 &&
42 git-checkout-index --temp -- path1 >out &&
43 test $(wc -l <out) = 1 &&
44 test $(cut "-d " -f2 out) = path1 &&
45 p=$(cut "-d " -f1 out) &&
46 test -f $p &&
47 test $(cat $p) = tree1path1'
49 test_expect_success \
50 'checkout all stage 0 to temporary files' '
51 rm -f path* .merge_* out .git/index &&
52 git-read-tree $t1 &&
53 git-checkout-index -a --temp >out &&
54 test $(wc -l <out) = 5 &&
55 for f in path0 path1 path3 path4 asubdir/path5
57 test $(grep $f out | cut "-d " -f2) = $f &&
58 p=$(grep $f out | cut "-d " -f1) &&
59 test -f $p &&
60 test $(cat $p) = tree1$f
61 done'
63 test_expect_success \
64 'prepare 3-way merge' '
65 rm -f path* .merge_* out .git/index &&
66 git-read-tree -m $t1 $t2 $t3'
68 test_expect_success \
69 'checkout one stage 2 to temporary file' '
70 rm -f path* .merge_* out &&
71 git-checkout-index --stage=2 --temp -- path1 >out &&
72 test $(wc -l <out) = 1 &&
73 test $(cut "-d " -f2 out) = path1 &&
74 p=$(cut "-d " -f1 out) &&
75 test -f $p &&
76 test $(cat $p) = tree2path1'
78 test_expect_success \
79 'checkout all stage 2 to temporary files' '
80 rm -f path* .merge_* out &&
81 git-checkout-index --all --stage=2 --temp >out &&
82 test $(wc -l <out) = 3 &&
83 for f in path1 path2 path4
85 test $(grep $f out | cut "-d " -f2) = $f &&
86 p=$(grep $f out | cut "-d " -f1) &&
87 test -f $p &&
88 test $(cat $p) = tree2$f
89 done'
91 test_expect_success \
92 'checkout all stages/one file to nothing' '
93 rm -f path* .merge_* out &&
94 git-checkout-index --stage=all --temp -- path0 >out &&
95 test $(wc -l <out) = 0'
97 test_expect_success \
98 'checkout all stages/one file to temporary files' '
99 rm -f path* .merge_* out &&
100 git-checkout-index --stage=all --temp -- path1 >out &&
101 test $(wc -l <out) = 1 &&
102 test $(cut "-d " -f2 out) = path1 &&
103 cut "-d " -f1 out | (read s1 s2 s3 &&
104 test -f $s1 &&
105 test -f $s2 &&
106 test -f $s3 &&
107 test $(cat $s1) = tree1path1 &&
108 test $(cat $s2) = tree2path1 &&
109 test $(cat $s3) = tree3path1)'
111 test_expect_success \
112 'checkout some stages/one file to temporary files' '
113 rm -f path* .merge_* out &&
114 git-checkout-index --stage=all --temp -- path2 >out &&
115 test $(wc -l <out) = 1 &&
116 test $(cut "-d " -f2 out) = path2 &&
117 cut "-d " -f1 out | (read s1 s2 s3 &&
118 test $s1 = . &&
119 test -f $s2 &&
120 test -f $s3 &&
121 test $(cat $s2) = tree2path2 &&
122 test $(cat $s3) = tree3path2)'
124 test_expect_success \
125 'checkout all stages/all files to temporary files' '
126 rm -f path* .merge_* out &&
127 git-checkout-index -a --stage=all --temp >out &&
128 test $(wc -l <out) = 5'
130 test_expect_success \
131 '-- path0: no entry' '
132 test x$(grep path0 out | cut "-d " -f2) = x'
134 test_expect_success \
135 '-- path1: all 3 stages' '
136 test $(grep path1 out | cut "-d " -f2) = path1 &&
137 grep path1 out | cut "-d " -f1 | (read s1 s2 s3 &&
138 test -f $s1 &&
139 test -f $s2 &&
140 test -f $s3 &&
141 test $(cat $s1) = tree1path1 &&
142 test $(cat $s2) = tree2path1 &&
143 test $(cat $s3) = tree3path1)'
145 test_expect_success \
146 '-- path2: no stage 1, have stage 2 and 3' '
147 test $(grep path2 out | cut "-d " -f2) = path2 &&
148 grep path2 out | cut "-d " -f1 | (read s1 s2 s3 &&
149 test $s1 = . &&
150 test -f $s2 &&
151 test -f $s3 &&
152 test $(cat $s2) = tree2path2 &&
153 test $(cat $s3) = tree3path2)'
155 test_expect_success \
156 '-- path3: no stage 2, have stage 1 and 3' '
157 test $(grep path3 out | cut "-d " -f2) = path3 &&
158 grep path3 out | cut "-d " -f1 | (read s1 s2 s3 &&
159 test -f $s1 &&
160 test $s2 = . &&
161 test -f $s3 &&
162 test $(cat $s1) = tree1path3 &&
163 test $(cat $s3) = tree3path3)'
165 test_expect_success \
166 '-- path4: no stage 3, have stage 1 and 3' '
167 test $(grep path4 out | cut "-d " -f2) = path4 &&
168 grep path4 out | cut "-d " -f1 | (read s1 s2 s3 &&
169 test -f $s1 &&
170 test -f $s2 &&
171 test $s3 = . &&
172 test $(cat $s1) = tree1path4 &&
173 test $(cat $s2) = tree2path4)'
175 test_expect_success \
176 '-- asubdir/path5: no stage 2 and 3 have stage 1' '
177 test $(grep asubdir/path5 out | cut "-d " -f2) = asubdir/path5 &&
178 grep asubdir/path5 out | cut "-d " -f1 | (read s1 s2 s3 &&
179 test -f $s1 &&
180 test $s2 = . &&
181 test $s3 = . &&
182 test $(cat $s1) = tree1asubdir/path5)'
184 test_expect_success \
185 'checkout --temp within subdir' '
186 (cd asubdir &&
187 git-checkout-index -a --stage=all >out &&
188 test $(wc -l <out) = 1 &&
189 test $(grep path5 out | cut "-d " -f2) = path5 &&
190 grep path5 out | cut "-d " -f1 | (read s1 s2 s3 &&
191 test -f ../$s1 &&
192 test $s2 = . &&
193 test $s3 = . &&
194 test $(cat ../$s1) = tree1asubdir/path5)
197 test_expect_success \
198 'checkout --temp symlink' '
199 rm -f path* .merge_* out .git/index &&
200 ln -s b a &&
201 git-update-index --add a &&
202 t4=$(git-write-tree) &&
203 rm -f .git/index &&
204 git-read-tree $t4 &&
205 git-checkout-index --temp -a >out &&
206 test $(wc -l <out) = 1 &&
207 test $(cut "-d " -f2 out) = a &&
208 p=$(cut "-d " -f1 out) &&
209 test -f $p &&
210 test $(cat $p) = b'
212 test_done