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