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 3ce1b845 2019-07-15 stsp function test_import_basic {
20 71db5e8c 2019-08-08 stsp local testname=import_basic
21 3ce1b845 2019-07-15 stsp local testroot=`mktemp -p /tmp -d got-test-$testname-XXXXXXXX`
22 3ce1b845 2019-07-15 stsp
23 3ce1b845 2019-07-15 stsp got 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 3ce1b845 2019-07-15 stsp ret="$?"
31 3ce1b845 2019-07-15 stsp if [ "$ret" != "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 3ce1b845 2019-07-15 stsp echo "Created branch refs/heads/master 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 3ce1b845 2019-07-15 stsp ret="$?"
46 3ce1b845 2019-07-15 stsp if [ "$ret" != "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 3ce1b845 2019-07-15 stsp
59 3ce1b845 2019-07-15 stsp echo "-----------------------------------------------" \
60 3ce1b845 2019-07-15 stsp > $testroot/stdout.expected
61 3ce1b845 2019-07-15 stsp echo "commit $head_commit (master)" >> $testroot/stdout.expected
62 3ce1b845 2019-07-15 stsp echo "from: $GOT_AUTHOR" >> $testroot/stdout.expected
63 3ce1b845 2019-07-15 stsp echo " " >> $testroot/stdout.expected
64 3ce1b845 2019-07-15 stsp echo " init" >> $testroot/stdout.expected
65 3ce1b845 2019-07-15 stsp echo " " >> $testroot/stdout.expected
66 3ce1b845 2019-07-15 stsp echo "diff /dev/null $head_commit" >> $testroot/stdout.expected
67 3ce1b845 2019-07-15 stsp echo "blob - /dev/null" >> $testroot/stdout.expected
68 3ce1b845 2019-07-15 stsp echo "blob + $id_alpha" >> $testroot/stdout.expected
69 3ce1b845 2019-07-15 stsp echo "--- /dev/null" >> $testroot/stdout.expected
70 3ce1b845 2019-07-15 stsp echo "+++ alpha" >> $testroot/stdout.expected
71 3ce1b845 2019-07-15 stsp echo "@@ -0,0 +1 @@" >> $testroot/stdout.expected
72 3ce1b845 2019-07-15 stsp echo "+alpha" >> $testroot/stdout.expected
73 3ce1b845 2019-07-15 stsp echo "blob - /dev/null" >> $testroot/stdout.expected
74 3ce1b845 2019-07-15 stsp echo "blob + $id_beta" >> $testroot/stdout.expected
75 3ce1b845 2019-07-15 stsp echo "--- /dev/null" >> $testroot/stdout.expected
76 3ce1b845 2019-07-15 stsp echo "+++ beta" >> $testroot/stdout.expected
77 3ce1b845 2019-07-15 stsp echo "@@ -0,0 +1 @@" >> $testroot/stdout.expected
78 3ce1b845 2019-07-15 stsp echo "+beta" >> $testroot/stdout.expected
79 3ce1b845 2019-07-15 stsp echo "blob - /dev/null" >> $testroot/stdout.expected
80 3ce1b845 2019-07-15 stsp echo "blob + $id_zeta" >> $testroot/stdout.expected
81 3ce1b845 2019-07-15 stsp echo "--- /dev/null" >> $testroot/stdout.expected
82 3ce1b845 2019-07-15 stsp echo "+++ epsilon/zeta" >> $testroot/stdout.expected
83 3ce1b845 2019-07-15 stsp echo "@@ -0,0 +1 @@" >> $testroot/stdout.expected
84 3ce1b845 2019-07-15 stsp echo "+zeta" >> $testroot/stdout.expected
85 3ce1b845 2019-07-15 stsp echo "blob - /dev/null" >> $testroot/stdout.expected
86 3ce1b845 2019-07-15 stsp echo "blob + $id_delta" >> $testroot/stdout.expected
87 3ce1b845 2019-07-15 stsp echo "--- /dev/null" >> $testroot/stdout.expected
88 3ce1b845 2019-07-15 stsp echo "+++ gamma/delta" >> $testroot/stdout.expected
89 3ce1b845 2019-07-15 stsp echo "@@ -0,0 +1 @@" >> $testroot/stdout.expected
90 3ce1b845 2019-07-15 stsp echo "+delta" >> $testroot/stdout.expected
91 3ce1b845 2019-07-15 stsp echo "" >> $testroot/stdout.expected
92 3ce1b845 2019-07-15 stsp
93 3ce1b845 2019-07-15 stsp cmp -s $testroot/stdout.expected $testroot/stdout
94 3ce1b845 2019-07-15 stsp ret="$?"
95 3ce1b845 2019-07-15 stsp if [ "$ret" != "0" ]; then
96 3ce1b845 2019-07-15 stsp diff -u $testroot/stdout.expected $testroot/stdout
97 3ce1b845 2019-07-15 stsp test_done "$testroot" "$ret"
98 3ce1b845 2019-07-15 stsp return 1
99 3ce1b845 2019-07-15 stsp fi
100 3ce1b845 2019-07-15 stsp
101 3ce1b845 2019-07-15 stsp echo "A $testroot/wt/alpha" > $testroot/stdout.expected
102 3ce1b845 2019-07-15 stsp echo "A $testroot/wt/beta" >> $testroot/stdout.expected
103 3ce1b845 2019-07-15 stsp echo "A $testroot/wt/epsilon/zeta" >> $testroot/stdout.expected
104 3ce1b845 2019-07-15 stsp echo "A $testroot/wt/gamma/delta" >> $testroot/stdout.expected
105 3ce1b845 2019-07-15 stsp echo "Now shut up and hack" >> $testroot/stdout.expected
106 3ce1b845 2019-07-15 stsp
107 3ce1b845 2019-07-15 stsp got checkout $testroot/repo $testroot/wt > $testroot/stdout
108 3ce1b845 2019-07-15 stsp ret="$?"
109 3ce1b845 2019-07-15 stsp if [ "$ret" != "0" ]; then
110 3ce1b845 2019-07-15 stsp test_done "$testroot" "$ret"
111 3ce1b845 2019-07-15 stsp return 1
112 3ce1b845 2019-07-15 stsp fi
113 3ce1b845 2019-07-15 stsp
114 3ce1b845 2019-07-15 stsp cmp -s $testroot/stdout.expected $testroot/stdout
115 3ce1b845 2019-07-15 stsp ret="$?"
116 3ce1b845 2019-07-15 stsp if [ "$ret" != "0" ]; then
117 3ce1b845 2019-07-15 stsp diff -u $testroot/stdout.expected $testroot/stdout
118 3ce1b845 2019-07-15 stsp test_done "$testroot" "$ret"
119 3ce1b845 2019-07-15 stsp return 1
120 3ce1b845 2019-07-15 stsp fi
121 3ce1b845 2019-07-15 stsp
122 3ce1b845 2019-07-15 stsp echo "alpha" > $testroot/content.expected
123 3ce1b845 2019-07-15 stsp echo "beta" >> $testroot/content.expected
124 3ce1b845 2019-07-15 stsp echo "zeta" >> $testroot/content.expected
125 3ce1b845 2019-07-15 stsp echo "delta" >> $testroot/content.expected
126 3ce1b845 2019-07-15 stsp cat $testroot/wt/alpha $testroot/wt/beta $testroot/wt/epsilon/zeta \
127 3ce1b845 2019-07-15 stsp $testroot/wt/gamma/delta > $testroot/content
128 3ce1b845 2019-07-15 stsp
129 3ce1b845 2019-07-15 stsp cmp -s $testroot/content.expected $testroot/content
130 3ce1b845 2019-07-15 stsp ret="$?"
131 3ce1b845 2019-07-15 stsp if [ "$ret" != "0" ]; then
132 3ce1b845 2019-07-15 stsp diff -u $testroot/content.expected $testroot/content
133 3ce1b845 2019-07-15 stsp fi
134 3ce1b845 2019-07-15 stsp test_done "$testroot" "$ret"
135 3ce1b845 2019-07-15 stsp }
136 3ce1b845 2019-07-15 stsp
137 3ce1b845 2019-07-15 stsp function test_import_requires_new_branch {
138 3ce1b845 2019-07-15 stsp local testroot=`test_init import_requires_new_branch`
139 3ce1b845 2019-07-15 stsp
140 3ce1b845 2019-07-15 stsp mkdir $testroot/tree
141 3ce1b845 2019-07-15 stsp make_test_tree $testroot/tree
142 3ce1b845 2019-07-15 stsp
143 3ce1b845 2019-07-15 stsp got import -m 'init' -r $testroot/repo $testroot/tree \
144 3ce1b845 2019-07-15 stsp > $testroot/stdout 2> $testroot/stderr
145 3ce1b845 2019-07-15 stsp ret="$?"
146 3ce1b845 2019-07-15 stsp if [ "$ret" == "0" ]; then
147 3ce1b845 2019-07-15 stsp echo "import command should have failed but did not"
148 3ce1b845 2019-07-15 stsp test_done "$testroot" "1"
149 3ce1b845 2019-07-15 stsp return 1
150 3ce1b845 2019-07-15 stsp fi
151 3ce1b845 2019-07-15 stsp
152 3ce1b845 2019-07-15 stsp echo "got: import target branch already exists" \
153 3ce1b845 2019-07-15 stsp > $testroot/stderr.expected
154 3ce1b845 2019-07-15 stsp cmp -s $testroot/stderr.expected $testroot/stderr
155 3ce1b845 2019-07-15 stsp ret="$?"
156 3ce1b845 2019-07-15 stsp if [ "$ret" != "0" ]; then
157 3ce1b845 2019-07-15 stsp diff -u $testroot/stderr.expected $testroot/stderr
158 3ce1b845 2019-07-15 stsp test_done "$testroot" "$ret"
159 3ce1b845 2019-07-15 stsp return 1
160 3ce1b845 2019-07-15 stsp fi
161 3ce1b845 2019-07-15 stsp
162 3ce1b845 2019-07-15 stsp got import -b newbranch -m 'init' -r $testroot/repo $testroot/tree \
163 3ce1b845 2019-07-15 stsp > $testroot/stdout
164 3ce1b845 2019-07-15 stsp ret="$?"
165 3ce1b845 2019-07-15 stsp test_done "$testroot" "$ret"
166 3ce1b845 2019-07-15 stsp
167 3ce1b845 2019-07-15 stsp }
168 3ce1b845 2019-07-15 stsp
169 3ce1b845 2019-07-15 stsp function test_import_ignores {
170 71db5e8c 2019-08-08 stsp local testname=import_ignores
171 3ce1b845 2019-07-15 stsp local testroot=`mktemp -p /tmp -d got-test-$testname-XXXXXXXX`
172 3ce1b845 2019-07-15 stsp
173 3ce1b845 2019-07-15 stsp got init $testroot/repo
174 3ce1b845 2019-07-15 stsp
175 3ce1b845 2019-07-15 stsp mkdir $testroot/tree
176 3ce1b845 2019-07-15 stsp make_test_tree $testroot/tree
177 3ce1b845 2019-07-15 stsp
178 3ce1b845 2019-07-15 stsp got import -I alpha -I '*lta*' -I '*silon' \
179 3ce1b845 2019-07-15 stsp -m 'init' -r $testroot/repo $testroot/tree > $testroot/stdout
180 3ce1b845 2019-07-15 stsp ret="$?"
181 3ce1b845 2019-07-15 stsp if [ "$ret" != "0" ]; then
182 3ce1b845 2019-07-15 stsp test_done "$testroot" "$ret"
183 3ce1b845 2019-07-15 stsp return 1
184 3ce1b845 2019-07-15 stsp fi
185 3ce1b845 2019-07-15 stsp
186 3ce1b845 2019-07-15 stsp local head_commit=`git_show_head $testroot/repo`
187 3ce1b845 2019-07-15 stsp echo "A $testroot/tree/beta" >> $testroot/stdout.expected
188 3ce1b845 2019-07-15 stsp echo "Created branch refs/heads/master with commit $head_commit" \
189 3ce1b845 2019-07-15 stsp >> $testroot/stdout.expected
190 3ce1b845 2019-07-15 stsp
191 3ce1b845 2019-07-15 stsp cmp -s $testroot/stdout.expected $testroot/stdout
192 3ce1b845 2019-07-15 stsp ret="$?"
193 3ce1b845 2019-07-15 stsp if [ "$ret" != "0" ]; then
194 3ce1b845 2019-07-15 stsp diff -u $testroot/stdout.expected $testroot/stdout
195 3ce1b845 2019-07-15 stsp fi
196 3ce1b845 2019-07-15 stsp test_done "$testroot" "$ret"
197 3ce1b845 2019-07-15 stsp
198 3ce1b845 2019-07-15 stsp
199 3ce1b845 2019-07-15 stsp }
200 3ce1b845 2019-07-15 stsp
201 3ce1b845 2019-07-15 stsp run_test test_import_basic
202 3ce1b845 2019-07-15 stsp run_test test_import_requires_new_branch
203 3ce1b845 2019-07-15 stsp run_test test_import_ignores