3 c4296144 2019-05-09 stsp # Copyright (c) 2019 Stefan Sperling <stsp@openbsd.org>
5 c4296144 2019-05-09 stsp # Permission to use, copy, modify, and distribute this software for any
6 c4296144 2019-05-09 stsp # purpose with or without fee is hereby granted, provided that the above
7 c4296144 2019-05-09 stsp # copyright notice and this permission notice appear in all copies.
9 c4296144 2019-05-09 stsp # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 c4296144 2019-05-09 stsp # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 c4296144 2019-05-09 stsp # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 c4296144 2019-05-09 stsp # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 c4296144 2019-05-09 stsp # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 c4296144 2019-05-09 stsp # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 c4296144 2019-05-09 stsp # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 c4296144 2019-05-09 stsp . ./common.sh
19 35bd8fed 2019-05-09 stsp name=$(getent passwd $USER | cut -d: -f5)
20 35bd8fed 2019-05-09 stsp export GOT_AUTHOR="$name <$(whoami)@$(hostname)>"
22 c4296144 2019-05-09 stsp function test_commit_basic {
23 c4296144 2019-05-09 stsp local testroot=`test_init commit_basic`
25 c4296144 2019-05-09 stsp got checkout $testroot/repo $testroot/wt > /dev/null
27 c4296144 2019-05-09 stsp if [ "$ret" != "0" ]; then
28 c4296144 2019-05-09 stsp test_done "$testroot" "$ret"
32 c4296144 2019-05-09 stsp echo "modified alpha" > $testroot/wt/alpha
33 c4296144 2019-05-09 stsp (cd $testroot/wt && got rm beta >/dev/null)
34 c4296144 2019-05-09 stsp echo "new file" > $testroot/wt/new
35 c4296144 2019-05-09 stsp (cd $testroot/wt && got add new >/dev/null)
37 c4296144 2019-05-09 stsp (cd $testroot/wt && got commit -m 'test commit_basic' > $testroot/stdout)
39 c4296144 2019-05-09 stsp local head_rev=`git_show_head $testroot/repo`
40 afa376bf 2019-05-09 stsp echo "A new" > $testroot/stdout.expected
41 afa376bf 2019-05-09 stsp echo "M alpha" >> $testroot/stdout.expected
42 afa376bf 2019-05-09 stsp echo "D beta" >> $testroot/stdout.expected
43 c4296144 2019-05-09 stsp echo "created commit $head_rev" >> $testroot/stdout.expected
45 c4296144 2019-05-09 stsp cmp $testroot/stdout.expected $testroot/stdout
47 c4296144 2019-05-09 stsp if [ "$ret" != "0" ]; then
48 c4296144 2019-05-09 stsp diff -u $testroot/stdout.expected $testroot/stdout
50 c4296144 2019-05-09 stsp test_done "$testroot" "$ret"
53 baa7dcfa 2019-05-09 stsp function test_commit_new_subdir {
54 baa7dcfa 2019-05-09 stsp local testroot=`test_init commit_new_subdir`
56 baa7dcfa 2019-05-09 stsp got checkout $testroot/repo $testroot/wt > /dev/null
58 baa7dcfa 2019-05-09 stsp if [ "$ret" != "0" ]; then
59 baa7dcfa 2019-05-09 stsp test_done "$testroot" "$ret"
63 baa7dcfa 2019-05-09 stsp mkdir -p $testroot/wt/d
64 baa7dcfa 2019-05-09 stsp echo "new file" > $testroot/wt/d/new
65 baa7dcfa 2019-05-09 stsp echo "another new file" > $testroot/wt/d/new2
66 baa7dcfa 2019-05-09 stsp (cd $testroot/wt && got add d/new >/dev/null)
67 baa7dcfa 2019-05-09 stsp (cd $testroot/wt && got add d/new2 >/dev/null)
69 baa7dcfa 2019-05-09 stsp (cd $testroot/wt && \
70 baa7dcfa 2019-05-09 stsp got commit -m 'test commit_new_subdir' > $testroot/stdout)
72 baa7dcfa 2019-05-09 stsp local head_rev=`git_show_head $testroot/repo`
73 baa7dcfa 2019-05-09 stsp echo "A d/new" > $testroot/stdout.expected
74 baa7dcfa 2019-05-09 stsp echo "A d/new2" >> $testroot/stdout.expected
75 baa7dcfa 2019-05-09 stsp echo "created commit $head_rev" >> $testroot/stdout.expected
77 baa7dcfa 2019-05-09 stsp cmp $testroot/stdout.expected $testroot/stdout
79 baa7dcfa 2019-05-09 stsp if [ "$ret" != "0" ]; then
80 baa7dcfa 2019-05-09 stsp diff -u $testroot/stdout.expected $testroot/stdout
82 baa7dcfa 2019-05-09 stsp test_done "$testroot" "$ret"
85 bc70eb79 2019-05-09 stsp function test_commit_subdir {
86 bc70eb79 2019-05-09 stsp local testroot=`test_init commit_subdir`
88 bc70eb79 2019-05-09 stsp got checkout $testroot/repo $testroot/wt > /dev/null
90 bc70eb79 2019-05-09 stsp if [ "$ret" != "0" ]; then
91 bc70eb79 2019-05-09 stsp test_done "$testroot" "$ret"
95 bc70eb79 2019-05-09 stsp echo "modified alpha" > $testroot/wt/alpha
96 bc70eb79 2019-05-09 stsp echo "modified zeta" > $testroot/wt/epsilon/zeta
98 bc70eb79 2019-05-09 stsp (cd $testroot/wt && \
99 bc70eb79 2019-05-09 stsp got commit -m 'test commit_subdir' epsilon > $testroot/stdout)
101 bc70eb79 2019-05-09 stsp local head_rev=`git_show_head $testroot/repo`
102 bc70eb79 2019-05-09 stsp echo "M epsilon/zeta" >> $testroot/stdout.expected
103 bc70eb79 2019-05-09 stsp echo "created commit $head_rev" >> $testroot/stdout.expected
105 bc70eb79 2019-05-09 stsp cmp $testroot/stdout.expected $testroot/stdout
107 bc70eb79 2019-05-09 stsp if [ "$ret" != "0" ]; then
108 bc70eb79 2019-05-09 stsp diff -u $testroot/stdout.expected $testroot/stdout
110 bc70eb79 2019-05-09 stsp test_done "$testroot" "$ret"
113 5bbcb68b 2019-05-09 stsp function test_commit_single_file {
114 5bbcb68b 2019-05-09 stsp local testroot=`test_init commit_single_file`
116 5bbcb68b 2019-05-09 stsp got checkout $testroot/repo $testroot/wt > /dev/null
118 5bbcb68b 2019-05-09 stsp if [ "$ret" != "0" ]; then
119 5bbcb68b 2019-05-09 stsp test_done "$testroot" "$ret"
123 5bbcb68b 2019-05-09 stsp echo "modified alpha" > $testroot/wt/alpha
124 5bbcb68b 2019-05-09 stsp echo "modified zeta" > $testroot/wt/epsilon/zeta
126 5bbcb68b 2019-05-09 stsp (cd $testroot/wt && got commit -m 'test commit_subdir' epsilon/zeta \
127 5bbcb68b 2019-05-09 stsp > $testroot/stdout)
129 5bbcb68b 2019-05-09 stsp local head_rev=`git_show_head $testroot/repo`
130 5bbcb68b 2019-05-09 stsp echo "M epsilon/zeta" >> $testroot/stdout.expected
131 5bbcb68b 2019-05-09 stsp echo "created commit $head_rev" >> $testroot/stdout.expected
133 5bbcb68b 2019-05-09 stsp cmp $testroot/stdout.expected $testroot/stdout
135 5bbcb68b 2019-05-09 stsp if [ "$ret" != "0" ]; then
136 5bbcb68b 2019-05-09 stsp diff -u $testroot/stdout.expected $testroot/stdout
138 5bbcb68b 2019-05-09 stsp test_done "$testroot" "$ret"
141 819f385b 2019-05-10 stsp function test_commit_out_of_date {
142 819f385b 2019-05-10 stsp local testroot=`test_init commit_out_of_date`
144 819f385b 2019-05-10 stsp got checkout $testroot/repo $testroot/wt > /dev/null
146 819f385b 2019-05-10 stsp if [ "$ret" != "0" ]; then
147 819f385b 2019-05-10 stsp test_done "$testroot" "$ret"
151 819f385b 2019-05-10 stsp echo "modified alpha" > $testroot/repo/alpha
152 819f385b 2019-05-10 stsp git_commit $testroot/repo -m "modified alpha"
154 819f385b 2019-05-10 stsp echo "modified alpha" > $testroot/wt/alpha
156 819f385b 2019-05-10 stsp (cd $testroot/wt && got commit -m 'test commit_out_of_date' \
157 819f385b 2019-05-10 stsp > $testroot/stdout 2> $testroot/stderr)
159 819f385b 2019-05-10 stsp local head_rev=`git_show_head $testroot/repo`
160 819f385b 2019-05-10 stsp echo -n > $testroot/stdout.expected
161 819f385b 2019-05-10 stsp echo "got: work tree must be updated before these" \
162 819f385b 2019-05-10 stsp "changes can be committed" > $testroot/stderr.expected
164 819f385b 2019-05-10 stsp cmp $testroot/stdout.expected $testroot/stdout
166 819f385b 2019-05-10 stsp if [ "$ret" != "0" ]; then
167 819f385b 2019-05-10 stsp diff -u $testroot/stdout.expected $testroot/stdout
168 819f385b 2019-05-10 stsp test_done "$testroot" "$ret"
172 819f385b 2019-05-10 stsp cmp $testroot/stderr.expected $testroot/stderr
174 819f385b 2019-05-10 stsp if [ "$ret" != "0" ]; then
175 819f385b 2019-05-10 stsp diff -u $testroot/stderr.expected $testroot/stderr
177 819f385b 2019-05-10 stsp test_done "$testroot" "$ret"
180 c4296144 2019-05-09 stsp run_test test_commit_basic
181 baa7dcfa 2019-05-09 stsp run_test test_commit_new_subdir
182 bc70eb79 2019-05-09 stsp run_test test_commit_subdir
183 5bbcb68b 2019-05-09 stsp run_test test_commit_single_file
184 819f385b 2019-05-10 stsp run_test test_commit_out_of_date