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