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