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 function test_import_basic {
20 local testname=import_basic
21 local testroot=`mktemp -p /tmp -d 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" != "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" != "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" != "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 "Now shut up and hack" >> $testroot/stdout.expected
109 got checkout $testroot/repo $testroot/wt > $testroot/stdout
110 ret="$?"
111 if [ "$ret" != "0" ]; then
112 test_done "$testroot" "$ret"
113 return 1
114 fi
116 cmp -s $testroot/stdout.expected $testroot/stdout
117 ret="$?"
118 if [ "$ret" != "0" ]; then
119 diff -u $testroot/stdout.expected $testroot/stdout
120 test_done "$testroot" "$ret"
121 return 1
122 fi
124 echo "alpha" > $testroot/content.expected
125 echo "beta" >> $testroot/content.expected
126 echo "zeta" >> $testroot/content.expected
127 echo "delta" >> $testroot/content.expected
128 cat $testroot/wt/alpha $testroot/wt/beta $testroot/wt/epsilon/zeta \
129 $testroot/wt/gamma/delta > $testroot/content
131 cmp -s $testroot/content.expected $testroot/content
132 ret="$?"
133 if [ "$ret" != "0" ]; then
134 diff -u $testroot/content.expected $testroot/content
135 fi
136 test_done "$testroot" "$ret"
139 function test_import_requires_new_branch {
140 local testroot=`test_init import_requires_new_branch`
142 mkdir $testroot/tree
143 make_test_tree $testroot/tree
145 got import -b master -m 'init' -r $testroot/repo $testroot/tree \
146 > $testroot/stdout 2> $testroot/stderr
147 ret="$?"
148 if [ "$ret" == "0" ]; then
149 echo "import command should have failed but did not"
150 test_done "$testroot" "1"
151 return 1
152 fi
154 echo "got: import target branch already exists" \
155 > $testroot/stderr.expected
156 cmp -s $testroot/stderr.expected $testroot/stderr
157 ret="$?"
158 if [ "$ret" != "0" ]; then
159 diff -u $testroot/stderr.expected $testroot/stderr
160 test_done "$testroot" "$ret"
161 return 1
162 fi
164 got import -b newbranch -m 'init' -r $testroot/repo $testroot/tree \
165 > $testroot/stdout
166 ret="$?"
167 test_done "$testroot" "$ret"
171 function test_import_ignores {
172 local testname=import_ignores
173 local testroot=`mktemp -p /tmp -d got-test-$testname-XXXXXXXX`
175 got init $testroot/repo
177 mkdir $testroot/tree
178 make_test_tree $testroot/tree
180 got import -I alpha -I '*lta*' -I '*silon' \
181 -m 'init' -r $testroot/repo $testroot/tree > $testroot/stdout
182 ret="$?"
183 if [ "$ret" != "0" ]; then
184 test_done "$testroot" "$ret"
185 return 1
186 fi
188 local head_commit=`git_show_head $testroot/repo`
189 echo "A $testroot/tree/beta" >> $testroot/stdout.expected
190 echo "Created branch refs/heads/main with commit $head_commit" \
191 >> $testroot/stdout.expected
193 cmp -s $testroot/stdout.expected $testroot/stdout
194 ret="$?"
195 if [ "$ret" != "0" ]; then
196 diff -u $testroot/stdout.expected $testroot/stdout
197 fi
198 test_done "$testroot" "$ret"
201 function test_import_empty_dir {
202 local testname=import_empty_dir
203 local testroot=`mktemp -p /tmp -d got-test-$testname-XXXXXXXX`
205 got init $testroot/repo
207 mkdir $testroot/tree
208 mkdir -p $testroot/tree/empty $testroot/tree/notempty
209 echo "alpha" > $testroot/tree/notempty/alpha
211 got import -m 'init' -r $testroot/repo $testroot/tree > $testroot/stdout
212 ret="$?"
213 if [ "$ret" != "0" ]; then
214 test_done "$testroot" "$ret"
215 return 1
216 fi
218 local head_commit=`git_show_head $testroot/repo`
219 echo "A $testroot/tree/notempty/alpha" >> $testroot/stdout.expected
220 echo "Created branch refs/heads/main with commit $head_commit" \
221 >> $testroot/stdout.expected
223 cmp -s $testroot/stdout.expected $testroot/stdout
224 ret="$?"
225 if [ "$ret" != "0" ]; then
226 diff -u $testroot/stdout.expected $testroot/stdout
227 test_done "$testroot" "$ret"
228 return 1
229 fi
231 # Verify that Got did not import the empty directory
232 echo "notempty/" > $testroot/stdout.expected
233 echo "notempty/alpha" >> $testroot/stdout.expected
235 got tree -r $testroot/repo -R > $testroot/stdout
236 cmp -s $testroot/stdout.expected $testroot/stdout
237 ret="$?"
238 if [ "$ret" != "0" ]; then
239 diff -u $testroot/stdout.expected $testroot/stdout
240 fi
241 test_done "$testroot" "$ret"
244 run_test test_import_basic
245 run_test test_import_requires_new_branch
246 run_test test_import_ignores
247 run_test test_import_empty_dir