t2004-checkout-cache-temp.sh 5.52 KB
Newer Older
1 2 3 4 5
#!/bin/sh
#
# Copyright (c) 2006 Shawn Pearce
#

6
test_description='git checkout-index --temp test.
7

8
With --temp flag, git checkout-index writes to temporary merge files
9 10 11 12 13 14 15 16 17 18 19 20
rather than the tracked path.'

. ./test-lib.sh

test_expect_success \
'preparation' '
mkdir asubdir &&
echo tree1path0 >path0 &&
echo tree1path1 >path1 &&
echo tree1path3 >path3 &&
echo tree1path4 >path4 &&
echo tree1asubdir/path5 >asubdir/path5 &&
21 22
git update-index --add path0 path1 path3 path4 asubdir/path5 &&
t1=$(git write-tree) &&
23 24 25 26 27
rm -f path* .merge_* out .git/index &&
echo tree2path0 >path0 &&
echo tree2path1 >path1 &&
echo tree2path2 >path2 &&
echo tree2path4 >path4 &&
28 29
git update-index --add path0 path1 path2 path4 &&
t2=$(git write-tree) &&
30 31 32 33 34
rm -f path* .merge_* out .git/index &&
echo tree2path0 >path0 &&
echo tree3path1 >path1 &&
echo tree3path2 >path2 &&
echo tree3path3 >path3 &&
35 36
git update-index --add path0 path1 path2 path3 &&
t3=$(git write-tree)'
37 38 39 40

test_expect_success \
'checkout one stage 0 to temporary file' '
rm -f path* .merge_* out .git/index &&
41 42
git read-tree $t1 &&
git checkout-index --temp -- path1 >out &&
43
test_line_count = 1 out &&
44 45 46 47 48 49 50 51
test $(cut "-d	" -f2 out) = path1 &&
p=$(cut "-d	" -f1 out) &&
test -f $p &&
test $(cat $p) = tree1path1'

test_expect_success \
'checkout all stage 0 to temporary files' '
rm -f path* .merge_* out .git/index &&
52 53
git read-tree $t1 &&
git checkout-index -a --temp >out &&
54
test_line_count = 5 out &&
55 56 57 58 59 60 61 62 63 64 65
for f in path0 path1 path3 path4 asubdir/path5
do
	test $(grep $f out | cut "-d	" -f2) = $f &&
	p=$(grep $f out | cut "-d	" -f1) &&
	test -f $p &&
	test $(cat $p) = tree1$f
done'

test_expect_success \
'prepare 3-way merge' '
rm -f path* .merge_* out .git/index &&
66
git read-tree -m $t1 $t2 $t3'
67 68 69 70

test_expect_success \
'checkout one stage 2 to temporary file' '
rm -f path* .merge_* out &&
71
git checkout-index --stage=2 --temp -- path1 >out &&
72
test_line_count = 1 out &&
73 74 75 76 77 78 79 80
test $(cut "-d	" -f2 out) = path1 &&
p=$(cut "-d	" -f1 out) &&
test -f $p &&
test $(cat $p) = tree2path1'

test_expect_success \
'checkout all stage 2 to temporary files' '
rm -f path* .merge_* out &&
81
git checkout-index --all --stage=2 --temp >out &&
82
test_line_count = 3 out &&
83 84 85 86 87 88 89 90 91 92 93
for f in path1 path2 path4
do
	test $(grep $f out | cut "-d	" -f2) = $f &&
	p=$(grep $f out | cut "-d	" -f1) &&
	test -f $p &&
	test $(cat $p) = tree2$f
done'

test_expect_success \
'checkout all stages/one file to nothing' '
rm -f path* .merge_* out &&
94
git checkout-index --stage=all --temp -- path0 >out &&
95
test_line_count = 0 out'
96 97 98 99

test_expect_success \
'checkout all stages/one file to temporary files' '
rm -f path* .merge_* out &&
100
git checkout-index --stage=all --temp -- path1 >out &&
101
test_line_count = 1 out &&
102 103 104 105 106 107 108 109 110 111 112 113
test $(cut "-d	" -f2 out) = path1 &&
cut "-d	" -f1 out | (read s1 s2 s3 &&
test -f $s1 &&
test -f $s2 &&
test -f $s3 &&
test $(cat $s1) = tree1path1 &&
test $(cat $s2) = tree2path1 &&
test $(cat $s3) = tree3path1)'

test_expect_success \
'checkout some stages/one file to temporary files' '
rm -f path* .merge_* out &&
114
git checkout-index --stage=all --temp -- path2 >out &&
115
test_line_count = 1 out &&
116 117 118 119 120 121 122 123 124 125 126
test $(cut "-d	" -f2 out) = path2 &&
cut "-d	" -f1 out | (read s1 s2 s3 &&
test $s1 = . &&
test -f $s2 &&
test -f $s3 &&
test $(cat $s2) = tree2path2 &&
test $(cat $s3) = tree3path2)'

test_expect_success \
'checkout all stages/all files to temporary files' '
rm -f path* .merge_* out &&
127
git checkout-index -a --stage=all --temp >out &&
128
test_line_count = 5 out'
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186

test_expect_success \
'-- path0: no entry' '
test x$(grep path0 out | cut "-d	" -f2) = x'

test_expect_success \
'-- path1: all 3 stages' '
test $(grep path1 out | cut "-d	" -f2) = path1 &&
grep path1 out | cut "-d	" -f1 | (read s1 s2 s3 &&
test -f $s1 &&
test -f $s2 &&
test -f $s3 &&
test $(cat $s1) = tree1path1 &&
test $(cat $s2) = tree2path1 &&
test $(cat $s3) = tree3path1)'

test_expect_success \
'-- path2: no stage 1, have stage 2 and 3' '
test $(grep path2 out | cut "-d	" -f2) = path2 &&
grep path2 out | cut "-d	" -f1 | (read s1 s2 s3 &&
test $s1 = . &&
test -f $s2 &&
test -f $s3 &&
test $(cat $s2) = tree2path2 &&
test $(cat $s3) = tree3path2)'

test_expect_success \
'-- path3: no stage 2, have stage 1 and 3' '
test $(grep path3 out | cut "-d	" -f2) = path3 &&
grep path3 out | cut "-d	" -f1 | (read s1 s2 s3 &&
test -f $s1 &&
test $s2 = . &&
test -f $s3 &&
test $(cat $s1) = tree1path3 &&
test $(cat $s3) = tree3path3)'

test_expect_success \
'-- path4: no stage 3, have stage 1 and 3' '
test $(grep path4 out | cut "-d	" -f2) = path4 &&
grep path4 out | cut "-d	" -f1 | (read s1 s2 s3 &&
test -f $s1 &&
test -f $s2 &&
test $s3 = . &&
test $(cat $s1) = tree1path4 &&
test $(cat $s2) = tree2path4)'

test_expect_success \
'-- asubdir/path5: no stage 2 and 3 have stage 1' '
test $(grep asubdir/path5 out | cut "-d	" -f2) = asubdir/path5 &&
grep asubdir/path5 out | cut "-d	" -f1 | (read s1 s2 s3 &&
test -f $s1 &&
test $s2 = . &&
test $s3 = . &&
test $(cat $s1) = tree1asubdir/path5)'

test_expect_success \
'checkout --temp within subdir' '
(cd asubdir &&
187
 git checkout-index -a --stage=all >out &&
188
 test_line_count = 1 out &&
189 190 191 192 193 194 195 196
 test $(grep path5 out | cut "-d	" -f2) = path5 &&
 grep path5 out | cut "-d	" -f1 | (read s1 s2 s3 &&
 test -f ../$s1 &&
 test $s2 = . &&
 test $s3 = . &&
 test $(cat ../$s1) = tree1asubdir/path5)
)'

197
test_expect_success \
198 199
'checkout --temp symlink' '
rm -f path* .merge_* out .git/index &&
200
test_ln_s_add b a &&
201
t4=$(git write-tree) &&
202
rm -f .git/index &&
203 204
git read-tree $t4 &&
git checkout-index --temp -a >out &&
205
test_line_count = 1 out &&
206 207 208 209 210 211
test $(cut "-d	" -f2 out) = a &&
p=$(cut "-d	" -f1 out) &&
test -f $p &&
test $(cat $p) = b'

test_done