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