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