Blame


1 95adcdca 2019-03-27 stsp #!/bin/sh
2 95adcdca 2019-03-27 stsp #
3 95adcdca 2019-03-27 stsp # Copyright (c) 2019 Stefan Sperling <stsp@openbsd.org>
4 95adcdca 2019-03-27 stsp #
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.
8 95adcdca 2019-03-27 stsp #
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.
16 95adcdca 2019-03-27 stsp
17 95adcdca 2019-03-27 stsp . ./common.sh
18 95adcdca 2019-03-27 stsp
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`
22 95adcdca 2019-03-27 stsp
23 95adcdca 2019-03-27 stsp got checkout $testroot/repo $testroot/wt > /dev/null
24 95adcdca 2019-03-27 stsp ret="$?"
25 95adcdca 2019-03-27 stsp if [ "$ret" != "0" ]; then
26 95adcdca 2019-03-27 stsp test_done "$testroot" "$ret"
27 95adcdca 2019-03-27 stsp return 1
28 95adcdca 2019-03-27 stsp fi
29 95adcdca 2019-03-27 stsp
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)
34 95adcdca 2019-03-27 stsp
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
59 95adcdca 2019-03-27 stsp
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
62 95adcdca 2019-03-27 stsp ret="$?"
63 95adcdca 2019-03-27 stsp if [ "$ret" != "0" ]; then
64 95adcdca 2019-03-27 stsp diff -u $testroot/stdout.expected $testroot/stdout
65 95adcdca 2019-03-27 stsp fi
66 95adcdca 2019-03-27 stsp test_done "$testroot" "$ret"
67 95adcdca 2019-03-27 stsp }
68 95adcdca 2019-03-27 stsp
69 95adcdca 2019-03-27 stsp function test_diff_shows_conflict {
70 95adcdca 2019-03-27 stsp local testroot=`test_init diff_shows_conflict 1`
71 95adcdca 2019-03-27 stsp
72 95adcdca 2019-03-27 stsp echo "1" > $testroot/repo/numbers
73 95adcdca 2019-03-27 stsp echo "2" >> $testroot/repo/numbers
74 95adcdca 2019-03-27 stsp echo "3" >> $testroot/repo/numbers
75 95adcdca 2019-03-27 stsp echo "4" >> $testroot/repo/numbers
76 95adcdca 2019-03-27 stsp echo "5" >> $testroot/repo/numbers
77 95adcdca 2019-03-27 stsp echo "6" >> $testroot/repo/numbers
78 95adcdca 2019-03-27 stsp echo "7" >> $testroot/repo/numbers
79 95adcdca 2019-03-27 stsp echo "8" >> $testroot/repo/numbers
80 95adcdca 2019-03-27 stsp (cd $testroot/repo && git add numbers)
81 95adcdca 2019-03-27 stsp git_commit $testroot/repo -m "added numbers file"
82 95adcdca 2019-03-27 stsp
83 95adcdca 2019-03-27 stsp got checkout $testroot/repo $testroot/wt > /dev/null
84 95adcdca 2019-03-27 stsp ret="$?"
85 95adcdca 2019-03-27 stsp if [ "$ret" != "0" ]; then
86 95adcdca 2019-03-27 stsp test_done "$testroot" "$ret"
87 95adcdca 2019-03-27 stsp return 1
88 95adcdca 2019-03-27 stsp fi
89 95adcdca 2019-03-27 stsp
90 95adcdca 2019-03-27 stsp sed -i 's/2/22/' $testroot/repo/numbers
91 95adcdca 2019-03-27 stsp git_commit $testroot/repo -m "modified line 2"
92 95adcdca 2019-03-27 stsp local head_rev=`git_show_head $testroot/repo`
93 95adcdca 2019-03-27 stsp
94 95adcdca 2019-03-27 stsp # modify line 2 in a conflicting way
95 95adcdca 2019-03-27 stsp sed -i 's/2/77/' $testroot/wt/numbers
96 95adcdca 2019-03-27 stsp
97 95adcdca 2019-03-27 stsp echo "C numbers" > $testroot/stdout.expected
98 95adcdca 2019-03-27 stsp echo -n "Updated to commit $head_rev" >> $testroot/stdout.expected
99 95adcdca 2019-03-27 stsp echo >> $testroot/stdout.expected
100 95adcdca 2019-03-27 stsp
101 95adcdca 2019-03-27 stsp (cd $testroot/wt && got update > $testroot/stdout)
102 95adcdca 2019-03-27 stsp
103 8d301dd9 2019-05-14 stsp cmp -s $testroot/stdout.expected $testroot/stdout
104 95adcdca 2019-03-27 stsp ret="$?"
105 95adcdca 2019-03-27 stsp if [ "$ret" != "0" ]; then
106 95adcdca 2019-03-27 stsp diff -u $testroot/stdout.expected $testroot/stdout
107 95adcdca 2019-03-27 stsp test_done "$testroot" "$ret"
108 95adcdca 2019-03-27 stsp return 1
109 95adcdca 2019-03-27 stsp fi
110 95adcdca 2019-03-27 stsp
111 95adcdca 2019-03-27 stsp echo "diff $head_rev $testroot/wt" > $testroot/stdout.expected
112 95adcdca 2019-03-27 stsp echo -n 'blob - ' >> $testroot/stdout.expected
113 95adcdca 2019-03-27 stsp got tree -r $testroot/repo -i | grep 'numbers$' | cut -d' ' -f 1 \
114 95adcdca 2019-03-27 stsp >> $testroot/stdout.expected
115 95adcdca 2019-03-27 stsp echo 'file + numbers' >> $testroot/stdout.expected
116 95adcdca 2019-03-27 stsp echo '--- numbers' >> $testroot/stdout.expected
117 95adcdca 2019-03-27 stsp echo '+++ numbers' >> $testroot/stdout.expected
118 95adcdca 2019-03-27 stsp echo '@@ -1,5 +1,9 @@' >> $testroot/stdout.expected
119 95adcdca 2019-03-27 stsp echo ' 1' >> $testroot/stdout.expected
120 95adcdca 2019-03-27 stsp echo "+<<<<<<< commit $head_rev" >> $testroot/stdout.expected
121 95adcdca 2019-03-27 stsp echo ' 22' >> $testroot/stdout.expected
122 95adcdca 2019-03-27 stsp echo '+=======' >> $testroot/stdout.expected
123 95adcdca 2019-03-27 stsp echo '+77' >> $testroot/stdout.expected
124 95adcdca 2019-03-27 stsp echo '+>>>>>>> numbers' >> $testroot/stdout.expected
125 95adcdca 2019-03-27 stsp echo ' 3' >> $testroot/stdout.expected
126 95adcdca 2019-03-27 stsp echo ' 4' >> $testroot/stdout.expected
127 95adcdca 2019-03-27 stsp echo ' 5' >> $testroot/stdout.expected
128 95adcdca 2019-03-27 stsp
129 95adcdca 2019-03-27 stsp (cd $testroot/wt && got diff > $testroot/stdout)
130 95adcdca 2019-03-27 stsp
131 8d301dd9 2019-05-14 stsp cmp -s $testroot/stdout.expected $testroot/stdout
132 95adcdca 2019-03-27 stsp ret="$?"
133 95adcdca 2019-03-27 stsp if [ "$ret" != "0" ]; then
134 95adcdca 2019-03-27 stsp diff -u $testroot/stdout.expected $testroot/stdout
135 95adcdca 2019-03-27 stsp fi
136 95adcdca 2019-03-27 stsp test_done "$testroot" "$ret"
137 95adcdca 2019-03-27 stsp }
138 95adcdca 2019-03-27 stsp
139 d24820bf 2019-08-11 stsp function test_diff_tag {
140 d24820bf 2019-08-11 stsp local testroot=`test_init diff_tag`
141 d24820bf 2019-08-11 stsp local commit_id0=`git_show_head $testroot/repo`
142 d24820bf 2019-08-11 stsp local tag1=1.0.0
143 d24820bf 2019-08-11 stsp local tag2=2.0.0
144 d24820bf 2019-08-11 stsp
145 d24820bf 2019-08-11 stsp echo "modified alpha" > $testroot/repo/alpha
146 d24820bf 2019-08-11 stsp git_commit $testroot/repo -m "changed alpha"
147 d24820bf 2019-08-11 stsp local commit_id1=`git_show_head $testroot/repo`
148 d24820bf 2019-08-11 stsp
149 d24820bf 2019-08-11 stsp (cd $testroot/repo && git tag -m "test" $tag1)
150 d24820bf 2019-08-11 stsp
151 d24820bf 2019-08-11 stsp echo "new file" > $testroot/repo/new
152 d24820bf 2019-08-11 stsp (cd $testroot/repo && git add new)
153 d24820bf 2019-08-11 stsp git_commit $testroot/repo -m "new file"
154 d24820bf 2019-08-11 stsp local commit_id2=`git_show_head $testroot/repo`
155 d24820bf 2019-08-11 stsp
156 d24820bf 2019-08-11 stsp (cd $testroot/repo && git tag -m "test" $tag2)
157 d24820bf 2019-08-11 stsp
158 d24820bf 2019-08-11 stsp echo "diff $commit_id0 refs/tags/$tag1" > $testroot/stdout.expected
159 d24820bf 2019-08-11 stsp echo -n 'blob - ' >> $testroot/stdout.expected
160 d24820bf 2019-08-11 stsp got tree -r $testroot/repo -c $commit_id0 -i | grep 'alpha$' | \
161 d24820bf 2019-08-11 stsp cut -d' ' -f 1 >> $testroot/stdout.expected
162 d24820bf 2019-08-11 stsp echo -n 'blob + ' >> $testroot/stdout.expected
163 d24820bf 2019-08-11 stsp got tree -r $testroot/repo -i | grep 'alpha$' | cut -d' ' -f 1 \
164 d24820bf 2019-08-11 stsp >> $testroot/stdout.expected
165 d24820bf 2019-08-11 stsp echo '--- alpha' >> $testroot/stdout.expected
166 d24820bf 2019-08-11 stsp echo '+++ alpha' >> $testroot/stdout.expected
167 d24820bf 2019-08-11 stsp echo '@@ -1 +1 @@' >> $testroot/stdout.expected
168 d24820bf 2019-08-11 stsp echo '-alpha' >> $testroot/stdout.expected
169 d24820bf 2019-08-11 stsp echo '+modified alpha' >> $testroot/stdout.expected
170 d24820bf 2019-08-11 stsp
171 d24820bf 2019-08-11 stsp got diff -r $testroot/repo $commit_id0 $tag1 > $testroot/stdout
172 d24820bf 2019-08-11 stsp cmp -s $testroot/stdout.expected $testroot/stdout
173 d24820bf 2019-08-11 stsp ret="$?"
174 d24820bf 2019-08-11 stsp if [ "$ret" != "0" ]; then
175 d24820bf 2019-08-11 stsp diff -u $testroot/stdout.expected $testroot/stdout
176 d24820bf 2019-08-11 stsp test_done "$testroot" "$ret"
177 d24820bf 2019-08-11 stsp return 1
178 d24820bf 2019-08-11 stsp fi
179 d24820bf 2019-08-11 stsp
180 d24820bf 2019-08-11 stsp echo "diff refs/tags/$tag1 refs/tags/$tag2" > $testroot/stdout.expected
181 d24820bf 2019-08-11 stsp echo "blob - /dev/null" >> $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 -i -c $commit_id2 | grep 'new$' | \
184 d24820bf 2019-08-11 stsp cut -d' ' -f 1 >> $testroot/stdout.expected
185 d24820bf 2019-08-11 stsp echo '--- /dev/null' >> $testroot/stdout.expected
186 d24820bf 2019-08-11 stsp echo '+++ new' >> $testroot/stdout.expected
187 d24820bf 2019-08-11 stsp echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
188 d24820bf 2019-08-11 stsp echo '+new file' >> $testroot/stdout.expected
189 d24820bf 2019-08-11 stsp
190 d24820bf 2019-08-11 stsp got diff -r $testroot/repo $tag1 $tag2 > $testroot/stdout
191 d24820bf 2019-08-11 stsp cmp -s $testroot/stdout.expected $testroot/stdout
192 d24820bf 2019-08-11 stsp ret="$?"
193 d24820bf 2019-08-11 stsp if [ "$ret" != "0" ]; then
194 d24820bf 2019-08-11 stsp diff -u $testroot/stdout.expected $testroot/stdout
195 d24820bf 2019-08-11 stsp fi
196 d24820bf 2019-08-11 stsp test_done "$testroot" "$ret"
197 d24820bf 2019-08-11 stsp }
198 d24820bf 2019-08-11 stsp
199 95adcdca 2019-03-27 stsp run_test test_diff_basic
200 95adcdca 2019-03-27 stsp run_test test_diff_shows_conflict
201 d24820bf 2019-08-11 stsp run_test test_diff_tag