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 got 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 $tree_id" >> $testroot/stdout.expected
69 echo "blob - /dev/null" >> $testroot/stdout.expected
70 echo "blob + $id_alpha (mode 644)" >> $testroot/stdout.expected
71 echo "--- /dev/null" >> $testroot/stdout.expected
72 echo "+++ alpha" >> $testroot/stdout.expected
73 echo "@@ -0,0 +1 @@" >> $testroot/stdout.expected
74 echo "+alpha" >> $testroot/stdout.expected
75 echo "blob - /dev/null" >> $testroot/stdout.expected
76 echo "blob + $id_beta (mode 644)" >> $testroot/stdout.expected
77 echo "--- /dev/null" >> $testroot/stdout.expected
78 echo "+++ beta" >> $testroot/stdout.expected
79 echo "@@ -0,0 +1 @@" >> $testroot/stdout.expected
80 echo "+beta" >> $testroot/stdout.expected
81 echo "blob - /dev/null" >> $testroot/stdout.expected
82 echo "blob + $id_zeta (mode 644)" >> $testroot/stdout.expected
83 echo "--- /dev/null" >> $testroot/stdout.expected
84 echo "+++ epsilon/zeta" >> $testroot/stdout.expected
85 echo "@@ -0,0 +1 @@" >> $testroot/stdout.expected
86 echo "+zeta" >> $testroot/stdout.expected
87 echo "blob - /dev/null" >> $testroot/stdout.expected
88 echo "blob + $id_delta (mode 644)" >> $testroot/stdout.expected
89 echo "--- /dev/null" >> $testroot/stdout.expected
90 echo "+++ gamma/delta" >> $testroot/stdout.expected
91 echo "@@ -0,0 +1 @@" >> $testroot/stdout.expected
92 echo "+delta" >> $testroot/stdout.expected
93 echo "" >> $testroot/stdout.expected
95 cmp -s $testroot/stdout.expected $testroot/stdout
96 ret=$?
97 if [ $ret -ne 0 ]; then
98 diff -u $testroot/stdout.expected $testroot/stdout
99 test_done "$testroot" "$ret"
100 return 1
101 fi
103 echo "A $testroot/wt/alpha" > $testroot/stdout.expected
104 echo "A $testroot/wt/beta" >> $testroot/stdout.expected
105 echo "A $testroot/wt/epsilon/zeta" >> $testroot/stdout.expected
106 echo "A $testroot/wt/gamma/delta" >> $testroot/stdout.expected
107 echo "Checked out refs/heads/main: $head_commit" \
108 >> $testroot/stdout.expected
109 echo "Now shut up and hack" >> $testroot/stdout.expected
111 got checkout $testroot/repo $testroot/wt > $testroot/stdout
112 ret=$?
113 if [ $ret -ne 0 ]; then
114 test_done "$testroot" "$ret"
115 return 1
116 fi
118 cmp -s $testroot/stdout.expected $testroot/stdout
119 ret=$?
120 if [ $ret -ne 0 ]; then
121 diff -u $testroot/stdout.expected $testroot/stdout
122 test_done "$testroot" "$ret"
123 return 1
124 fi
126 echo "alpha" > $testroot/content.expected
127 echo "beta" >> $testroot/content.expected
128 echo "zeta" >> $testroot/content.expected
129 echo "delta" >> $testroot/content.expected
130 cat $testroot/wt/alpha $testroot/wt/beta $testroot/wt/epsilon/zeta \
131 $testroot/wt/gamma/delta > $testroot/content
133 cmp -s $testroot/content.expected $testroot/content
134 ret=$?
135 if [ $ret -ne 0 ]; then
136 diff -u $testroot/content.expected $testroot/content
137 fi
138 test_done "$testroot" "$ret"
141 test_import_requires_new_branch() {
142 local testroot=`test_init import_requires_new_branch`
144 mkdir $testroot/tree
145 make_test_tree $testroot/tree
147 got import -b master -m 'init' -r $testroot/repo $testroot/tree \
148 > $testroot/stdout 2> $testroot/stderr
149 ret=$?
150 if [ $ret -eq 0 ]; then
151 echo "import command should have failed but did not"
152 test_done "$testroot" "1"
153 return 1
154 fi
156 echo "got: import target branch already exists" \
157 > $testroot/stderr.expected
158 cmp -s $testroot/stderr.expected $testroot/stderr
159 ret=$?
160 if [ $ret -ne 0 ]; then
161 diff -u $testroot/stderr.expected $testroot/stderr
162 test_done "$testroot" "$ret"
163 return 1
164 fi
166 got import -b newbranch -m 'init' -r $testroot/repo $testroot/tree \
167 > $testroot/stdout
168 ret=$?
169 test_done "$testroot" "$ret"
173 test_import_ignores() {
174 local testname=import_ignores
175 local testroot=`mktemp -d "$GOT_TEST_ROOT/got-test-$testname-XXXXXXXX"`
177 got init $testroot/repo
179 mkdir $testroot/tree
180 make_test_tree $testroot/tree
182 got import -I alpha -I '*lta*' -I '*silon' \
183 -m 'init' -r $testroot/repo $testroot/tree > $testroot/stdout
184 ret=$?
185 if [ $ret -ne 0 ]; then
186 test_done "$testroot" "$ret"
187 return 1
188 fi
190 local head_commit=`git_show_head $testroot/repo`
191 echo "A $testroot/tree/beta" >> $testroot/stdout.expected
192 echo "Created branch refs/heads/main with commit $head_commit" \
193 >> $testroot/stdout.expected
195 cmp -s $testroot/stdout.expected $testroot/stdout
196 ret=$?
197 if [ $ret -ne 0 ]; then
198 diff -u $testroot/stdout.expected $testroot/stdout
199 fi
200 test_done "$testroot" "$ret"
203 test_import_empty_dir() {
204 local testname=import_empty_dir
205 local testroot=`mktemp -d "$GOT_TEST_ROOT/got-test-$testname-XXXXXXXX"`
207 got init $testroot/repo
209 mkdir $testroot/tree
210 mkdir -p $testroot/tree/empty $testroot/tree/notempty
211 echo "alpha" > $testroot/tree/notempty/alpha
213 got import -m 'init' -r $testroot/repo $testroot/tree > $testroot/stdout
214 ret=$?
215 if [ $ret -ne 0 ]; then
216 test_done "$testroot" "$ret"
217 return 1
218 fi
220 local head_commit=`git_show_head $testroot/repo`
221 echo "A $testroot/tree/notempty/alpha" >> $testroot/stdout.expected
222 echo "Created branch refs/heads/main with commit $head_commit" \
223 >> $testroot/stdout.expected
225 cmp -s $testroot/stdout.expected $testroot/stdout
226 ret=$?
227 if [ $ret -ne 0 ]; then
228 diff -u $testroot/stdout.expected $testroot/stdout
229 test_done "$testroot" "$ret"
230 return 1
231 fi
233 # Verify that Got did not import the empty directory
234 echo "notempty/" > $testroot/stdout.expected
235 echo "notempty/alpha" >> $testroot/stdout.expected
237 got tree -r $testroot/repo -R > $testroot/stdout
238 cmp -s $testroot/stdout.expected $testroot/stdout
239 ret=$?
240 if [ $ret -ne 0 ]; then
241 diff -u $testroot/stdout.expected $testroot/stdout
242 fi
243 test_done "$testroot" "$ret"
246 test_import_symlink() {
247 local testname=import_symlink
248 local testroot=`mktemp -d "$GOT_TEST_ROOT/got-test-$testname-XXXXXXXX"`
250 got init $testroot/repo
252 mkdir $testroot/tree
253 echo 'this is file alpha' > $testroot/tree/alpha
254 ln -s alpha $testroot/tree/alpha.link
256 got import -m 'init' -r $testroot/repo $testroot/tree \
257 > $testroot/stdout
258 ret=$?
259 if [ $ret -ne 0 ]; then
260 test_done "$testroot" "$ret"
261 return 1
262 fi
264 local head_commit=`git_show_head $testroot/repo`
265 echo "A $testroot/tree/alpha" > $testroot/stdout.expected
266 echo "A $testroot/tree/alpha.link" >> $testroot/stdout.expected
267 echo "Created branch refs/heads/main with commit $head_commit" \
268 >> $testroot/stdout.expected
270 cmp -s $testroot/stdout.expected $testroot/stdout
271 ret=$?
272 if [ $ret -ne 0 ]; then
273 diff -u $testroot/stdout.expected $testroot/stdout
274 test_done "$testroot" "$ret"
275 return 1
276 fi
278 id_alpha=`get_blob_id $testroot/repo "" alpha`
279 id_alpha_link=$(got tree -r $testroot/repo -i | grep 'alpha.link@ -> alpha$' | cut -d' ' -f 1)
280 tree_id=`(cd $testroot/repo && got cat $head_commit | \
281 grep ^tree | cut -d ' ' -f 2)`
283 got tree -i -r $testroot/repo -c $head_commit > $testroot/stdout
285 echo "$id_alpha alpha" > $testroot/stdout.expected
286 echo "$id_alpha_link alpha.link@ -> alpha" >> $testroot/stdout.expected
288 cmp -s $testroot/stdout.expected $testroot/stdout
289 ret=$?
290 if [ $ret -ne 0 ]; then
291 diff -u $testroot/stdout.expected $testroot/stdout
292 fi
293 test_done "$testroot" "$ret"
296 test_parseargs "$@"
297 run_test test_import_basic
298 run_test test_import_requires_new_branch
299 run_test test_import_ignores
300 run_test test_import_empty_dir
301 run_test test_import_symlink