Blame


1 3ce1b845 2019-07-15 stsp #!/bin/sh
2 3ce1b845 2019-07-15 stsp #
3 3ce1b845 2019-07-15 stsp # Copyright (c) 2019 Stefan Sperling <stsp@openbsd.org>
4 3ce1b845 2019-07-15 stsp #
5 3ce1b845 2019-07-15 stsp # Permission to use, copy, modify, and distribute this software for any
6 3ce1b845 2019-07-15 stsp # purpose with or without fee is hereby granted, provided that the above
7 3ce1b845 2019-07-15 stsp # copyright notice and this permission notice appear in all copies.
8 3ce1b845 2019-07-15 stsp #
9 3ce1b845 2019-07-15 stsp # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 3ce1b845 2019-07-15 stsp # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 3ce1b845 2019-07-15 stsp # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 3ce1b845 2019-07-15 stsp # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 3ce1b845 2019-07-15 stsp # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 3ce1b845 2019-07-15 stsp # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 3ce1b845 2019-07-15 stsp # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 3ce1b845 2019-07-15 stsp
17 3ce1b845 2019-07-15 stsp . ./common.sh
18 3ce1b845 2019-07-15 stsp
19 f6cae3ed 2020-09-13 naddy test_import_basic() {
20 71db5e8c 2019-08-08 stsp local testname=import_basic
21 ea2819be 2023-05-29 op local testroot=`mktemp -d \
22 ea2819be 2023-05-29 op "$GOT_TEST_ROOT/got-test-$testname-XXXXXXXXXX"`
23 3ce1b845 2019-07-15 stsp
24 02a5c5d0 2022-07-04 stsp gotadmin init $testroot/repo
25 3ce1b845 2019-07-15 stsp
26 3ce1b845 2019-07-15 stsp mkdir $testroot/tree
27 3ce1b845 2019-07-15 stsp make_test_tree $testroot/tree
28 3ce1b845 2019-07-15 stsp
29 3ce1b845 2019-07-15 stsp got import -m 'init' -r $testroot/repo $testroot/tree \
30 3ce1b845 2019-07-15 stsp > $testroot/stdout
31 49c543a6 2022-03-31 naddy ret=$?
32 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
33 3ce1b845 2019-07-15 stsp test_done "$testroot" "$ret"
34 3ce1b845 2019-07-15 stsp return 1
35 3ce1b845 2019-07-15 stsp fi
36 3ce1b845 2019-07-15 stsp
37 3ce1b845 2019-07-15 stsp local head_commit=`git_show_head $testroot/repo`
38 3ce1b845 2019-07-15 stsp echo "A $testroot/tree/gamma/delta" > $testroot/stdout.expected
39 3ce1b845 2019-07-15 stsp echo "A $testroot/tree/epsilon/zeta" >> $testroot/stdout.expected
40 3ce1b845 2019-07-15 stsp echo "A $testroot/tree/alpha" >> $testroot/stdout.expected
41 3ce1b845 2019-07-15 stsp echo "A $testroot/tree/beta" >> $testroot/stdout.expected
42 5d67f40d 2019-11-08 stsp echo "Created branch refs/heads/main with commit $head_commit" \
43 3ce1b845 2019-07-15 stsp >> $testroot/stdout.expected
44 3ce1b845 2019-07-15 stsp
45 3ce1b845 2019-07-15 stsp cmp -s $testroot/stdout.expected $testroot/stdout
46 49c543a6 2022-03-31 naddy ret=$?
47 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
48 3ce1b845 2019-07-15 stsp diff -u $testroot/stdout.expected $testroot/stdout
49 3ce1b845 2019-07-15 stsp test_done "$testroot" "$ret"
50 3ce1b845 2019-07-15 stsp return 1
51 3ce1b845 2019-07-15 stsp fi
52 3ce1b845 2019-07-15 stsp
53 3ce1b845 2019-07-15 stsp (cd $testroot/repo && got log -p | grep -v ^date: > $testroot/stdout)
54 3ce1b845 2019-07-15 stsp
55 3ce1b845 2019-07-15 stsp id_alpha=`get_blob_id $testroot/repo "" alpha`
56 3ce1b845 2019-07-15 stsp id_beta=`get_blob_id $testroot/repo "" beta`
57 3ce1b845 2019-07-15 stsp id_zeta=`get_blob_id $testroot/repo epsilon zeta`
58 3ce1b845 2019-07-15 stsp id_delta=`get_blob_id $testroot/repo gamma delta`
59 44392932 2019-08-25 stsp tree_id=`(cd $testroot/repo && got cat $head_commit | \
60 44392932 2019-08-25 stsp grep ^tree | cut -d ' ' -f 2)`
61 3ce1b845 2019-07-15 stsp
62 3ce1b845 2019-07-15 stsp echo "-----------------------------------------------" \
63 3ce1b845 2019-07-15 stsp > $testroot/stdout.expected
64 5d67f40d 2019-11-08 stsp echo "commit $head_commit (main)" >> $testroot/stdout.expected
65 3ce1b845 2019-07-15 stsp echo "from: $GOT_AUTHOR" >> $testroot/stdout.expected
66 3ce1b845 2019-07-15 stsp echo " " >> $testroot/stdout.expected
67 3ce1b845 2019-07-15 stsp echo " init" >> $testroot/stdout.expected
68 3ce1b845 2019-07-15 stsp echo " " >> $testroot/stdout.expected
69 8469d821 2022-06-25 stsp echo "diff /dev/null $head_commit" >> $testroot/stdout.expected
70 8469d821 2022-06-25 stsp echo "commit - /dev/null" >> $testroot/stdout.expected
71 8469d821 2022-06-25 stsp echo "commit + $head_commit" >> $testroot/stdout.expected
72 3ce1b845 2019-07-15 stsp echo "blob - /dev/null" >> $testroot/stdout.expected
73 46f68b20 2019-10-19 stsp echo "blob + $id_alpha (mode 644)" >> $testroot/stdout.expected
74 3ce1b845 2019-07-15 stsp echo "--- /dev/null" >> $testroot/stdout.expected
75 3ce1b845 2019-07-15 stsp echo "+++ alpha" >> $testroot/stdout.expected
76 3ce1b845 2019-07-15 stsp echo "@@ -0,0 +1 @@" >> $testroot/stdout.expected
77 3ce1b845 2019-07-15 stsp echo "+alpha" >> $testroot/stdout.expected
78 3ce1b845 2019-07-15 stsp echo "blob - /dev/null" >> $testroot/stdout.expected
79 46f68b20 2019-10-19 stsp echo "blob + $id_beta (mode 644)" >> $testroot/stdout.expected
80 3ce1b845 2019-07-15 stsp echo "--- /dev/null" >> $testroot/stdout.expected
81 3ce1b845 2019-07-15 stsp echo "+++ beta" >> $testroot/stdout.expected
82 3ce1b845 2019-07-15 stsp echo "@@ -0,0 +1 @@" >> $testroot/stdout.expected
83 3ce1b845 2019-07-15 stsp echo "+beta" >> $testroot/stdout.expected
84 3ce1b845 2019-07-15 stsp echo "blob - /dev/null" >> $testroot/stdout.expected
85 46f68b20 2019-10-19 stsp echo "blob + $id_zeta (mode 644)" >> $testroot/stdout.expected
86 3ce1b845 2019-07-15 stsp echo "--- /dev/null" >> $testroot/stdout.expected
87 3ce1b845 2019-07-15 stsp echo "+++ epsilon/zeta" >> $testroot/stdout.expected
88 3ce1b845 2019-07-15 stsp echo "@@ -0,0 +1 @@" >> $testroot/stdout.expected
89 3ce1b845 2019-07-15 stsp echo "+zeta" >> $testroot/stdout.expected
90 3ce1b845 2019-07-15 stsp echo "blob - /dev/null" >> $testroot/stdout.expected
91 46f68b20 2019-10-19 stsp echo "blob + $id_delta (mode 644)" >> $testroot/stdout.expected
92 3ce1b845 2019-07-15 stsp echo "--- /dev/null" >> $testroot/stdout.expected
93 3ce1b845 2019-07-15 stsp echo "+++ gamma/delta" >> $testroot/stdout.expected
94 3ce1b845 2019-07-15 stsp echo "@@ -0,0 +1 @@" >> $testroot/stdout.expected
95 3ce1b845 2019-07-15 stsp echo "+delta" >> $testroot/stdout.expected
96 3ce1b845 2019-07-15 stsp echo "" >> $testroot/stdout.expected
97 3ce1b845 2019-07-15 stsp
98 3ce1b845 2019-07-15 stsp cmp -s $testroot/stdout.expected $testroot/stdout
99 49c543a6 2022-03-31 naddy ret=$?
100 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
101 3ce1b845 2019-07-15 stsp diff -u $testroot/stdout.expected $testroot/stdout
102 3ce1b845 2019-07-15 stsp test_done "$testroot" "$ret"
103 3ce1b845 2019-07-15 stsp return 1
104 3ce1b845 2019-07-15 stsp fi
105 3ce1b845 2019-07-15 stsp
106 3ce1b845 2019-07-15 stsp echo "A $testroot/wt/alpha" > $testroot/stdout.expected
107 3ce1b845 2019-07-15 stsp echo "A $testroot/wt/beta" >> $testroot/stdout.expected
108 3ce1b845 2019-07-15 stsp echo "A $testroot/wt/epsilon/zeta" >> $testroot/stdout.expected
109 3ce1b845 2019-07-15 stsp echo "A $testroot/wt/gamma/delta" >> $testroot/stdout.expected
110 08e5873e 2021-09-14 stsp echo "Checked out refs/heads/main: $head_commit" \
111 08e5873e 2021-09-14 stsp >> $testroot/stdout.expected
112 3ce1b845 2019-07-15 stsp echo "Now shut up and hack" >> $testroot/stdout.expected
113 3ce1b845 2019-07-15 stsp
114 3ce1b845 2019-07-15 stsp got checkout $testroot/repo $testroot/wt > $testroot/stdout
115 49c543a6 2022-03-31 naddy ret=$?
116 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
117 3ce1b845 2019-07-15 stsp test_done "$testroot" "$ret"
118 3ce1b845 2019-07-15 stsp return 1
119 3ce1b845 2019-07-15 stsp fi
120 3ce1b845 2019-07-15 stsp
121 3ce1b845 2019-07-15 stsp cmp -s $testroot/stdout.expected $testroot/stdout
122 49c543a6 2022-03-31 naddy ret=$?
123 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
124 3ce1b845 2019-07-15 stsp diff -u $testroot/stdout.expected $testroot/stdout
125 3ce1b845 2019-07-15 stsp test_done "$testroot" "$ret"
126 3ce1b845 2019-07-15 stsp return 1
127 3ce1b845 2019-07-15 stsp fi
128 3ce1b845 2019-07-15 stsp
129 3ce1b845 2019-07-15 stsp echo "alpha" > $testroot/content.expected
130 3ce1b845 2019-07-15 stsp echo "beta" >> $testroot/content.expected
131 3ce1b845 2019-07-15 stsp echo "zeta" >> $testroot/content.expected
132 3ce1b845 2019-07-15 stsp echo "delta" >> $testroot/content.expected
133 3ce1b845 2019-07-15 stsp cat $testroot/wt/alpha $testroot/wt/beta $testroot/wt/epsilon/zeta \
134 3ce1b845 2019-07-15 stsp $testroot/wt/gamma/delta > $testroot/content
135 3ce1b845 2019-07-15 stsp
136 3ce1b845 2019-07-15 stsp cmp -s $testroot/content.expected $testroot/content
137 49c543a6 2022-03-31 naddy ret=$?
138 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
139 3ce1b845 2019-07-15 stsp diff -u $testroot/content.expected $testroot/content
140 3ce1b845 2019-07-15 stsp fi
141 3ce1b845 2019-07-15 stsp test_done "$testroot" "$ret"
142 3ce1b845 2019-07-15 stsp }
143 3ce1b845 2019-07-15 stsp
144 6f04a73d 2022-09-20 mark test_import_specified_head() {
145 6f04a73d 2022-09-20 mark local testname=import_specified_head
146 ea2819be 2023-05-29 op local testroot=`mktemp -d \
147 ea2819be 2023-05-29 op "$GOT_TEST_ROOT/got-test-$testname-XXXXXXXXXX"`
148 6f04a73d 2022-09-20 mark local headref=trunk
149 6f04a73d 2022-09-20 mark
150 6f04a73d 2022-09-20 mark gotadmin init -b $headref $testroot/repo
151 6f04a73d 2022-09-20 mark
152 6f04a73d 2022-09-20 mark mkdir $testroot/tree
153 6f04a73d 2022-09-20 mark make_test_tree $testroot/tree
154 6f04a73d 2022-09-20 mark
155 6f04a73d 2022-09-20 mark got import -m init -r $testroot/repo $testroot/tree > $testroot/stdout
156 6f04a73d 2022-09-20 mark ret=$?
157 6f04a73d 2022-09-20 mark if [ $ret -ne 0 ]; then
158 6f04a73d 2022-09-20 mark test_done "$testroot" "$ret"
159 6f04a73d 2022-09-20 mark return 1
160 6f04a73d 2022-09-20 mark fi
161 6f04a73d 2022-09-20 mark
162 6f04a73d 2022-09-20 mark local head_commit=`git_show_head $testroot/repo`
163 6f04a73d 2022-09-20 mark echo "A $testroot/tree/gamma/delta" > $testroot/stdout.expected
164 6f04a73d 2022-09-20 mark echo "A $testroot/tree/epsilon/zeta" >> $testroot/stdout.expected
165 6f04a73d 2022-09-20 mark echo "A $testroot/tree/alpha" >> $testroot/stdout.expected
166 6f04a73d 2022-09-20 mark echo "A $testroot/tree/beta" >> $testroot/stdout.expected
167 6f04a73d 2022-09-20 mark echo "Created branch refs/heads/$headref with commit $head_commit" \
168 6f04a73d 2022-09-20 mark >> $testroot/stdout.expected
169 6f04a73d 2022-09-20 mark
170 6f04a73d 2022-09-20 mark cmp -s $testroot/stdout.expected $testroot/stdout
171 6f04a73d 2022-09-20 mark ret=$?
172 6f04a73d 2022-09-20 mark if [ $ret -ne 0 ]; then
173 6f04a73d 2022-09-20 mark echo "fail"
174 6f04a73d 2022-09-20 mark diff -u $testroot/stdout.expected $testroot/stdout
175 6f04a73d 2022-09-20 mark test_done "$testroot" "$ret"
176 6f04a73d 2022-09-20 mark return 1
177 6f04a73d 2022-09-20 mark fi
178 6f04a73d 2022-09-20 mark
179 6f04a73d 2022-09-20 mark (cd $testroot/repo && got log -p | grep -v ^date: > $testroot/stdout)
180 6f04a73d 2022-09-20 mark
181 6f04a73d 2022-09-20 mark id_alpha=`get_blob_id $testroot/repo "" alpha`
182 6f04a73d 2022-09-20 mark id_beta=`get_blob_id $testroot/repo "" beta`
183 6f04a73d 2022-09-20 mark id_zeta=`get_blob_id $testroot/repo epsilon zeta`
184 6f04a73d 2022-09-20 mark id_delta=`get_blob_id $testroot/repo gamma delta`
185 6f04a73d 2022-09-20 mark tree_id=`(cd $testroot/repo && got cat $head_commit | \
186 6f04a73d 2022-09-20 mark grep ^tree | cut -d ' ' -f 2)`
187 6f04a73d 2022-09-20 mark
188 6f04a73d 2022-09-20 mark echo "-----------------------------------------------" \
189 6f04a73d 2022-09-20 mark > $testroot/stdout.expected
190 6f04a73d 2022-09-20 mark echo "commit $head_commit ($headref)" >> $testroot/stdout.expected
191 6f04a73d 2022-09-20 mark echo "from: $GOT_AUTHOR" >> $testroot/stdout.expected
192 6f04a73d 2022-09-20 mark echo " " >> $testroot/stdout.expected
193 6f04a73d 2022-09-20 mark echo " init" >> $testroot/stdout.expected
194 6f04a73d 2022-09-20 mark echo " " >> $testroot/stdout.expected
195 6f04a73d 2022-09-20 mark echo "diff /dev/null $head_commit" >> $testroot/stdout.expected
196 6f04a73d 2022-09-20 mark echo "commit - /dev/null" >> $testroot/stdout.expected
197 6f04a73d 2022-09-20 mark echo "commit + $head_commit" >> $testroot/stdout.expected
198 6f04a73d 2022-09-20 mark echo "blob - /dev/null" >> $testroot/stdout.expected
199 6f04a73d 2022-09-20 mark echo "blob + $id_alpha (mode 644)" >> $testroot/stdout.expected
200 6f04a73d 2022-09-20 mark echo "--- /dev/null" >> $testroot/stdout.expected
201 6f04a73d 2022-09-20 mark echo "+++ alpha" >> $testroot/stdout.expected
202 6f04a73d 2022-09-20 mark echo "@@ -0,0 +1 @@" >> $testroot/stdout.expected
203 6f04a73d 2022-09-20 mark echo "+alpha" >> $testroot/stdout.expected
204 6f04a73d 2022-09-20 mark echo "blob - /dev/null" >> $testroot/stdout.expected
205 6f04a73d 2022-09-20 mark echo "blob + $id_beta (mode 644)" >> $testroot/stdout.expected
206 6f04a73d 2022-09-20 mark echo "--- /dev/null" >> $testroot/stdout.expected
207 6f04a73d 2022-09-20 mark echo "+++ beta" >> $testroot/stdout.expected
208 6f04a73d 2022-09-20 mark echo "@@ -0,0 +1 @@" >> $testroot/stdout.expected
209 6f04a73d 2022-09-20 mark echo "+beta" >> $testroot/stdout.expected
210 6f04a73d 2022-09-20 mark echo "blob - /dev/null" >> $testroot/stdout.expected
211 6f04a73d 2022-09-20 mark echo "blob + $id_zeta (mode 644)" >> $testroot/stdout.expected
212 6f04a73d 2022-09-20 mark echo "--- /dev/null" >> $testroot/stdout.expected
213 6f04a73d 2022-09-20 mark echo "+++ epsilon/zeta" >> $testroot/stdout.expected
214 6f04a73d 2022-09-20 mark echo "@@ -0,0 +1 @@" >> $testroot/stdout.expected
215 6f04a73d 2022-09-20 mark echo "+zeta" >> $testroot/stdout.expected
216 6f04a73d 2022-09-20 mark echo "blob - /dev/null" >> $testroot/stdout.expected
217 6f04a73d 2022-09-20 mark echo "blob + $id_delta (mode 644)" >> $testroot/stdout.expected
218 6f04a73d 2022-09-20 mark echo "--- /dev/null" >> $testroot/stdout.expected
219 6f04a73d 2022-09-20 mark echo "+++ gamma/delta" >> $testroot/stdout.expected
220 6f04a73d 2022-09-20 mark echo "@@ -0,0 +1 @@" >> $testroot/stdout.expected
221 6f04a73d 2022-09-20 mark echo "+delta" >> $testroot/stdout.expected
222 6f04a73d 2022-09-20 mark echo "" >> $testroot/stdout.expected
223 6f04a73d 2022-09-20 mark
224 6f04a73d 2022-09-20 mark cmp -s $testroot/stdout.expected $testroot/stdout
225 6f04a73d 2022-09-20 mark ret=$?
226 6f04a73d 2022-09-20 mark if [ $ret -ne 0 ]; then
227 6f04a73d 2022-09-20 mark echo "fail"
228 6f04a73d 2022-09-20 mark diff -u $testroot/stdout.expected $testroot/stdout
229 6f04a73d 2022-09-20 mark test_done "$testroot" "$ret"
230 6f04a73d 2022-09-20 mark return 1
231 6f04a73d 2022-09-20 mark fi
232 6f04a73d 2022-09-20 mark
233 6f04a73d 2022-09-20 mark echo "A $testroot/wt/alpha" > $testroot/stdout.expected
234 6f04a73d 2022-09-20 mark echo "A $testroot/wt/beta" >> $testroot/stdout.expected
235 6f04a73d 2022-09-20 mark echo "A $testroot/wt/epsilon/zeta" >> $testroot/stdout.expected
236 6f04a73d 2022-09-20 mark echo "A $testroot/wt/gamma/delta" >> $testroot/stdout.expected
237 6f04a73d 2022-09-20 mark echo "Checked out refs/heads/$headref: $head_commit" \
238 6f04a73d 2022-09-20 mark >> $testroot/stdout.expected
239 6f04a73d 2022-09-20 mark echo "Now shut up and hack" >> $testroot/stdout.expected
240 6f04a73d 2022-09-20 mark
241 6f04a73d 2022-09-20 mark got checkout $testroot/repo $testroot/wt > $testroot/stdout
242 6f04a73d 2022-09-20 mark cmp -s $testroot/stdout.expected $testroot/stdout
243 6f04a73d 2022-09-20 mark ret=$?
244 6f04a73d 2022-09-20 mark if [ $ret -ne 0 ]; then
245 6f04a73d 2022-09-20 mark echo "fail"
246 6f04a73d 2022-09-20 mark diff -u $testroot/stdout.expected $testroot/stdout
247 6f04a73d 2022-09-20 mark test_done "$testroot" "$ret"
248 6f04a73d 2022-09-20 mark return 1
249 6f04a73d 2022-09-20 mark fi
250 6f04a73d 2022-09-20 mark
251 6f04a73d 2022-09-20 mark cmp -s $testroot/stdout.expected $testroot/stdout
252 6f04a73d 2022-09-20 mark ret=$?
253 6f04a73d 2022-09-20 mark if [ $ret -ne 0 ]; then
254 6f04a73d 2022-09-20 mark echo "fail"
255 6f04a73d 2022-09-20 mark diff -u $testroot/stdout.expected $testroot/stdout
256 6f04a73d 2022-09-20 mark test_done "$testroot" "$ret"
257 6f04a73d 2022-09-20 mark return 1
258 6f04a73d 2022-09-20 mark fi
259 6f04a73d 2022-09-20 mark
260 6f04a73d 2022-09-20 mark echo "alpha" > $testroot/content.expected
261 6f04a73d 2022-09-20 mark echo "beta" >> $testroot/content.expected
262 6f04a73d 2022-09-20 mark echo "zeta" >> $testroot/content.expected
263 6f04a73d 2022-09-20 mark echo "delta" >> $testroot/content.expected
264 6f04a73d 2022-09-20 mark cat $testroot/wt/alpha $testroot/wt/beta $testroot/wt/epsilon/zeta \
265 6f04a73d 2022-09-20 mark $testroot/wt/gamma/delta > $testroot/content
266 6f04a73d 2022-09-20 mark
267 6f04a73d 2022-09-20 mark cmp -s $testroot/content.expected $testroot/content
268 6f04a73d 2022-09-20 mark ret=$?
269 6f04a73d 2022-09-20 mark if [ $ret -ne 0 ]; then
270 6f04a73d 2022-09-20 mark echo "fail"
271 6f04a73d 2022-09-20 mark diff -u $testroot/content.expected $testroot/content
272 6f04a73d 2022-09-20 mark fi
273 6f04a73d 2022-09-20 mark test_done "$testroot" "$ret"
274 6f04a73d 2022-09-20 mark }
275 6f04a73d 2022-09-20 mark
276 6f04a73d 2022-09-20 mark test_import_detached_head() {
277 6f04a73d 2022-09-20 mark local testroot=`test_init import_detached_head`
278 6f04a73d 2022-09-20 mark
279 6f04a73d 2022-09-20 mark # mute verbose 'detached HEAD' warning
280 6f04a73d 2022-09-20 mark (cd $testroot/repo && git config --local advice.detachedHead false)
281 6f04a73d 2022-09-20 mark ret=$?
282 6f04a73d 2022-09-20 mark if [ $ret -ne 0 ]; then
283 6f04a73d 2022-09-20 mark test_done "$testroot" "$ret"
284 6f04a73d 2022-09-20 mark return 1
285 6f04a73d 2022-09-20 mark fi
286 6f04a73d 2022-09-20 mark
287 6f04a73d 2022-09-20 mark # enter detached HEAD state
288 6f04a73d 2022-09-20 mark local head_commit=`git_show_head $testroot/repo | cut -c1-7`
289 6f04a73d 2022-09-20 mark (cd $testroot/repo && \
290 6f04a73d 2022-09-20 mark git checkout $head_commit > $testroot/stdout 2> $testroot/stderr)
291 6f04a73d 2022-09-20 mark ret=$?
292 6f04a73d 2022-09-20 mark if [ $ret -ne 0 ]; then
293 6f04a73d 2022-09-20 mark test_done "$testroot" "$ret"
294 6f04a73d 2022-09-20 mark return 1
295 6f04a73d 2022-09-20 mark fi
296 6f04a73d 2022-09-20 mark
297 6f04a73d 2022-09-20 mark echo "HEAD is now at $head_commit adding the test tree" >> \
298 6f04a73d 2022-09-20 mark $testroot/stderr.expected
299 6f04a73d 2022-09-20 mark
300 6f04a73d 2022-09-20 mark cmp -s $testroot/stderr.expected $testroot/stderr
301 6f04a73d 2022-09-20 mark ret=$?
302 6f04a73d 2022-09-20 mark if [ $ret -ne 0 ]; then
303 6f04a73d 2022-09-20 mark echo "fail"
304 6f04a73d 2022-09-20 mark diff -u $testroot/stderr.expected $testroot/stderr
305 6f04a73d 2022-09-20 mark test_done "$testroot" "$ret"
306 6f04a73d 2022-09-20 mark return 1
307 6f04a73d 2022-09-20 mark fi
308 6f04a73d 2022-09-20 mark
309 6f04a73d 2022-09-20 mark mkdir $testroot/import
310 6f04a73d 2022-09-20 mark make_test_tree $testroot/import
311 6f04a73d 2022-09-20 mark
312 6f04a73d 2022-09-20 mark # detached HEAD (i.e., not symbolic) so import should fallback to "main"
313 6f04a73d 2022-09-20 mark got import -r $testroot/repo -m init $testroot/import > $testroot/stdout
314 6f04a73d 2022-09-20 mark ret=$?
315 6f04a73d 2022-09-20 mark if [ $ret -ne 0 ]; then
316 6f04a73d 2022-09-20 mark test_done "$testroot" "$ret"
317 6f04a73d 2022-09-20 mark return 1
318 6f04a73d 2022-09-20 mark fi
319 6f04a73d 2022-09-20 mark
320 6f04a73d 2022-09-20 mark local main_commit=`(cd $testroot/repo && \
321 6f04a73d 2022-09-20 mark git show-ref main | cut -d ' ' -f 1)`
322 6f04a73d 2022-09-20 mark echo "A $testroot/import/gamma/delta" > $testroot/stdout.expected
323 6f04a73d 2022-09-20 mark echo "A $testroot/import/epsilon/zeta" >> $testroot/stdout.expected
324 6f04a73d 2022-09-20 mark echo "A $testroot/import/alpha" >> $testroot/stdout.expected
325 6f04a73d 2022-09-20 mark echo "A $testroot/import/beta" >> $testroot/stdout.expected
326 6f04a73d 2022-09-20 mark echo "Created branch refs/heads/main with commit $main_commit" \
327 6f04a73d 2022-09-20 mark >> $testroot/stdout.expected
328 6f04a73d 2022-09-20 mark
329 6f04a73d 2022-09-20 mark cmp -s $testroot/stdout.expected $testroot/stdout
330 6f04a73d 2022-09-20 mark ret=$?
331 6f04a73d 2022-09-20 mark if [ $ret -ne 0 ]; then
332 6f04a73d 2022-09-20 mark echo "fail"
333 6f04a73d 2022-09-20 mark diff -u $testroot/stdout.expected $testroot/stdout
334 6f04a73d 2022-09-20 mark fi
335 6f04a73d 2022-09-20 mark test_done "$testroot" "$ret"
336 6f04a73d 2022-09-20 mark }
337 6f04a73d 2022-09-20 mark
338 f6cae3ed 2020-09-13 naddy test_import_requires_new_branch() {
339 3ce1b845 2019-07-15 stsp local testroot=`test_init import_requires_new_branch`
340 3ce1b845 2019-07-15 stsp
341 3ce1b845 2019-07-15 stsp mkdir $testroot/tree
342 3ce1b845 2019-07-15 stsp make_test_tree $testroot/tree
343 3ce1b845 2019-07-15 stsp
344 5d67f40d 2019-11-08 stsp got import -b master -m 'init' -r $testroot/repo $testroot/tree \
345 3ce1b845 2019-07-15 stsp > $testroot/stdout 2> $testroot/stderr
346 49c543a6 2022-03-31 naddy ret=$?
347 49c543a6 2022-03-31 naddy if [ $ret -eq 0 ]; then
348 3ce1b845 2019-07-15 stsp echo "import command should have failed but did not"
349 3ce1b845 2019-07-15 stsp test_done "$testroot" "1"
350 3ce1b845 2019-07-15 stsp return 1
351 3ce1b845 2019-07-15 stsp fi
352 3ce1b845 2019-07-15 stsp
353 3ce1b845 2019-07-15 stsp echo "got: import target branch already exists" \
354 3ce1b845 2019-07-15 stsp > $testroot/stderr.expected
355 3ce1b845 2019-07-15 stsp cmp -s $testroot/stderr.expected $testroot/stderr
356 49c543a6 2022-03-31 naddy ret=$?
357 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
358 3ce1b845 2019-07-15 stsp diff -u $testroot/stderr.expected $testroot/stderr
359 3ce1b845 2019-07-15 stsp test_done "$testroot" "$ret"
360 3ce1b845 2019-07-15 stsp return 1
361 3ce1b845 2019-07-15 stsp fi
362 3ce1b845 2019-07-15 stsp
363 3ce1b845 2019-07-15 stsp got import -b newbranch -m 'init' -r $testroot/repo $testroot/tree \
364 3ce1b845 2019-07-15 stsp > $testroot/stdout
365 49c543a6 2022-03-31 naddy ret=$?
366 3ce1b845 2019-07-15 stsp test_done "$testroot" "$ret"
367 3ce1b845 2019-07-15 stsp
368 3ce1b845 2019-07-15 stsp }
369 3ce1b845 2019-07-15 stsp
370 f6cae3ed 2020-09-13 naddy test_import_ignores() {
371 71db5e8c 2019-08-08 stsp local testname=import_ignores
372 ea2819be 2023-05-29 op local testroot=`mktemp -d \
373 ea2819be 2023-05-29 op "$GOT_TEST_ROOT/got-test-$testname-XXXXXXXXXX"`
374 3ce1b845 2019-07-15 stsp
375 02a5c5d0 2022-07-04 stsp gotadmin init $testroot/repo
376 3ce1b845 2019-07-15 stsp
377 3ce1b845 2019-07-15 stsp mkdir $testroot/tree
378 3ce1b845 2019-07-15 stsp make_test_tree $testroot/tree
379 3ce1b845 2019-07-15 stsp
380 d0f874e0 2023-02-19 stsp touch $testroot/tree/upsilon
381 d0f874e0 2023-02-19 stsp mkdir $testroot/tree/ysilon
382 49351f3b 2023-02-06 stsp got import -I alpha -I 'beta/' -I '*lta*' -I '*silon/' \
383 3ce1b845 2019-07-15 stsp -m 'init' -r $testroot/repo $testroot/tree > $testroot/stdout
384 49c543a6 2022-03-31 naddy ret=$?
385 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
386 3ce1b845 2019-07-15 stsp test_done "$testroot" "$ret"
387 3ce1b845 2019-07-15 stsp return 1
388 3ce1b845 2019-07-15 stsp fi
389 3ce1b845 2019-07-15 stsp
390 3ce1b845 2019-07-15 stsp local head_commit=`git_show_head $testroot/repo`
391 3ce1b845 2019-07-15 stsp echo "A $testroot/tree/beta" >> $testroot/stdout.expected
392 d0f874e0 2023-02-19 stsp echo "A $testroot/tree/upsilon" >> $testroot/stdout.expected
393 5d67f40d 2019-11-08 stsp echo "Created branch refs/heads/main with commit $head_commit" \
394 3ce1b845 2019-07-15 stsp >> $testroot/stdout.expected
395 3ce1b845 2019-07-15 stsp
396 3ce1b845 2019-07-15 stsp cmp -s $testroot/stdout.expected $testroot/stdout
397 49c543a6 2022-03-31 naddy ret=$?
398 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
399 3ce1b845 2019-07-15 stsp diff -u $testroot/stdout.expected $testroot/stdout
400 3ce1b845 2019-07-15 stsp fi
401 3ce1b845 2019-07-15 stsp test_done "$testroot" "$ret"
402 db1d3576 2019-10-04 stsp }
403 3ce1b845 2019-07-15 stsp
404 f6cae3ed 2020-09-13 naddy test_import_empty_dir() {
405 db1d3576 2019-10-04 stsp local testname=import_empty_dir
406 ea2819be 2023-05-29 op local testroot=`mktemp -d \
407 ea2819be 2023-05-29 op "$GOT_TEST_ROOT/got-test-$testname-XXXXXXXXXX"`
408 3ce1b845 2019-07-15 stsp
409 02a5c5d0 2022-07-04 stsp gotadmin init $testroot/repo
410 db1d3576 2019-10-04 stsp
411 db1d3576 2019-10-04 stsp mkdir $testroot/tree
412 db1d3576 2019-10-04 stsp mkdir -p $testroot/tree/empty $testroot/tree/notempty
413 db1d3576 2019-10-04 stsp echo "alpha" > $testroot/tree/notempty/alpha
414 db1d3576 2019-10-04 stsp
415 db1d3576 2019-10-04 stsp got import -m 'init' -r $testroot/repo $testroot/tree > $testroot/stdout
416 49c543a6 2022-03-31 naddy ret=$?
417 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
418 db1d3576 2019-10-04 stsp test_done "$testroot" "$ret"
419 db1d3576 2019-10-04 stsp return 1
420 db1d3576 2019-10-04 stsp fi
421 db1d3576 2019-10-04 stsp
422 db1d3576 2019-10-04 stsp local head_commit=`git_show_head $testroot/repo`
423 db1d3576 2019-10-04 stsp echo "A $testroot/tree/notempty/alpha" >> $testroot/stdout.expected
424 5d67f40d 2019-11-08 stsp echo "Created branch refs/heads/main with commit $head_commit" \
425 db1d3576 2019-10-04 stsp >> $testroot/stdout.expected
426 db1d3576 2019-10-04 stsp
427 db1d3576 2019-10-04 stsp cmp -s $testroot/stdout.expected $testroot/stdout
428 49c543a6 2022-03-31 naddy ret=$?
429 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
430 db1d3576 2019-10-04 stsp diff -u $testroot/stdout.expected $testroot/stdout
431 db1d3576 2019-10-04 stsp test_done "$testroot" "$ret"
432 db1d3576 2019-10-04 stsp return 1
433 db1d3576 2019-10-04 stsp fi
434 db1d3576 2019-10-04 stsp
435 db1d3576 2019-10-04 stsp # Verify that Got did not import the empty directory
436 db1d3576 2019-10-04 stsp echo "notempty/" > $testroot/stdout.expected
437 db1d3576 2019-10-04 stsp echo "notempty/alpha" >> $testroot/stdout.expected
438 db1d3576 2019-10-04 stsp
439 db1d3576 2019-10-04 stsp got tree -r $testroot/repo -R > $testroot/stdout
440 db1d3576 2019-10-04 stsp cmp -s $testroot/stdout.expected $testroot/stdout
441 49c543a6 2022-03-31 naddy ret=$?
442 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
443 db1d3576 2019-10-04 stsp diff -u $testroot/stdout.expected $testroot/stdout
444 db1d3576 2019-10-04 stsp fi
445 db1d3576 2019-10-04 stsp test_done "$testroot" "$ret"
446 3ce1b845 2019-07-15 stsp }
447 3ce1b845 2019-07-15 stsp
448 f6cae3ed 2020-09-13 naddy test_import_symlink() {
449 e8863bdc 2020-07-23 stsp local testname=import_symlink
450 ea2819be 2023-05-29 op local testroot=`mktemp -d \
451 ea2819be 2023-05-29 op "$GOT_TEST_ROOT/got-test-$testname-XXXXXXXXXX"`
452 e8863bdc 2020-07-23 stsp
453 02a5c5d0 2022-07-04 stsp gotadmin init $testroot/repo
454 e8863bdc 2020-07-23 stsp
455 e8863bdc 2020-07-23 stsp mkdir $testroot/tree
456 e8863bdc 2020-07-23 stsp echo 'this is file alpha' > $testroot/tree/alpha
457 e8863bdc 2020-07-23 stsp ln -s alpha $testroot/tree/alpha.link
458 e8863bdc 2020-07-23 stsp
459 e8863bdc 2020-07-23 stsp got import -m 'init' -r $testroot/repo $testroot/tree \
460 e8863bdc 2020-07-23 stsp > $testroot/stdout
461 49c543a6 2022-03-31 naddy ret=$?
462 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
463 e8863bdc 2020-07-23 stsp test_done "$testroot" "$ret"
464 e8863bdc 2020-07-23 stsp return 1
465 e8863bdc 2020-07-23 stsp fi
466 e8863bdc 2020-07-23 stsp
467 e8863bdc 2020-07-23 stsp local head_commit=`git_show_head $testroot/repo`
468 e8863bdc 2020-07-23 stsp echo "A $testroot/tree/alpha" > $testroot/stdout.expected
469 e8863bdc 2020-07-23 stsp echo "A $testroot/tree/alpha.link" >> $testroot/stdout.expected
470 e8863bdc 2020-07-23 stsp echo "Created branch refs/heads/main with commit $head_commit" \
471 e8863bdc 2020-07-23 stsp >> $testroot/stdout.expected
472 e8863bdc 2020-07-23 stsp
473 e8863bdc 2020-07-23 stsp cmp -s $testroot/stdout.expected $testroot/stdout
474 49c543a6 2022-03-31 naddy ret=$?
475 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
476 e8863bdc 2020-07-23 stsp diff -u $testroot/stdout.expected $testroot/stdout
477 e8863bdc 2020-07-23 stsp test_done "$testroot" "$ret"
478 e8863bdc 2020-07-23 stsp return 1
479 e8863bdc 2020-07-23 stsp fi
480 e8863bdc 2020-07-23 stsp
481 e8863bdc 2020-07-23 stsp id_alpha=`get_blob_id $testroot/repo "" alpha`
482 e8863bdc 2020-07-23 stsp id_alpha_link=$(got tree -r $testroot/repo -i | grep 'alpha.link@ -> alpha$' | cut -d' ' -f 1)
483 e8863bdc 2020-07-23 stsp tree_id=`(cd $testroot/repo && got cat $head_commit | \
484 e8863bdc 2020-07-23 stsp grep ^tree | cut -d ' ' -f 2)`
485 e8863bdc 2020-07-23 stsp
486 e8863bdc 2020-07-23 stsp got tree -i -r $testroot/repo -c $head_commit > $testroot/stdout
487 e8863bdc 2020-07-23 stsp
488 e8863bdc 2020-07-23 stsp echo "$id_alpha alpha" > $testroot/stdout.expected
489 e8863bdc 2020-07-23 stsp echo "$id_alpha_link alpha.link@ -> alpha" >> $testroot/stdout.expected
490 e8863bdc 2020-07-23 stsp
491 e8863bdc 2020-07-23 stsp cmp -s $testroot/stdout.expected $testroot/stdout
492 49c543a6 2022-03-31 naddy ret=$?
493 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
494 e8863bdc 2020-07-23 stsp diff -u $testroot/stdout.expected $testroot/stdout
495 e8863bdc 2020-07-23 stsp fi
496 e8863bdc 2020-07-23 stsp test_done "$testroot" "$ret"
497 e8863bdc 2020-07-23 stsp }
498 e8863bdc 2020-07-23 stsp
499 7fb414ae 2020-08-08 stsp test_parseargs "$@"
500 3ce1b845 2019-07-15 stsp run_test test_import_basic
501 6f04a73d 2022-09-20 mark run_test test_import_specified_head
502 6f04a73d 2022-09-20 mark run_test test_import_detached_head
503 3ce1b845 2019-07-15 stsp run_test test_import_requires_new_branch
504 3ce1b845 2019-07-15 stsp run_test test_import_ignores
505 db1d3576 2019-10-04 stsp run_test test_import_empty_dir
506 e8863bdc 2020-07-23 stsp run_test test_import_symlink