Blob


1 #!/bin/sh
2 #
3 # Copyright (c) 2019 Stefan Sperling <stsp@openbsd.org>
4 #
5 # Permission to use, copy, modify, and distribute this software for any
6 # purpose with or without fee is hereby granted, provided that the above
7 # copyright notice and this permission notice appear in all copies.
8 #
9 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 . ./common.sh
19 test_import_basic() {
20 local testname=import_basic
21 local testroot=`mktemp -d "$GOT_TEST_ROOT/got-test-$testname-XXXXXXXX"`
23 gotadmin init $testroot/repo
25 mkdir $testroot/tree
26 make_test_tree $testroot/tree
28 got import -m 'init' -r $testroot/repo $testroot/tree \
29 > $testroot/stdout
30 ret=$?
31 if [ $ret -ne 0 ]; then
32 test_done "$testroot" "$ret"
33 return 1
34 fi
36 local head_commit=`git_show_head $testroot/repo`
37 echo "A $testroot/tree/gamma/delta" > $testroot/stdout.expected
38 echo "A $testroot/tree/epsilon/zeta" >> $testroot/stdout.expected
39 echo "A $testroot/tree/alpha" >> $testroot/stdout.expected
40 echo "A $testroot/tree/beta" >> $testroot/stdout.expected
41 echo "Created branch refs/heads/main with commit $head_commit" \
42 >> $testroot/stdout.expected
44 cmp -s $testroot/stdout.expected $testroot/stdout
45 ret=$?
46 if [ $ret -ne 0 ]; then
47 diff -u $testroot/stdout.expected $testroot/stdout
48 test_done "$testroot" "$ret"
49 return 1
50 fi
52 (cd $testroot/repo && got log -p | grep -v ^date: > $testroot/stdout)
54 id_alpha=`get_blob_id $testroot/repo "" alpha`
55 id_beta=`get_blob_id $testroot/repo "" beta`
56 id_zeta=`get_blob_id $testroot/repo epsilon zeta`
57 id_delta=`get_blob_id $testroot/repo gamma delta`
58 tree_id=`(cd $testroot/repo && got cat $head_commit | \
59 grep ^tree | cut -d ' ' -f 2)`
61 echo "-----------------------------------------------" \
62 > $testroot/stdout.expected
63 echo "commit $head_commit (main)" >> $testroot/stdout.expected
64 echo "from: $GOT_AUTHOR" >> $testroot/stdout.expected
65 echo " " >> $testroot/stdout.expected
66 echo " init" >> $testroot/stdout.expected
67 echo " " >> $testroot/stdout.expected
68 echo "diff /dev/null $head_commit" >> $testroot/stdout.expected
69 echo "commit - /dev/null" >> $testroot/stdout.expected
70 echo "commit + $head_commit" >> $testroot/stdout.expected
71 echo "blob - /dev/null" >> $testroot/stdout.expected
72 echo "blob + $id_alpha (mode 644)" >> $testroot/stdout.expected
73 echo "--- /dev/null" >> $testroot/stdout.expected
74 echo "+++ alpha" >> $testroot/stdout.expected
75 echo "@@ -0,0 +1 @@" >> $testroot/stdout.expected
76 echo "+alpha" >> $testroot/stdout.expected
77 echo "blob - /dev/null" >> $testroot/stdout.expected
78 echo "blob + $id_beta (mode 644)" >> $testroot/stdout.expected
79 echo "--- /dev/null" >> $testroot/stdout.expected
80 echo "+++ beta" >> $testroot/stdout.expected
81 echo "@@ -0,0 +1 @@" >> $testroot/stdout.expected
82 echo "+beta" >> $testroot/stdout.expected
83 echo "blob - /dev/null" >> $testroot/stdout.expected
84 echo "blob + $id_zeta (mode 644)" >> $testroot/stdout.expected
85 echo "--- /dev/null" >> $testroot/stdout.expected
86 echo "+++ epsilon/zeta" >> $testroot/stdout.expected
87 echo "@@ -0,0 +1 @@" >> $testroot/stdout.expected
88 echo "+zeta" >> $testroot/stdout.expected
89 echo "blob - /dev/null" >> $testroot/stdout.expected
90 echo "blob + $id_delta (mode 644)" >> $testroot/stdout.expected
91 echo "--- /dev/null" >> $testroot/stdout.expected
92 echo "+++ gamma/delta" >> $testroot/stdout.expected
93 echo "@@ -0,0 +1 @@" >> $testroot/stdout.expected
94 echo "+delta" >> $testroot/stdout.expected
95 echo "" >> $testroot/stdout.expected
97 cmp -s $testroot/stdout.expected $testroot/stdout
98 ret=$?
99 if [ $ret -ne 0 ]; then
100 diff -u $testroot/stdout.expected $testroot/stdout
101 test_done "$testroot" "$ret"
102 return 1
103 fi
105 echo "A $testroot/wt/alpha" > $testroot/stdout.expected
106 echo "A $testroot/wt/beta" >> $testroot/stdout.expected
107 echo "A $testroot/wt/epsilon/zeta" >> $testroot/stdout.expected
108 echo "A $testroot/wt/gamma/delta" >> $testroot/stdout.expected
109 echo "Checked out refs/heads/main: $head_commit" \
110 >> $testroot/stdout.expected
111 echo "Now shut up and hack" >> $testroot/stdout.expected
113 got checkout $testroot/repo $testroot/wt > $testroot/stdout
114 ret=$?
115 if [ $ret -ne 0 ]; then
116 test_done "$testroot" "$ret"
117 return 1
118 fi
120 cmp -s $testroot/stdout.expected $testroot/stdout
121 ret=$?
122 if [ $ret -ne 0 ]; then
123 diff -u $testroot/stdout.expected $testroot/stdout
124 test_done "$testroot" "$ret"
125 return 1
126 fi
128 echo "alpha" > $testroot/content.expected
129 echo "beta" >> $testroot/content.expected
130 echo "zeta" >> $testroot/content.expected
131 echo "delta" >> $testroot/content.expected
132 cat $testroot/wt/alpha $testroot/wt/beta $testroot/wt/epsilon/zeta \
133 $testroot/wt/gamma/delta > $testroot/content
135 cmp -s $testroot/content.expected $testroot/content
136 ret=$?
137 if [ $ret -ne 0 ]; then
138 diff -u $testroot/content.expected $testroot/content
139 fi
140 test_done "$testroot" "$ret"
143 test_import_requires_new_branch() {
144 local testroot=`test_init import_requires_new_branch`
146 mkdir $testroot/tree
147 make_test_tree $testroot/tree
149 got import -b master -m 'init' -r $testroot/repo $testroot/tree \
150 > $testroot/stdout 2> $testroot/stderr
151 ret=$?
152 if [ $ret -eq 0 ]; then
153 echo "import command should have failed but did not"
154 test_done "$testroot" "1"
155 return 1
156 fi
158 echo "got: import target branch already exists" \
159 > $testroot/stderr.expected
160 cmp -s $testroot/stderr.expected $testroot/stderr
161 ret=$?
162 if [ $ret -ne 0 ]; then
163 diff -u $testroot/stderr.expected $testroot/stderr
164 test_done "$testroot" "$ret"
165 return 1
166 fi
168 got import -b newbranch -m 'init' -r $testroot/repo $testroot/tree \
169 > $testroot/stdout
170 ret=$?
171 test_done "$testroot" "$ret"
175 test_import_ignores() {
176 local testname=import_ignores
177 local testroot=`mktemp -d "$GOT_TEST_ROOT/got-test-$testname-XXXXXXXX"`
179 gotadmin init $testroot/repo
181 mkdir $testroot/tree
182 make_test_tree $testroot/tree
184 got import -I alpha -I '*lta*' -I '*silon' \
185 -m 'init' -r $testroot/repo $testroot/tree > $testroot/stdout
186 ret=$?
187 if [ $ret -ne 0 ]; then
188 test_done "$testroot" "$ret"
189 return 1
190 fi
192 local head_commit=`git_show_head $testroot/repo`
193 echo "A $testroot/tree/beta" >> $testroot/stdout.expected
194 echo "Created branch refs/heads/main with commit $head_commit" \
195 >> $testroot/stdout.expected
197 cmp -s $testroot/stdout.expected $testroot/stdout
198 ret=$?
199 if [ $ret -ne 0 ]; then
200 diff -u $testroot/stdout.expected $testroot/stdout
201 fi
202 test_done "$testroot" "$ret"
205 test_import_empty_dir() {
206 local testname=import_empty_dir
207 local testroot=`mktemp -d "$GOT_TEST_ROOT/got-test-$testname-XXXXXXXX"`
209 gotadmin init $testroot/repo
211 mkdir $testroot/tree
212 mkdir -p $testroot/tree/empty $testroot/tree/notempty
213 echo "alpha" > $testroot/tree/notempty/alpha
215 got import -m 'init' -r $testroot/repo $testroot/tree > $testroot/stdout
216 ret=$?
217 if [ $ret -ne 0 ]; then
218 test_done "$testroot" "$ret"
219 return 1
220 fi
222 local head_commit=`git_show_head $testroot/repo`
223 echo "A $testroot/tree/notempty/alpha" >> $testroot/stdout.expected
224 echo "Created branch refs/heads/main with commit $head_commit" \
225 >> $testroot/stdout.expected
227 cmp -s $testroot/stdout.expected $testroot/stdout
228 ret=$?
229 if [ $ret -ne 0 ]; then
230 diff -u $testroot/stdout.expected $testroot/stdout
231 test_done "$testroot" "$ret"
232 return 1
233 fi
235 # Verify that Got did not import the empty directory
236 echo "notempty/" > $testroot/stdout.expected
237 echo "notempty/alpha" >> $testroot/stdout.expected
239 got tree -r $testroot/repo -R > $testroot/stdout
240 cmp -s $testroot/stdout.expected $testroot/stdout
241 ret=$?
242 if [ $ret -ne 0 ]; then
243 diff -u $testroot/stdout.expected $testroot/stdout
244 fi
245 test_done "$testroot" "$ret"
248 test_import_symlink() {
249 local testname=import_symlink
250 local testroot=`mktemp -d "$GOT_TEST_ROOT/got-test-$testname-XXXXXXXX"`
252 gotadmin init $testroot/repo
254 mkdir $testroot/tree
255 echo 'this is file alpha' > $testroot/tree/alpha
256 ln -s alpha $testroot/tree/alpha.link
258 got import -m 'init' -r $testroot/repo $testroot/tree \
259 > $testroot/stdout
260 ret=$?
261 if [ $ret -ne 0 ]; then
262 test_done "$testroot" "$ret"
263 return 1
264 fi
266 local head_commit=`git_show_head $testroot/repo`
267 echo "A $testroot/tree/alpha" > $testroot/stdout.expected
268 echo "A $testroot/tree/alpha.link" >> $testroot/stdout.expected
269 echo "Created branch refs/heads/main with commit $head_commit" \
270 >> $testroot/stdout.expected
272 cmp -s $testroot/stdout.expected $testroot/stdout
273 ret=$?
274 if [ $ret -ne 0 ]; then
275 diff -u $testroot/stdout.expected $testroot/stdout
276 test_done "$testroot" "$ret"
277 return 1
278 fi
280 id_alpha=`get_blob_id $testroot/repo "" alpha`
281 id_alpha_link=$(got tree -r $testroot/repo -i | grep 'alpha.link@ -> alpha$' | cut -d' ' -f 1)
282 tree_id=`(cd $testroot/repo && got cat $head_commit | \
283 grep ^tree | cut -d ' ' -f 2)`
285 got tree -i -r $testroot/repo -c $head_commit > $testroot/stdout
287 echo "$id_alpha alpha" > $testroot/stdout.expected
288 echo "$id_alpha_link alpha.link@ -> alpha" >> $testroot/stdout.expected
290 cmp -s $testroot/stdout.expected $testroot/stdout
291 ret=$?
292 if [ $ret -ne 0 ]; then
293 diff -u $testroot/stdout.expected $testroot/stdout
294 fi
295 test_done "$testroot" "$ret"
298 test_parseargs "$@"
299 run_test test_import_basic
300 run_test test_import_requires_new_branch
301 run_test test_import_ignores
302 run_test test_import_empty_dir
303 run_test test_import_symlink