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.'
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 &&
39 'checkout one stage 0 to temporary file' '
40 rm -f path* .merge_* out .git/index &&
42 git checkout-index --temp -- path1 >out &&
43 test_line_count = 1 out &&
44 test $(cut "-d " -f2 out) = path1 &&
45 p=$(cut "-d " -f1 out) &&
47 test $(cat $p) = tree1path1'
50 'checkout all stage 0 to temporary files' '
51 rm -f path* .merge_* out .git/index &&
53 git checkout-index -a --temp >out &&
54 test_line_count = 5 out &&
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) &&
60 test $(cat $p) = tree1$f
64 'prepare 3-way merge' '
65 rm -f path* .merge_* out .git/index &&
66 git read-tree -m $t1 $t2 $t3'
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_line_count = 1 out &&
73 test $(cut "-d " -f2 out) = path1 &&
74 p=$(cut "-d " -f1 out) &&
76 test $(cat $p) = tree2path1'
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_line_count = 3 out &&
83 for f in path1 path2 path4
85 test $(grep $f out | cut "-d " -f2) = $f &&
86 p=$(grep $f out | cut "-d " -f1) &&
88 test $(cat $p) = tree2$f
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_line_count = 0 out'
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_line_count = 1 out &&
102 test $(cut "-d " -f2 out) = path1 &&
103 cut "-d " -f1 out | (read s1 s2 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_line_count = 1 out &&
116 test $(cut "-d " -f2 out) = path2 &&
117 cut "-d " -f1 out | (read s1 s2 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_line_count = 5 out'
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 &&
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 &&
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 &&
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 &&
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 &&
182 test $(cat $s1) = tree1asubdir/path5)'
184 test_expect_success \
185 'checkout --temp within subdir' '
187 git checkout-index -a --stage=all >out &&
188 test_line_count = 1 out &&
189 test $(grep path5 out | cut "-d " -f2) = path5 &&
190 grep path5 out | cut "-d " -f1 | (read s1 s2 s3 &&
194 test $(cat ../$s1) = tree1asubdir/path5)
197 test_expect_success \
198 'checkout --temp symlink' '
199 rm -f path* .merge_* out .git/index &&
201 t4=$(git write-tree) &&
204 git checkout-index --temp -a >out &&
205 test_line_count = 1 out &&
206 test $(cut "-d " -f2 out) = a &&
207 p=$(cut "-d " -f1 out) &&