3 95adcdca 2019-03-27 stsp # Copyright (c) 2019 Stefan Sperling <stsp@openbsd.org>
5 95adcdca 2019-03-27 stsp # Permission to use, copy, modify, and distribute this software for any
6 95adcdca 2019-03-27 stsp # purpose with or without fee is hereby granted, provided that the above
7 95adcdca 2019-03-27 stsp # copyright notice and this permission notice appear in all copies.
9 95adcdca 2019-03-27 stsp # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 95adcdca 2019-03-27 stsp # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 95adcdca 2019-03-27 stsp # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 95adcdca 2019-03-27 stsp # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 95adcdca 2019-03-27 stsp # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 95adcdca 2019-03-27 stsp # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 95adcdca 2019-03-27 stsp # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 95adcdca 2019-03-27 stsp . ./common.sh
19 95adcdca 2019-03-27 stsp function test_diff_basic {
20 95adcdca 2019-03-27 stsp local testroot=`test_init diff_basic`
21 95adcdca 2019-03-27 stsp local head_rev=`git_show_head $testroot/repo`
23 95adcdca 2019-03-27 stsp got checkout $testroot/repo $testroot/wt > /dev/null
25 95adcdca 2019-03-27 stsp if [ "$ret" != "0" ]; then
26 95adcdca 2019-03-27 stsp test_done "$testroot" "$ret"
30 95adcdca 2019-03-27 stsp echo "modified alpha" > $testroot/wt/alpha
31 95adcdca 2019-03-27 stsp (cd $testroot/wt && got rm beta >/dev/null)
32 95adcdca 2019-03-27 stsp echo "new file" > $testroot/wt/new
33 95adcdca 2019-03-27 stsp (cd $testroot/wt && got add new >/dev/null)
35 95adcdca 2019-03-27 stsp echo "diff $head_rev $testroot/wt" > $testroot/stdout.expected
36 95adcdca 2019-03-27 stsp echo -n 'blob - ' >> $testroot/stdout.expected
37 95adcdca 2019-03-27 stsp got tree -r $testroot/repo -i | grep 'alpha$' | cut -d' ' -f 1 \
38 95adcdca 2019-03-27 stsp >> $testroot/stdout.expected
39 95adcdca 2019-03-27 stsp echo 'file + alpha' >> $testroot/stdout.expected
40 95adcdca 2019-03-27 stsp echo '--- alpha' >> $testroot/stdout.expected
41 95adcdca 2019-03-27 stsp echo '+++ alpha' >> $testroot/stdout.expected
42 95adcdca 2019-03-27 stsp echo '@@ -1 +1 @@' >> $testroot/stdout.expected
43 95adcdca 2019-03-27 stsp echo '-alpha' >> $testroot/stdout.expected
44 95adcdca 2019-03-27 stsp echo '+modified alpha' >> $testroot/stdout.expected
45 95adcdca 2019-03-27 stsp echo -n 'blob - ' >> $testroot/stdout.expected
46 95adcdca 2019-03-27 stsp got tree -r $testroot/repo -i | grep 'beta$' | cut -d' ' -f 1 \
47 95adcdca 2019-03-27 stsp >> $testroot/stdout.expected
48 95adcdca 2019-03-27 stsp echo 'file + /dev/null' >> $testroot/stdout.expected
49 95adcdca 2019-03-27 stsp echo '--- beta' >> $testroot/stdout.expected
50 95adcdca 2019-03-27 stsp echo '+++ beta' >> $testroot/stdout.expected
51 95adcdca 2019-03-27 stsp echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
52 95adcdca 2019-03-27 stsp echo '-beta' >> $testroot/stdout.expected
53 95adcdca 2019-03-27 stsp echo 'blob - /dev/null' >> $testroot/stdout.expected
54 95adcdca 2019-03-27 stsp echo 'file + new' >> $testroot/stdout.expected
55 95adcdca 2019-03-27 stsp echo '--- new' >> $testroot/stdout.expected
56 95adcdca 2019-03-27 stsp echo '+++ new' >> $testroot/stdout.expected
57 95adcdca 2019-03-27 stsp echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
58 95adcdca 2019-03-27 stsp echo '+new file' >> $testroot/stdout.expected
60 95adcdca 2019-03-27 stsp (cd $testroot/wt && got diff > $testroot/stdout)
61 8d301dd9 2019-05-14 stsp cmp -s $testroot/stdout.expected $testroot/stdout
63 95adcdca 2019-03-27 stsp if [ "$ret" != "0" ]; then
64 95adcdca 2019-03-27 stsp diff -u $testroot/stdout.expected $testroot/stdout
65 2a06fe5f 2019-08-24 stsp test_done "$testroot" "$ret"
69 2a06fe5f 2019-08-24 stsp # diff non-existent path
70 2a06fe5f 2019-08-24 stsp (cd $testroot/wt && got diff nonexistent > $testroot/stdout \
71 2a06fe5f 2019-08-24 stsp 2> $testroot/stderr)
73 2a06fe5f 2019-08-24 stsp echo -n > $testroot/stdout.expected
74 2a06fe5f 2019-08-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
76 2a06fe5f 2019-08-24 stsp if [ "$ret" != "0" ]; then
77 2a06fe5f 2019-08-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
78 2a06fe5f 2019-08-24 stsp test_done "$testroot" "$ret"
82 2a06fe5f 2019-08-24 stsp echo "got: nonexistent: No such file or directory" \
83 2a06fe5f 2019-08-24 stsp > $testroot/stderr.expected
84 2a06fe5f 2019-08-24 stsp cmp -s $testroot/stderr.expected $testroot/stderr
86 2a06fe5f 2019-08-24 stsp if [ "$ret" != "0" ]; then
87 2a06fe5f 2019-08-24 stsp diff -u $testroot/stderr.expected $testroot/stderr
89 95adcdca 2019-03-27 stsp test_done "$testroot" "$ret"
92 95adcdca 2019-03-27 stsp function test_diff_shows_conflict {
93 95adcdca 2019-03-27 stsp local testroot=`test_init diff_shows_conflict 1`
95 95adcdca 2019-03-27 stsp echo "1" > $testroot/repo/numbers
96 95adcdca 2019-03-27 stsp echo "2" >> $testroot/repo/numbers
97 95adcdca 2019-03-27 stsp echo "3" >> $testroot/repo/numbers
98 95adcdca 2019-03-27 stsp echo "4" >> $testroot/repo/numbers
99 95adcdca 2019-03-27 stsp echo "5" >> $testroot/repo/numbers
100 95adcdca 2019-03-27 stsp echo "6" >> $testroot/repo/numbers
101 95adcdca 2019-03-27 stsp echo "7" >> $testroot/repo/numbers
102 95adcdca 2019-03-27 stsp echo "8" >> $testroot/repo/numbers
103 95adcdca 2019-03-27 stsp (cd $testroot/repo && git add numbers)
104 95adcdca 2019-03-27 stsp git_commit $testroot/repo -m "added numbers file"
106 95adcdca 2019-03-27 stsp got checkout $testroot/repo $testroot/wt > /dev/null
108 95adcdca 2019-03-27 stsp if [ "$ret" != "0" ]; then
109 95adcdca 2019-03-27 stsp test_done "$testroot" "$ret"
113 95adcdca 2019-03-27 stsp sed -i 's/2/22/' $testroot/repo/numbers
114 95adcdca 2019-03-27 stsp git_commit $testroot/repo -m "modified line 2"
115 95adcdca 2019-03-27 stsp local head_rev=`git_show_head $testroot/repo`
117 95adcdca 2019-03-27 stsp # modify line 2 in a conflicting way
118 95adcdca 2019-03-27 stsp sed -i 's/2/77/' $testroot/wt/numbers
120 95adcdca 2019-03-27 stsp echo "C numbers" > $testroot/stdout.expected
121 95adcdca 2019-03-27 stsp echo -n "Updated to commit $head_rev" >> $testroot/stdout.expected
122 95adcdca 2019-03-27 stsp echo >> $testroot/stdout.expected
124 95adcdca 2019-03-27 stsp (cd $testroot/wt && got update > $testroot/stdout)
126 8d301dd9 2019-05-14 stsp cmp -s $testroot/stdout.expected $testroot/stdout
128 95adcdca 2019-03-27 stsp if [ "$ret" != "0" ]; then
129 95adcdca 2019-03-27 stsp diff -u $testroot/stdout.expected $testroot/stdout
130 95adcdca 2019-03-27 stsp test_done "$testroot" "$ret"
134 95adcdca 2019-03-27 stsp echo "diff $head_rev $testroot/wt" > $testroot/stdout.expected
135 95adcdca 2019-03-27 stsp echo -n 'blob - ' >> $testroot/stdout.expected
136 95adcdca 2019-03-27 stsp got tree -r $testroot/repo -i | grep 'numbers$' | cut -d' ' -f 1 \
137 95adcdca 2019-03-27 stsp >> $testroot/stdout.expected
138 95adcdca 2019-03-27 stsp echo 'file + numbers' >> $testroot/stdout.expected
139 95adcdca 2019-03-27 stsp echo '--- numbers' >> $testroot/stdout.expected
140 95adcdca 2019-03-27 stsp echo '+++ numbers' >> $testroot/stdout.expected
141 95adcdca 2019-03-27 stsp echo '@@ -1,5 +1,9 @@' >> $testroot/stdout.expected
142 95adcdca 2019-03-27 stsp echo ' 1' >> $testroot/stdout.expected
143 95adcdca 2019-03-27 stsp echo "+<<<<<<< commit $head_rev" >> $testroot/stdout.expected
144 95adcdca 2019-03-27 stsp echo ' 22' >> $testroot/stdout.expected
145 95adcdca 2019-03-27 stsp echo '+=======' >> $testroot/stdout.expected
146 95adcdca 2019-03-27 stsp echo '+77' >> $testroot/stdout.expected
147 95adcdca 2019-03-27 stsp echo '+>>>>>>> numbers' >> $testroot/stdout.expected
148 95adcdca 2019-03-27 stsp echo ' 3' >> $testroot/stdout.expected
149 95adcdca 2019-03-27 stsp echo ' 4' >> $testroot/stdout.expected
150 95adcdca 2019-03-27 stsp echo ' 5' >> $testroot/stdout.expected
152 95adcdca 2019-03-27 stsp (cd $testroot/wt && got diff > $testroot/stdout)
154 8d301dd9 2019-05-14 stsp cmp -s $testroot/stdout.expected $testroot/stdout
156 95adcdca 2019-03-27 stsp if [ "$ret" != "0" ]; then
157 95adcdca 2019-03-27 stsp diff -u $testroot/stdout.expected $testroot/stdout
159 95adcdca 2019-03-27 stsp test_done "$testroot" "$ret"
162 d24820bf 2019-08-11 stsp function test_diff_tag {
163 d24820bf 2019-08-11 stsp local testroot=`test_init diff_tag`
164 d24820bf 2019-08-11 stsp local commit_id0=`git_show_head $testroot/repo`
165 d24820bf 2019-08-11 stsp local tag1=1.0.0
166 d24820bf 2019-08-11 stsp local tag2=2.0.0
168 d24820bf 2019-08-11 stsp echo "modified alpha" > $testroot/repo/alpha
169 d24820bf 2019-08-11 stsp git_commit $testroot/repo -m "changed alpha"
170 d24820bf 2019-08-11 stsp local commit_id1=`git_show_head $testroot/repo`
172 d24820bf 2019-08-11 stsp (cd $testroot/repo && git tag -m "test" $tag1)
174 d24820bf 2019-08-11 stsp echo "new file" > $testroot/repo/new
175 d24820bf 2019-08-11 stsp (cd $testroot/repo && git add new)
176 d24820bf 2019-08-11 stsp git_commit $testroot/repo -m "new file"
177 d24820bf 2019-08-11 stsp local commit_id2=`git_show_head $testroot/repo`
179 d24820bf 2019-08-11 stsp (cd $testroot/repo && git tag -m "test" $tag2)
181 d24820bf 2019-08-11 stsp echo "diff $commit_id0 refs/tags/$tag1" > $testroot/stdout.expected
182 d24820bf 2019-08-11 stsp echo -n 'blob - ' >> $testroot/stdout.expected
183 d24820bf 2019-08-11 stsp got tree -r $testroot/repo -c $commit_id0 -i | grep 'alpha$' | \
184 d24820bf 2019-08-11 stsp cut -d' ' -f 1 >> $testroot/stdout.expected
185 d24820bf 2019-08-11 stsp echo -n 'blob + ' >> $testroot/stdout.expected
186 d24820bf 2019-08-11 stsp got tree -r $testroot/repo -i | grep 'alpha$' | cut -d' ' -f 1 \
187 d24820bf 2019-08-11 stsp >> $testroot/stdout.expected
188 d24820bf 2019-08-11 stsp echo '--- alpha' >> $testroot/stdout.expected
189 d24820bf 2019-08-11 stsp echo '+++ alpha' >> $testroot/stdout.expected
190 d24820bf 2019-08-11 stsp echo '@@ -1 +1 @@' >> $testroot/stdout.expected
191 d24820bf 2019-08-11 stsp echo '-alpha' >> $testroot/stdout.expected
192 d24820bf 2019-08-11 stsp echo '+modified alpha' >> $testroot/stdout.expected
194 d24820bf 2019-08-11 stsp got diff -r $testroot/repo $commit_id0 $tag1 > $testroot/stdout
195 d24820bf 2019-08-11 stsp cmp -s $testroot/stdout.expected $testroot/stdout
197 d24820bf 2019-08-11 stsp if [ "$ret" != "0" ]; then
198 d24820bf 2019-08-11 stsp diff -u $testroot/stdout.expected $testroot/stdout
199 d24820bf 2019-08-11 stsp test_done "$testroot" "$ret"
203 d24820bf 2019-08-11 stsp echo "diff refs/tags/$tag1 refs/tags/$tag2" > $testroot/stdout.expected
204 d24820bf 2019-08-11 stsp echo "blob - /dev/null" >> $testroot/stdout.expected
205 d24820bf 2019-08-11 stsp echo -n 'blob + ' >> $testroot/stdout.expected
206 d24820bf 2019-08-11 stsp got tree -r $testroot/repo -i -c $commit_id2 | grep 'new$' | \
207 d24820bf 2019-08-11 stsp cut -d' ' -f 1 >> $testroot/stdout.expected
208 d24820bf 2019-08-11 stsp echo '--- /dev/null' >> $testroot/stdout.expected
209 d24820bf 2019-08-11 stsp echo '+++ new' >> $testroot/stdout.expected
210 d24820bf 2019-08-11 stsp echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
211 d24820bf 2019-08-11 stsp echo '+new file' >> $testroot/stdout.expected
213 d24820bf 2019-08-11 stsp got diff -r $testroot/repo $tag1 $tag2 > $testroot/stdout
214 d24820bf 2019-08-11 stsp cmp -s $testroot/stdout.expected $testroot/stdout
216 d24820bf 2019-08-11 stsp if [ "$ret" != "0" ]; then
217 d24820bf 2019-08-11 stsp diff -u $testroot/stdout.expected $testroot/stdout
219 d24820bf 2019-08-11 stsp test_done "$testroot" "$ret"
222 95adcdca 2019-03-27 stsp run_test test_diff_basic
223 95adcdca 2019-03-27 stsp run_test test_diff_shows_conflict
224 d24820bf 2019-08-11 stsp run_test test_diff_tag