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 d6e78555 2023-06-01 thomas local testroot=`mktemp -d \
22 d6e78555 2023-06-01 thomas "$GOT_TEST_ROOT/got-test-$testname-XXXXXXXXXX"`
23 3ce1b845 2019-07-15 stsp
24 27b10c3c 2022-07-04 thomas 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 fc414659 2022-04-16 thomas ret=$?
32 fc414659 2022-04-16 thomas 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 fc414659 2022-04-16 thomas ret=$?
47 fc414659 2022-04-16 thomas 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 9b4458b4 2022-06-26 thomas echo "diff /dev/null $head_commit" >> $testroot/stdout.expected
70 9b4458b4 2022-06-26 thomas echo "commit - /dev/null" >> $testroot/stdout.expected
71 9b4458b4 2022-06-26 thomas 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 fc414659 2022-04-16 thomas ret=$?
100 fc414659 2022-04-16 thomas 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 fc414659 2022-04-16 thomas ret=$?
116 fc414659 2022-04-16 thomas 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 fc414659 2022-04-16 thomas ret=$?
123 fc414659 2022-04-16 thomas 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 fc414659 2022-04-16 thomas ret=$?
138 fc414659 2022-04-16 thomas 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 e9424ba1 2022-09-20 thomas test_import_specified_head() {
145 e9424ba1 2022-09-20 thomas local testname=import_specified_head
146 d6e78555 2023-06-01 thomas local testroot=`mktemp -d \
147 d6e78555 2023-06-01 thomas "$GOT_TEST_ROOT/got-test-$testname-XXXXXXXXXX"`
148 e9424ba1 2022-09-20 thomas local headref=trunk
149 e9424ba1 2022-09-20 thomas
150 e9424ba1 2022-09-20 thomas gotadmin init -b $headref $testroot/repo
151 e9424ba1 2022-09-20 thomas
152 e9424ba1 2022-09-20 thomas mkdir $testroot/tree
153 e9424ba1 2022-09-20 thomas make_test_tree $testroot/tree
154 e9424ba1 2022-09-20 thomas
155 e9424ba1 2022-09-20 thomas got import -m init -r $testroot/repo $testroot/tree > $testroot/stdout
156 e9424ba1 2022-09-20 thomas ret=$?
157 e9424ba1 2022-09-20 thomas if [ $ret -ne 0 ]; then
158 e9424ba1 2022-09-20 thomas test_done "$testroot" "$ret"
159 e9424ba1 2022-09-20 thomas return 1
160 e9424ba1 2022-09-20 thomas fi
161 e9424ba1 2022-09-20 thomas
162 e9424ba1 2022-09-20 thomas local head_commit=`git_show_head $testroot/repo`
163 e9424ba1 2022-09-20 thomas echo "A $testroot/tree/gamma/delta" > $testroot/stdout.expected
164 e9424ba1 2022-09-20 thomas echo "A $testroot/tree/epsilon/zeta" >> $testroot/stdout.expected
165 e9424ba1 2022-09-20 thomas echo "A $testroot/tree/alpha" >> $testroot/stdout.expected
166 e9424ba1 2022-09-20 thomas echo "A $testroot/tree/beta" >> $testroot/stdout.expected
167 e9424ba1 2022-09-20 thomas echo "Created branch refs/heads/$headref with commit $head_commit" \
168 e9424ba1 2022-09-20 thomas >> $testroot/stdout.expected
169 e9424ba1 2022-09-20 thomas
170 e9424ba1 2022-09-20 thomas cmp -s $testroot/stdout.expected $testroot/stdout
171 e9424ba1 2022-09-20 thomas ret=$?
172 e9424ba1 2022-09-20 thomas if [ $ret -ne 0 ]; then
173 e9424ba1 2022-09-20 thomas echo "fail"
174 e9424ba1 2022-09-20 thomas diff -u $testroot/stdout.expected $testroot/stdout
175 e9424ba1 2022-09-20 thomas test_done "$testroot" "$ret"
176 e9424ba1 2022-09-20 thomas return 1
177 e9424ba1 2022-09-20 thomas fi
178 e9424ba1 2022-09-20 thomas
179 e9424ba1 2022-09-20 thomas (cd $testroot/repo && got log -p | grep -v ^date: > $testroot/stdout)
180 e9424ba1 2022-09-20 thomas
181 e9424ba1 2022-09-20 thomas id_alpha=`get_blob_id $testroot/repo "" alpha`
182 e9424ba1 2022-09-20 thomas id_beta=`get_blob_id $testroot/repo "" beta`
183 e9424ba1 2022-09-20 thomas id_zeta=`get_blob_id $testroot/repo epsilon zeta`
184 e9424ba1 2022-09-20 thomas id_delta=`get_blob_id $testroot/repo gamma delta`
185 e9424ba1 2022-09-20 thomas tree_id=`(cd $testroot/repo && got cat $head_commit | \
186 e9424ba1 2022-09-20 thomas grep ^tree | cut -d ' ' -f 2)`
187 e9424ba1 2022-09-20 thomas
188 e9424ba1 2022-09-20 thomas echo "-----------------------------------------------" \
189 e9424ba1 2022-09-20 thomas > $testroot/stdout.expected
190 e9424ba1 2022-09-20 thomas echo "commit $head_commit ($headref)" >> $testroot/stdout.expected
191 e9424ba1 2022-09-20 thomas echo "from: $GOT_AUTHOR" >> $testroot/stdout.expected
192 e9424ba1 2022-09-20 thomas echo " " >> $testroot/stdout.expected
193 e9424ba1 2022-09-20 thomas echo " init" >> $testroot/stdout.expected
194 e9424ba1 2022-09-20 thomas echo " " >> $testroot/stdout.expected
195 e9424ba1 2022-09-20 thomas echo "diff /dev/null $head_commit" >> $testroot/stdout.expected
196 e9424ba1 2022-09-20 thomas echo "commit - /dev/null" >> $testroot/stdout.expected
197 e9424ba1 2022-09-20 thomas echo "commit + $head_commit" >> $testroot/stdout.expected
198 e9424ba1 2022-09-20 thomas echo "blob - /dev/null" >> $testroot/stdout.expected
199 e9424ba1 2022-09-20 thomas echo "blob + $id_alpha (mode 644)" >> $testroot/stdout.expected
200 e9424ba1 2022-09-20 thomas echo "--- /dev/null" >> $testroot/stdout.expected
201 e9424ba1 2022-09-20 thomas echo "+++ alpha" >> $testroot/stdout.expected
202 e9424ba1 2022-09-20 thomas echo "@@ -0,0 +1 @@" >> $testroot/stdout.expected
203 e9424ba1 2022-09-20 thomas echo "+alpha" >> $testroot/stdout.expected
204 e9424ba1 2022-09-20 thomas echo "blob - /dev/null" >> $testroot/stdout.expected
205 e9424ba1 2022-09-20 thomas echo "blob + $id_beta (mode 644)" >> $testroot/stdout.expected
206 e9424ba1 2022-09-20 thomas echo "--- /dev/null" >> $testroot/stdout.expected
207 e9424ba1 2022-09-20 thomas echo "+++ beta" >> $testroot/stdout.expected
208 e9424ba1 2022-09-20 thomas echo "@@ -0,0 +1 @@" >> $testroot/stdout.expected
209 e9424ba1 2022-09-20 thomas echo "+beta" >> $testroot/stdout.expected
210 e9424ba1 2022-09-20 thomas echo "blob - /dev/null" >> $testroot/stdout.expected
211 e9424ba1 2022-09-20 thomas echo "blob + $id_zeta (mode 644)" >> $testroot/stdout.expected
212 e9424ba1 2022-09-20 thomas echo "--- /dev/null" >> $testroot/stdout.expected
213 e9424ba1 2022-09-20 thomas echo "+++ epsilon/zeta" >> $testroot/stdout.expected
214 e9424ba1 2022-09-20 thomas echo "@@ -0,0 +1 @@" >> $testroot/stdout.expected
215 e9424ba1 2022-09-20 thomas echo "+zeta" >> $testroot/stdout.expected
216 e9424ba1 2022-09-20 thomas echo "blob - /dev/null" >> $testroot/stdout.expected
217 e9424ba1 2022-09-20 thomas echo "blob + $id_delta (mode 644)" >> $testroot/stdout.expected
218 e9424ba1 2022-09-20 thomas echo "--- /dev/null" >> $testroot/stdout.expected
219 e9424ba1 2022-09-20 thomas echo "+++ gamma/delta" >> $testroot/stdout.expected
220 e9424ba1 2022-09-20 thomas echo "@@ -0,0 +1 @@" >> $testroot/stdout.expected
221 e9424ba1 2022-09-20 thomas echo "+delta" >> $testroot/stdout.expected
222 e9424ba1 2022-09-20 thomas echo "" >> $testroot/stdout.expected
223 e9424ba1 2022-09-20 thomas
224 e9424ba1 2022-09-20 thomas cmp -s $testroot/stdout.expected $testroot/stdout
225 e9424ba1 2022-09-20 thomas ret=$?
226 e9424ba1 2022-09-20 thomas if [ $ret -ne 0 ]; then
227 e9424ba1 2022-09-20 thomas echo "fail"
228 e9424ba1 2022-09-20 thomas diff -u $testroot/stdout.expected $testroot/stdout
229 e9424ba1 2022-09-20 thomas test_done "$testroot" "$ret"
230 e9424ba1 2022-09-20 thomas return 1
231 e9424ba1 2022-09-20 thomas fi
232 e9424ba1 2022-09-20 thomas
233 e9424ba1 2022-09-20 thomas echo "A $testroot/wt/alpha" > $testroot/stdout.expected
234 e9424ba1 2022-09-20 thomas echo "A $testroot/wt/beta" >> $testroot/stdout.expected
235 e9424ba1 2022-09-20 thomas echo "A $testroot/wt/epsilon/zeta" >> $testroot/stdout.expected
236 e9424ba1 2022-09-20 thomas echo "A $testroot/wt/gamma/delta" >> $testroot/stdout.expected
237 e9424ba1 2022-09-20 thomas echo "Checked out refs/heads/$headref: $head_commit" \
238 e9424ba1 2022-09-20 thomas >> $testroot/stdout.expected
239 e9424ba1 2022-09-20 thomas echo "Now shut up and hack" >> $testroot/stdout.expected
240 e9424ba1 2022-09-20 thomas
241 e9424ba1 2022-09-20 thomas got checkout $testroot/repo $testroot/wt > $testroot/stdout
242 e9424ba1 2022-09-20 thomas cmp -s $testroot/stdout.expected $testroot/stdout
243 e9424ba1 2022-09-20 thomas ret=$?
244 e9424ba1 2022-09-20 thomas if [ $ret -ne 0 ]; then
245 e9424ba1 2022-09-20 thomas echo "fail"
246 e9424ba1 2022-09-20 thomas diff -u $testroot/stdout.expected $testroot/stdout
247 e9424ba1 2022-09-20 thomas test_done "$testroot" "$ret"
248 e9424ba1 2022-09-20 thomas return 1
249 e9424ba1 2022-09-20 thomas fi
250 e9424ba1 2022-09-20 thomas
251 e9424ba1 2022-09-20 thomas cmp -s $testroot/stdout.expected $testroot/stdout
252 e9424ba1 2022-09-20 thomas ret=$?
253 e9424ba1 2022-09-20 thomas if [ $ret -ne 0 ]; then
254 e9424ba1 2022-09-20 thomas echo "fail"
255 e9424ba1 2022-09-20 thomas diff -u $testroot/stdout.expected $testroot/stdout
256 e9424ba1 2022-09-20 thomas test_done "$testroot" "$ret"
257 e9424ba1 2022-09-20 thomas return 1
258 e9424ba1 2022-09-20 thomas fi
259 e9424ba1 2022-09-20 thomas
260 e9424ba1 2022-09-20 thomas echo "alpha" > $testroot/content.expected
261 e9424ba1 2022-09-20 thomas echo "beta" >> $testroot/content.expected
262 e9424ba1 2022-09-20 thomas echo "zeta" >> $testroot/content.expected
263 e9424ba1 2022-09-20 thomas echo "delta" >> $testroot/content.expected
264 e9424ba1 2022-09-20 thomas cat $testroot/wt/alpha $testroot/wt/beta $testroot/wt/epsilon/zeta \
265 e9424ba1 2022-09-20 thomas $testroot/wt/gamma/delta > $testroot/content
266 e9424ba1 2022-09-20 thomas
267 e9424ba1 2022-09-20 thomas cmp -s $testroot/content.expected $testroot/content
268 e9424ba1 2022-09-20 thomas ret=$?
269 e9424ba1 2022-09-20 thomas if [ $ret -ne 0 ]; then
270 e9424ba1 2022-09-20 thomas echo "fail"
271 e9424ba1 2022-09-20 thomas diff -u $testroot/content.expected $testroot/content
272 e9424ba1 2022-09-20 thomas fi
273 e9424ba1 2022-09-20 thomas test_done "$testroot" "$ret"
274 e9424ba1 2022-09-20 thomas }
275 e9424ba1 2022-09-20 thomas
276 e9424ba1 2022-09-20 thomas test_import_detached_head() {
277 e9424ba1 2022-09-20 thomas local testroot=`test_init import_detached_head`
278 e9424ba1 2022-09-20 thomas
279 e9424ba1 2022-09-20 thomas # mute verbose 'detached HEAD' warning
280 d1e03b8c 2023-10-08 thomas git -C $testroot/repo config --local advice.detachedHead false
281 e9424ba1 2022-09-20 thomas ret=$?
282 e9424ba1 2022-09-20 thomas if [ $ret -ne 0 ]; then
283 e9424ba1 2022-09-20 thomas test_done "$testroot" "$ret"
284 e9424ba1 2022-09-20 thomas return 1
285 e9424ba1 2022-09-20 thomas fi
286 e9424ba1 2022-09-20 thomas
287 e9424ba1 2022-09-20 thomas # enter detached HEAD state
288 e9424ba1 2022-09-20 thomas local head_commit=`git_show_head $testroot/repo | cut -c1-7`
289 d1e03b8c 2023-10-08 thomas git -C $testroot/repo checkout $head_commit \
290 d1e03b8c 2023-10-08 thomas > $testroot/stdout 2> $testroot/stderr
291 e9424ba1 2022-09-20 thomas ret=$?
292 e9424ba1 2022-09-20 thomas if [ $ret -ne 0 ]; then
293 e9424ba1 2022-09-20 thomas test_done "$testroot" "$ret"
294 e9424ba1 2022-09-20 thomas return 1
295 e9424ba1 2022-09-20 thomas fi
296 e9424ba1 2022-09-20 thomas
297 e9424ba1 2022-09-20 thomas echo "HEAD is now at $head_commit adding the test tree" >> \
298 e9424ba1 2022-09-20 thomas $testroot/stderr.expected
299 e9424ba1 2022-09-20 thomas
300 e9424ba1 2022-09-20 thomas cmp -s $testroot/stderr.expected $testroot/stderr
301 e9424ba1 2022-09-20 thomas ret=$?
302 e9424ba1 2022-09-20 thomas if [ $ret -ne 0 ]; then
303 e9424ba1 2022-09-20 thomas echo "fail"
304 e9424ba1 2022-09-20 thomas diff -u $testroot/stderr.expected $testroot/stderr
305 e9424ba1 2022-09-20 thomas test_done "$testroot" "$ret"
306 e9424ba1 2022-09-20 thomas return 1
307 e9424ba1 2022-09-20 thomas fi
308 e9424ba1 2022-09-20 thomas
309 e9424ba1 2022-09-20 thomas mkdir $testroot/import
310 e9424ba1 2022-09-20 thomas make_test_tree $testroot/import
311 e9424ba1 2022-09-20 thomas
312 e9424ba1 2022-09-20 thomas # detached HEAD (i.e., not symbolic) so import should fallback to "main"
313 e9424ba1 2022-09-20 thomas got import -r $testroot/repo -m init $testroot/import > $testroot/stdout
314 e9424ba1 2022-09-20 thomas ret=$?
315 e9424ba1 2022-09-20 thomas if [ $ret -ne 0 ]; then
316 e9424ba1 2022-09-20 thomas test_done "$testroot" "$ret"
317 e9424ba1 2022-09-20 thomas return 1
318 e9424ba1 2022-09-20 thomas fi
319 e9424ba1 2022-09-20 thomas
320 d1e03b8c 2023-10-08 thomas local main_commit=`git -C $testroot/repo show-ref main | \
321 d1e03b8c 2023-10-08 thomas cut -d ' ' -f 1`
322 e9424ba1 2022-09-20 thomas echo "A $testroot/import/gamma/delta" > $testroot/stdout.expected
323 e9424ba1 2022-09-20 thomas echo "A $testroot/import/epsilon/zeta" >> $testroot/stdout.expected
324 e9424ba1 2022-09-20 thomas echo "A $testroot/import/alpha" >> $testroot/stdout.expected
325 e9424ba1 2022-09-20 thomas echo "A $testroot/import/beta" >> $testroot/stdout.expected
326 e9424ba1 2022-09-20 thomas echo "Created branch refs/heads/main with commit $main_commit" \
327 e9424ba1 2022-09-20 thomas >> $testroot/stdout.expected
328 e9424ba1 2022-09-20 thomas
329 e9424ba1 2022-09-20 thomas cmp -s $testroot/stdout.expected $testroot/stdout
330 e9424ba1 2022-09-20 thomas ret=$?
331 e9424ba1 2022-09-20 thomas if [ $ret -ne 0 ]; then
332 e9424ba1 2022-09-20 thomas echo "fail"
333 e9424ba1 2022-09-20 thomas diff -u $testroot/stdout.expected $testroot/stdout
334 e9424ba1 2022-09-20 thomas fi
335 e9424ba1 2022-09-20 thomas test_done "$testroot" "$ret"
336 e9424ba1 2022-09-20 thomas }
337 e9424ba1 2022-09-20 thomas
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 fc414659 2022-04-16 thomas ret=$?
347 fc414659 2022-04-16 thomas 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 fc414659 2022-04-16 thomas ret=$?
357 fc414659 2022-04-16 thomas 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 fc414659 2022-04-16 thomas 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 d6e78555 2023-06-01 thomas local testroot=`mktemp -d \
373 d6e78555 2023-06-01 thomas "$GOT_TEST_ROOT/got-test-$testname-XXXXXXXXXX"`
374 3ce1b845 2019-07-15 stsp
375 27b10c3c 2022-07-04 thomas 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 5d6fee73 2023-02-20 thomas touch $testroot/tree/upsilon
381 5d6fee73 2023-02-20 thomas mkdir $testroot/tree/ysilon
382 e012cf94 2023-02-07 thomas 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 fc414659 2022-04-16 thomas ret=$?
385 fc414659 2022-04-16 thomas 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 5d6fee73 2023-02-20 thomas 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 fc414659 2022-04-16 thomas ret=$?
398 fc414659 2022-04-16 thomas 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 d6e78555 2023-06-01 thomas local testroot=`mktemp -d \
407 d6e78555 2023-06-01 thomas "$GOT_TEST_ROOT/got-test-$testname-XXXXXXXXXX"`
408 3ce1b845 2019-07-15 stsp
409 27b10c3c 2022-07-04 thomas 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 fc414659 2022-04-16 thomas ret=$?
417 fc414659 2022-04-16 thomas 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 fc414659 2022-04-16 thomas ret=$?
429 fc414659 2022-04-16 thomas 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 fc414659 2022-04-16 thomas ret=$?
442 fc414659 2022-04-16 thomas 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 d6e78555 2023-06-01 thomas local testroot=`mktemp -d \
451 d6e78555 2023-06-01 thomas "$GOT_TEST_ROOT/got-test-$testname-XXXXXXXXXX"`
452 e8863bdc 2020-07-23 stsp
453 27b10c3c 2022-07-04 thomas 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 fc414659 2022-04-16 thomas ret=$?
462 fc414659 2022-04-16 thomas 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 fc414659 2022-04-16 thomas ret=$?
475 fc414659 2022-04-16 thomas 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 fc414659 2022-04-16 thomas ret=$?
493 fc414659 2022-04-16 thomas 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 e9424ba1 2022-09-20 thomas run_test test_import_specified_head
502 e9424ba1 2022-09-20 thomas 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