blob: a9352b08a8b80e4a58131f31f98eb7481914ecbe [file] [log] [blame]
Shawn Pearcede84f992006-03-05 03:24:15 -05001#!/bin/sh
2#
3# Copyright (c) 2006 Shawn Pearce
4#
5
Junio C Hamano5be60072007-07-02 22:52:14 -07006test_description='git checkout-index --temp test.
Shawn Pearcede84f992006-03-05 03:24:15 -05007
Junio C Hamano5be60072007-07-02 22:52:14 -07008With --temp flag, git checkout-index writes to temporary merge files
Shawn Pearcede84f992006-03-05 03:24:15 -05009rather than the tracked path.'
10
11. ./test-lib.sh
12
Eric Sunshine9fb7b572014-12-24 04:43:12 -050013test_expect_success 'setup' '
14 mkdir asubdir &&
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 &&
35 t3=$(git write-tree)
36'
Shawn Pearcede84f992006-03-05 03:24:15 -050037
Eric Sunshine9fb7b572014-12-24 04:43:12 -050038test_expect_success 'checkout one stage 0 to temporary file' '
39 rm -f path* .merge_* actual .git/index &&
40 git read-tree $t1 &&
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) &&
Shawn Pearcede84f992006-03-05 03:24:15 -050045 test -f $p &&
Eric Sunshine9fb7b572014-12-24 04:43:12 -050046 test $(cat $p) = tree1path1
47'
Shawn Pearcede84f992006-03-05 03:24:15 -050048
Eric Sunshine9fb7b572014-12-24 04:43:12 -050049test_expect_success 'checkout all stage 0 to temporary files' '
50 rm -f path* .merge_* actual .git/index &&
51 git read-tree $t1 &&
52 git checkout-index -a --temp >actual &&
53 test_line_count = 5 actual &&
54 for f in path0 path1 path3 path4 asubdir/path5
55 do
56 test $(grep $f actual | cut "-d " -f2) = $f &&
57 p=$(grep $f actual | cut "-d " -f1) &&
58 test -f $p &&
59 test $(cat $p) = tree1$f
60 done
61'
Shawn Pearcede84f992006-03-05 03:24:15 -050062
Eric Sunshine9fb7b572014-12-24 04:43:12 -050063test_expect_success 'setup 3-way merge' '
64 rm -f path* .merge_* actual .git/index &&
65 git read-tree -m $t1 $t2 $t3
66'
Shawn Pearcede84f992006-03-05 03:24:15 -050067
Eric Sunshine9fb7b572014-12-24 04:43:12 -050068test_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) &&
Shawn Pearcede84f992006-03-05 03:24:15 -050074 test -f $p &&
Eric Sunshine9fb7b572014-12-24 04:43:12 -050075 test $(cat $p) = tree2path1
76'
Shawn Pearcede84f992006-03-05 03:24:15 -050077
Eric Sunshine9fb7b572014-12-24 04:43:12 -050078test_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
83 do
84 test $(grep $f actual | cut "-d " -f2) = $f &&
85 p=$(grep $f actual | cut "-d " -f1) &&
86 test -f $p &&
87 test $(cat $p) = tree2$f
88 done
89'
Shawn Pearcede84f992006-03-05 03:24:15 -050090
Jeff King7e410612020-10-27 03:37:14 -040091test_expect_success 'checkout all stages of unknown path' '
Jeff King0b809c82020-10-27 03:36:02 -040092 rm -f path* .merge_* actual &&
93 test_must_fail git checkout-index --stage=all --temp \
94 -- does-not-exist 2>stderr &&
95 test_i18ngrep not.in.the.cache stderr
96'
97
Eric Sunshine9fb7b572014-12-24 04:43:12 -050098test_expect_success 'checkout all stages/one file to nothing' '
99 rm -f path* .merge_* actual &&
Jeff King0b809c82020-10-27 03:36:02 -0400100 git checkout-index --stage=all --temp -- path0 >actual 2>stderr &&
101 test_must_be_empty stderr &&
Eric Sunshine9fb7b572014-12-24 04:43:12 -0500102 test_line_count = 0 actual
103'
Shawn Pearcede84f992006-03-05 03:24:15 -0500104
Eric Sunshine9fb7b572014-12-24 04:43:12 -0500105test_expect_success 'checkout all stages/one file to temporary files' '
106 rm -f path* .merge_* actual &&
107 git checkout-index --stage=all --temp -- path1 >actual &&
108 test_line_count = 1 actual &&
109 test $(cut "-d " -f2 actual) = path1 &&
110 cut "-d " -f1 actual | (read s1 s2 s3 &&
111 test -f $s1 &&
112 test -f $s2 &&
113 test -f $s3 &&
114 test $(cat $s1) = tree1path1 &&
115 test $(cat $s2) = tree2path1 &&
116 test $(cat $s3) = tree3path1)
117'
Shawn Pearcede84f992006-03-05 03:24:15 -0500118
Eric Sunshine9fb7b572014-12-24 04:43:12 -0500119test_expect_success 'checkout some stages/one file to temporary files' '
120 rm -f path* .merge_* actual &&
121 git checkout-index --stage=all --temp -- path2 >actual &&
122 test_line_count = 1 actual &&
123 test $(cut "-d " -f2 actual) = path2 &&
124 cut "-d " -f1 actual | (read s1 s2 s3 &&
125 test $s1 = . &&
126 test -f $s2 &&
127 test -f $s3 &&
128 test $(cat $s2) = tree2path2 &&
129 test $(cat $s3) = tree3path2)
130'
Shawn Pearcede84f992006-03-05 03:24:15 -0500131
Eric Sunshine9fb7b572014-12-24 04:43:12 -0500132test_expect_success 'checkout all stages/all files to temporary files' '
133 rm -f path* .merge_* actual &&
134 git checkout-index -a --stage=all --temp >actual &&
135 test_line_count = 5 actual
136'
Shawn Pearcede84f992006-03-05 03:24:15 -0500137
Eric Sunshine9fb7b572014-12-24 04:43:12 -0500138test_expect_success '-- path0: no entry' '
139 test x$(grep path0 actual | cut "-d " -f2) = x
140'
Shawn Pearcede84f992006-03-05 03:24:15 -0500141
Eric Sunshine9fb7b572014-12-24 04:43:12 -0500142test_expect_success '-- path1: all 3 stages' '
143 test $(grep path1 actual | cut "-d " -f2) = path1 &&
144 grep path1 actual | cut "-d " -f1 | (read s1 s2 s3 &&
145 test -f $s1 &&
146 test -f $s2 &&
147 test -f $s3 &&
148 test $(cat $s1) = tree1path1 &&
149 test $(cat $s2) = tree2path1 &&
150 test $(cat $s3) = tree3path1)
151'
Shawn Pearcede84f992006-03-05 03:24:15 -0500152
Eric Sunshine9fb7b572014-12-24 04:43:12 -0500153test_expect_success '-- path2: no stage 1, have stage 2 and 3' '
154 test $(grep path2 actual | cut "-d " -f2) = path2 &&
155 grep path2 actual | cut "-d " -f1 | (read s1 s2 s3 &&
156 test $s1 = . &&
157 test -f $s2 &&
158 test -f $s3 &&
159 test $(cat $s2) = tree2path2 &&
160 test $(cat $s3) = tree3path2)
161'
Shawn Pearcede84f992006-03-05 03:24:15 -0500162
Eric Sunshine9fb7b572014-12-24 04:43:12 -0500163test_expect_success '-- path3: no stage 2, have stage 1 and 3' '
164 test $(grep path3 actual | cut "-d " -f2) = path3 &&
165 grep path3 actual | cut "-d " -f1 | (read s1 s2 s3 &&
166 test -f $s1 &&
167 test $s2 = . &&
168 test -f $s3 &&
169 test $(cat $s1) = tree1path3 &&
170 test $(cat $s3) = tree3path3)
171'
Shawn Pearcede84f992006-03-05 03:24:15 -0500172
Eric Sunshine9fb7b572014-12-24 04:43:12 -0500173test_expect_success '-- path4: no stage 3, have stage 1 and 3' '
174 test $(grep path4 actual | cut "-d " -f2) = path4 &&
175 grep path4 actual | cut "-d " -f1 | (read s1 s2 s3 &&
176 test -f $s1 &&
177 test -f $s2 &&
178 test $s3 = . &&
179 test $(cat $s1) = tree1path4 &&
180 test $(cat $s2) = tree2path4)
181'
Shawn Pearcede84f992006-03-05 03:24:15 -0500182
Eric Sunshine9fb7b572014-12-24 04:43:12 -0500183test_expect_success '-- asubdir/path5: no stage 2 and 3 have stage 1' '
184 test $(grep asubdir/path5 actual | cut "-d " -f2) = asubdir/path5 &&
185 grep asubdir/path5 actual | cut "-d " -f1 | (read s1 s2 s3 &&
186 test -f $s1 &&
187 test $s2 = . &&
188 test $s3 = . &&
189 test $(cat $s1) = tree1asubdir/path5)
190'
Shawn Pearcede84f992006-03-05 03:24:15 -0500191
Eric Sunshine9fb7b572014-12-24 04:43:12 -0500192test_expect_success 'checkout --temp within subdir' '
193 (
194 cd asubdir &&
195 git checkout-index -a --stage=all >actual &&
196 test_line_count = 1 actual &&
197 test $(grep path5 actual | cut "-d " -f2) = path5 &&
198 grep path5 actual | cut "-d " -f1 | (read s1 s2 s3 &&
199 test -f ../$s1 &&
200 test $s2 = . &&
201 test $s3 = . &&
202 test $(cat ../$s1) = tree1asubdir/path5)
203 )
204'
205
206test_expect_success 'checkout --temp symlink' '
207 rm -f path* .merge_* actual .git/index &&
Eric Sunshine66e28e92014-12-24 04:43:14 -0500208 test_ln_s_add path7 path6 &&
Eric Sunshine9fb7b572014-12-24 04:43:12 -0500209 git checkout-index --temp -a >actual &&
210 test_line_count = 1 actual &&
Eric Sunshine66e28e92014-12-24 04:43:14 -0500211 test $(cut "-d " -f2 actual) = path6 &&
Eric Sunshine9fb7b572014-12-24 04:43:12 -0500212 p=$(cut "-d " -f1 actual) &&
213 test -f $p &&
Eric Sunshine66e28e92014-12-24 04:43:14 -0500214 test $(cat $p) = path7
Eric Sunshine9fb7b572014-12-24 04:43:12 -0500215'
Shawn Pearcede84f992006-03-05 03:24:15 -0500216
Eric Sunshine74c4de52014-12-24 04:43:16 -0500217test_expect_success 'emit well-formed relative path' '
Eric Sunshine052b2552014-12-24 04:43:15 -0500218 rm -f path* .merge_* actual .git/index &&
219 >path0123456789 &&
220 git update-index --add path0123456789 &&
221 (
222 cd asubdir &&
223 git checkout-index --temp -- ../path0123456789 >actual &&
224 test_line_count = 1 actual &&
225 test $(cut "-d " -f2 actual) = ../path0123456789
226 )
227'
228
Shawn Pearcede84f992006-03-05 03:24:15 -0500229test_done