3 3ce1b845 2019-07-15 stsp # Copyright (c) 2019 Stefan Sperling <stsp@openbsd.org>
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.
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.
17 3ce1b845 2019-07-15 stsp . ./common.sh
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"`
23 3ce1b845 2019-07-15 stsp got init $testroot/repo
25 3ce1b845 2019-07-15 stsp mkdir $testroot/tree
26 3ce1b845 2019-07-15 stsp make_test_tree $testroot/tree
28 3ce1b845 2019-07-15 stsp got import -m 'init' -r $testroot/repo $testroot/tree \
29 3ce1b845 2019-07-15 stsp > $testroot/stdout
31 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
32 3ce1b845 2019-07-15 stsp test_done "$testroot" "$ret"
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
44 3ce1b845 2019-07-15 stsp cmp -s $testroot/stdout.expected $testroot/stdout
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"
52 3ce1b845 2019-07-15 stsp (cd $testroot/repo && got log -p | grep -v ^date: > $testroot/stdout)
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)`
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
97 3ce1b845 2019-07-15 stsp cmp -s $testroot/stdout.expected $testroot/stdout
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"
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
113 3ce1b845 2019-07-15 stsp got checkout $testroot/repo $testroot/wt > $testroot/stdout
115 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
116 3ce1b845 2019-07-15 stsp test_done "$testroot" "$ret"
120 3ce1b845 2019-07-15 stsp cmp -s $testroot/stdout.expected $testroot/stdout
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"
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
135 3ce1b845 2019-07-15 stsp cmp -s $testroot/content.expected $testroot/content
137 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
138 3ce1b845 2019-07-15 stsp diff -u $testroot/content.expected $testroot/content
140 3ce1b845 2019-07-15 stsp test_done "$testroot" "$ret"
143 f6cae3ed 2020-09-13 naddy test_import_requires_new_branch() {
144 3ce1b845 2019-07-15 stsp local testroot=`test_init import_requires_new_branch`
146 3ce1b845 2019-07-15 stsp mkdir $testroot/tree
147 3ce1b845 2019-07-15 stsp make_test_tree $testroot/tree
149 5d67f40d 2019-11-08 stsp got import -b master -m 'init' -r $testroot/repo $testroot/tree \
150 3ce1b845 2019-07-15 stsp > $testroot/stdout 2> $testroot/stderr
152 49c543a6 2022-03-31 naddy if [ $ret -eq 0 ]; then
153 3ce1b845 2019-07-15 stsp echo "import command should have failed but did not"
154 3ce1b845 2019-07-15 stsp test_done "$testroot" "1"
158 3ce1b845 2019-07-15 stsp echo "got: import target branch already exists" \
159 3ce1b845 2019-07-15 stsp > $testroot/stderr.expected
160 3ce1b845 2019-07-15 stsp cmp -s $testroot/stderr.expected $testroot/stderr
162 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
163 3ce1b845 2019-07-15 stsp diff -u $testroot/stderr.expected $testroot/stderr
164 3ce1b845 2019-07-15 stsp test_done "$testroot" "$ret"
168 3ce1b845 2019-07-15 stsp got import -b newbranch -m 'init' -r $testroot/repo $testroot/tree \
169 3ce1b845 2019-07-15 stsp > $testroot/stdout
171 3ce1b845 2019-07-15 stsp test_done "$testroot" "$ret"
175 f6cae3ed 2020-09-13 naddy test_import_ignores() {
176 71db5e8c 2019-08-08 stsp local testname=import_ignores
177 743f0d3e 2020-10-01 stsp local testroot=`mktemp -d "$GOT_TEST_ROOT/got-test-$testname-XXXXXXXX"`
179 3ce1b845 2019-07-15 stsp got init $testroot/repo
181 3ce1b845 2019-07-15 stsp mkdir $testroot/tree
182 3ce1b845 2019-07-15 stsp make_test_tree $testroot/tree
184 3ce1b845 2019-07-15 stsp got import -I alpha -I '*lta*' -I '*silon' \
185 3ce1b845 2019-07-15 stsp -m 'init' -r $testroot/repo $testroot/tree > $testroot/stdout
187 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
188 3ce1b845 2019-07-15 stsp test_done "$testroot" "$ret"
192 3ce1b845 2019-07-15 stsp local head_commit=`git_show_head $testroot/repo`
193 3ce1b845 2019-07-15 stsp echo "A $testroot/tree/beta" >> $testroot/stdout.expected
194 5d67f40d 2019-11-08 stsp echo "Created branch refs/heads/main with commit $head_commit" \
195 3ce1b845 2019-07-15 stsp >> $testroot/stdout.expected
197 3ce1b845 2019-07-15 stsp cmp -s $testroot/stdout.expected $testroot/stdout
199 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
200 3ce1b845 2019-07-15 stsp diff -u $testroot/stdout.expected $testroot/stdout
202 3ce1b845 2019-07-15 stsp test_done "$testroot" "$ret"
205 f6cae3ed 2020-09-13 naddy test_import_empty_dir() {
206 db1d3576 2019-10-04 stsp local testname=import_empty_dir
207 743f0d3e 2020-10-01 stsp local testroot=`mktemp -d "$GOT_TEST_ROOT/got-test-$testname-XXXXXXXX"`
209 db1d3576 2019-10-04 stsp got init $testroot/repo
211 db1d3576 2019-10-04 stsp mkdir $testroot/tree
212 db1d3576 2019-10-04 stsp mkdir -p $testroot/tree/empty $testroot/tree/notempty
213 db1d3576 2019-10-04 stsp echo "alpha" > $testroot/tree/notempty/alpha
215 db1d3576 2019-10-04 stsp got import -m 'init' -r $testroot/repo $testroot/tree > $testroot/stdout
217 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
218 db1d3576 2019-10-04 stsp test_done "$testroot" "$ret"
222 db1d3576 2019-10-04 stsp local head_commit=`git_show_head $testroot/repo`
223 db1d3576 2019-10-04 stsp echo "A $testroot/tree/notempty/alpha" >> $testroot/stdout.expected
224 5d67f40d 2019-11-08 stsp echo "Created branch refs/heads/main with commit $head_commit" \
225 db1d3576 2019-10-04 stsp >> $testroot/stdout.expected
227 db1d3576 2019-10-04 stsp cmp -s $testroot/stdout.expected $testroot/stdout
229 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
230 db1d3576 2019-10-04 stsp diff -u $testroot/stdout.expected $testroot/stdout
231 db1d3576 2019-10-04 stsp test_done "$testroot" "$ret"
235 db1d3576 2019-10-04 stsp # Verify that Got did not import the empty directory
236 db1d3576 2019-10-04 stsp echo "notempty/" > $testroot/stdout.expected
237 db1d3576 2019-10-04 stsp echo "notempty/alpha" >> $testroot/stdout.expected
239 db1d3576 2019-10-04 stsp got tree -r $testroot/repo -R > $testroot/stdout
240 db1d3576 2019-10-04 stsp cmp -s $testroot/stdout.expected $testroot/stdout
242 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
243 db1d3576 2019-10-04 stsp diff -u $testroot/stdout.expected $testroot/stdout
245 db1d3576 2019-10-04 stsp test_done "$testroot" "$ret"
248 f6cae3ed 2020-09-13 naddy test_import_symlink() {
249 e8863bdc 2020-07-23 stsp local testname=import_symlink
250 743f0d3e 2020-10-01 stsp local testroot=`mktemp -d "$GOT_TEST_ROOT/got-test-$testname-XXXXXXXX"`
252 e8863bdc 2020-07-23 stsp got init $testroot/repo
254 e8863bdc 2020-07-23 stsp mkdir $testroot/tree
255 e8863bdc 2020-07-23 stsp echo 'this is file alpha' > $testroot/tree/alpha
256 e8863bdc 2020-07-23 stsp ln -s alpha $testroot/tree/alpha.link
258 e8863bdc 2020-07-23 stsp got import -m 'init' -r $testroot/repo $testroot/tree \
259 e8863bdc 2020-07-23 stsp > $testroot/stdout
261 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
262 e8863bdc 2020-07-23 stsp test_done "$testroot" "$ret"
266 e8863bdc 2020-07-23 stsp local head_commit=`git_show_head $testroot/repo`
267 e8863bdc 2020-07-23 stsp echo "A $testroot/tree/alpha" > $testroot/stdout.expected
268 e8863bdc 2020-07-23 stsp echo "A $testroot/tree/alpha.link" >> $testroot/stdout.expected
269 e8863bdc 2020-07-23 stsp echo "Created branch refs/heads/main with commit $head_commit" \
270 e8863bdc 2020-07-23 stsp >> $testroot/stdout.expected
272 e8863bdc 2020-07-23 stsp cmp -s $testroot/stdout.expected $testroot/stdout
274 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
275 e8863bdc 2020-07-23 stsp diff -u $testroot/stdout.expected $testroot/stdout
276 e8863bdc 2020-07-23 stsp test_done "$testroot" "$ret"
280 e8863bdc 2020-07-23 stsp id_alpha=`get_blob_id $testroot/repo "" alpha`
281 e8863bdc 2020-07-23 stsp id_alpha_link=$(got tree -r $testroot/repo -i | grep 'alpha.link@ -> alpha$' | cut -d' ' -f 1)
282 e8863bdc 2020-07-23 stsp tree_id=`(cd $testroot/repo && got cat $head_commit | \
283 e8863bdc 2020-07-23 stsp grep ^tree | cut -d ' ' -f 2)`
285 e8863bdc 2020-07-23 stsp got tree -i -r $testroot/repo -c $head_commit > $testroot/stdout
287 e8863bdc 2020-07-23 stsp echo "$id_alpha alpha" > $testroot/stdout.expected
288 e8863bdc 2020-07-23 stsp echo "$id_alpha_link alpha.link@ -> alpha" >> $testroot/stdout.expected
290 e8863bdc 2020-07-23 stsp cmp -s $testroot/stdout.expected $testroot/stdout
292 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
293 e8863bdc 2020-07-23 stsp diff -u $testroot/stdout.expected $testroot/stdout
295 e8863bdc 2020-07-23 stsp test_done "$testroot" "$ret"
298 7fb414ae 2020-08-08 stsp test_parseargs "$@"
299 3ce1b845 2019-07-15 stsp run_test test_import_basic
300 3ce1b845 2019-07-15 stsp run_test test_import_requires_new_branch
301 3ce1b845 2019-07-15 stsp run_test test_import_ignores
302 db1d3576 2019-10-04 stsp run_test test_import_empty_dir
303 e8863bdc 2020-07-23 stsp run_test test_import_symlink