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