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.'
13 test_expect_success 'setup' '
15 echo tree1path0 >path0 &&
16 echo tree1path1 >path1 &&
17 echo tree1path3 >path3 &&
18 echo tree1path4 >path4 &&
19 echo tree1asubdir/path5 >asubdir/path5 &&
20 git update-index --add path0 path1 path3 path4 asubdir/path5 &&
21 t1=$(git write-tree) &&
22 rm -f path* .merge_* actual .git/index &&
23 echo tree2path0 >path0 &&
24 echo tree2path1 >path1 &&
25 echo tree2path2 >path2 &&
26 echo tree2path4 >path4 &&
27 git update-index --add path0 path1 path2 path4 &&
28 t2=$(git write-tree) &&
29 rm -f path* .merge_* actual .git/index &&
30 echo tree2path0 >path0 &&
31 echo tree3path1 >path1 &&
32 echo tree3path2 >path2 &&
33 echo tree3path3 >path3 &&
34 git update-index --add path0 path1 path2 path3 &&
38 test_expect_success 'checkout one stage 0 to temporary file' '
39 rm -f path* .merge_* actual .git/index &&
41 git checkout-index --temp -- path1 >actual &&
42 test_line_count = 1 actual &&
43 test $(cut "-d " -f2 actual) = path1 &&
44 p=$(cut "-d " -f1 actual) &&
46 test $(cat $p) = tree1path1
49 test_expect_success 'checkout all stage 0 to temporary files' '
50 rm -f path* .merge_* actual .git/index &&
52 git checkout-index -a --temp >actual &&
53 test_line_count = 5 actual &&
54 for f in path0 path1 path3 path4 asubdir/path5
56 test $(grep $f actual | cut "-d " -f2) = $f &&
57 p=$(grep $f actual | cut "-d " -f1) &&
59 test $(cat $p) = tree1$f
63 test_expect_success 'setup 3-way merge' '
64 rm -f path* .merge_* actual .git/index &&
65 git read-tree -m $t1 $t2 $t3
68 test_expect_success 'checkout one stage 2 to temporary file' '
69 rm -f path* .merge_* actual &&
70 git checkout-index --stage=2 --temp -- path1 >actual &&
71 test_line_count = 1 actual &&
72 test $(cut "-d " -f2 actual) = path1 &&
73 p=$(cut "-d " -f1 actual) &&
75 test $(cat $p) = tree2path1
78 test_expect_success 'checkout all stage 2 to temporary files' '
79 rm -f path* .merge_* actual &&
80 git checkout-index --all --stage=2 --temp >actual &&
81 test_line_count = 3 actual &&
82 for f in path1 path2 path4
84 test $(grep $f actual | cut "-d " -f2) = $f &&
85 p=$(grep $f actual | cut "-d " -f1) &&
87 test $(cat $p) = tree2$f
91 test_expect_success 'checkout all stages/one file to nothing' '
92 rm -f path* .merge_* actual &&
93 git checkout-index --stage=all --temp -- path0 >actual &&
94 test_line_count = 0 actual
97 test_expect_success 'checkout all stages/one file to temporary files' '
98 rm -f path* .merge_* actual &&
99 git checkout-index --stage=all --temp -- path1 >actual &&
100 test_line_count = 1 actual &&
101 test $(cut "-d " -f2 actual) = path1 &&
102 cut "-d " -f1 actual | (read s1 s2 s3 &&
106 test $(cat $s1) = tree1path1 &&
107 test $(cat $s2) = tree2path1 &&
108 test $(cat $s3) = tree3path1)
111 test_expect_success 'checkout some stages/one file to temporary files' '
112 rm -f path* .merge_* actual &&
113 git checkout-index --stage=all --temp -- path2 >actual &&
114 test_line_count = 1 actual &&
115 test $(cut "-d " -f2 actual) = path2 &&
116 cut "-d " -f1 actual | (read s1 s2 s3 &&
120 test $(cat $s2) = tree2path2 &&
121 test $(cat $s3) = tree3path2)
124 test_expect_success 'checkout all stages/all files to temporary files' '
125 rm -f path* .merge_* actual &&
126 git checkout-index -a --stage=all --temp >actual &&
127 test_line_count = 5 actual
130 test_expect_success '-- path0: no entry' '
131 test x$(grep path0 actual | cut "-d " -f2) = x
134 test_expect_success '-- path1: all 3 stages' '
135 test $(grep path1 actual | cut "-d " -f2) = path1 &&
136 grep path1 actual | cut "-d " -f1 | (read s1 s2 s3 &&
140 test $(cat $s1) = tree1path1 &&
141 test $(cat $s2) = tree2path1 &&
142 test $(cat $s3) = tree3path1)
145 test_expect_success '-- path2: no stage 1, have stage 2 and 3' '
146 test $(grep path2 actual | cut "-d " -f2) = path2 &&
147 grep path2 actual | cut "-d " -f1 | (read s1 s2 s3 &&
151 test $(cat $s2) = tree2path2 &&
152 test $(cat $s3) = tree3path2)
155 test_expect_success '-- path3: no stage 2, have stage 1 and 3' '
156 test $(grep path3 actual | cut "-d " -f2) = path3 &&
157 grep path3 actual | cut "-d " -f1 | (read s1 s2 s3 &&
161 test $(cat $s1) = tree1path3 &&
162 test $(cat $s3) = tree3path3)
165 test_expect_success '-- path4: no stage 3, have stage 1 and 3' '
166 test $(grep path4 actual | cut "-d " -f2) = path4 &&
167 grep path4 actual | cut "-d " -f1 | (read s1 s2 s3 &&
171 test $(cat $s1) = tree1path4 &&
172 test $(cat $s2) = tree2path4)
175 test_expect_success '-- asubdir/path5: no stage 2 and 3 have stage 1' '
176 test $(grep asubdir/path5 actual | cut "-d " -f2) = asubdir/path5 &&
177 grep asubdir/path5 actual | cut "-d " -f1 | (read s1 s2 s3 &&
181 test $(cat $s1) = tree1asubdir/path5)
184 test_expect_success 'checkout --temp within subdir' '
187 git checkout-index -a --stage=all >actual &&
188 test_line_count = 1 actual &&
189 test $(grep path5 actual | cut "-d " -f2) = path5 &&
190 grep path5 actual | cut "-d " -f1 | (read s1 s2 s3 &&
194 test $(cat ../$s1) = tree1asubdir/path5)
198 test_expect_success 'checkout --temp symlink' '
199 rm -f path* .merge_* actual .git/index &&
200 test_ln_s_add path7 path6 &&
201 git checkout-index --temp -a >actual &&
202 test_line_count = 1 actual &&
203 test $(cut "-d " -f2 actual) = path6 &&
204 p=$(cut "-d " -f1 actual) &&
206 test $(cat $p) = path7
209 test_expect_success 'emit well-formed relative path' '
210 rm -f path* .merge_* actual .git/index &&
212 git update-index --add path0123456789 &&
215 git checkout-index --temp -- ../path0123456789 >actual &&
216 test_line_count = 1 actual &&
217 test $(cut "-d " -f2 actual) = ../path0123456789