Blame


1 01073a5d 2019-08-22 stsp #!/bin/sh
2 01073a5d 2019-08-22 stsp #
3 01073a5d 2019-08-22 stsp # Copyright (c) 2019 Stefan Sperling <stsp@openbsd.org>
4 01073a5d 2019-08-22 stsp #
5 01073a5d 2019-08-22 stsp # Permission to use, copy, modify, and distribute this software for any
6 01073a5d 2019-08-22 stsp # purpose with or without fee is hereby granted, provided that the above
7 01073a5d 2019-08-22 stsp # copyright notice and this permission notice appear in all copies.
8 01073a5d 2019-08-22 stsp #
9 01073a5d 2019-08-22 stsp # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 01073a5d 2019-08-22 stsp # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 01073a5d 2019-08-22 stsp # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 01073a5d 2019-08-22 stsp # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 01073a5d 2019-08-22 stsp # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 01073a5d 2019-08-22 stsp # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 01073a5d 2019-08-22 stsp # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 01073a5d 2019-08-22 stsp
17 01073a5d 2019-08-22 stsp . ./common.sh
18 01073a5d 2019-08-22 stsp
19 01073a5d 2019-08-22 stsp function test_cat_basic {
20 01073a5d 2019-08-22 stsp local testroot=`test_init cat_basic`
21 01073a5d 2019-08-22 stsp local commit_id=`git_show_head $testroot/repo`
22 01073a5d 2019-08-22 stsp local author_time=`git_show_author_time $testroot/repo`
23 01073a5d 2019-08-22 stsp local alpha_id=`got tree -r $testroot/repo -i | grep 'alpha$' | cut -d' ' -f 1`
24 01073a5d 2019-08-22 stsp local gamma_id=`got tree -r $testroot/repo -i | grep 'gamma/$' | cut -d' ' -f 1`
25 01073a5d 2019-08-22 stsp local delta_id=`got tree -r $testroot/repo -i gamma | grep 'delta$' | cut -d' ' -f 1`
26 01073a5d 2019-08-22 stsp
27 01073a5d 2019-08-22 stsp # cat blob
28 01073a5d 2019-08-22 stsp echo "alpha" > $testroot/stdout.expected
29 01073a5d 2019-08-22 stsp got cat -r $testroot/repo $alpha_id > $testroot/stdout
30 01073a5d 2019-08-22 stsp cmp -s $testroot/stdout.expected $testroot/stdout
31 01073a5d 2019-08-22 stsp ret="$?"
32 01073a5d 2019-08-22 stsp if [ "$ret" != "0" ]; then
33 01073a5d 2019-08-22 stsp diff -u $testroot/stdout.expected $testroot/stdout
34 01073a5d 2019-08-22 stsp test_done "$testroot" "$ret"
35 01073a5d 2019-08-22 stsp return 1
36 01073a5d 2019-08-22 stsp fi
37 01073a5d 2019-08-22 stsp
38 01073a5d 2019-08-22 stsp # cat tree
39 01073a5d 2019-08-22 stsp echo "$delta_id 0100644 delta" > $testroot/stdout.expected
40 01073a5d 2019-08-22 stsp got cat -r $testroot/repo $gamma_id > $testroot/stdout
41 01073a5d 2019-08-22 stsp cmp -s $testroot/stdout.expected $testroot/stdout
42 01073a5d 2019-08-22 stsp ret="$?"
43 01073a5d 2019-08-22 stsp if [ "$ret" != "0" ]; then
44 01073a5d 2019-08-22 stsp diff -u $testroot/stdout.expected $testroot/stdout
45 01073a5d 2019-08-22 stsp test_done "$testroot" "$ret"
46 01073a5d 2019-08-22 stsp return 1
47 01073a5d 2019-08-22 stsp fi
48 01073a5d 2019-08-22 stsp
49 01073a5d 2019-08-22 stsp # cat commit
50 8aa93786 2019-08-22 stsp echo -n "tree " > $testroot/stdout.expected
51 01073a5d 2019-08-22 stsp git_show_tree $testroot/repo >> $testroot/stdout.expected
52 01073a5d 2019-08-22 stsp echo >> $testroot/stdout.expected
53 8aa93786 2019-08-22 stsp echo "numparents 0" >> $testroot/stdout.expected
54 8aa93786 2019-08-22 stsp echo "author $GOT_AUTHOR $author_time +0000" >> $testroot/stdout.expected
55 896e9b6f 2019-08-26 stsp echo "committer $GOT_AUTHOR $author_time +0000" \
56 896e9b6f 2019-08-26 stsp >> $testroot/stdout.expected
57 8aa93786 2019-08-22 stsp echo "messagelen 22" >> $testroot/stdout.expected
58 01073a5d 2019-08-22 stsp printf "\nadding the test tree\n" >> $testroot/stdout.expected
59 01073a5d 2019-08-22 stsp
60 01073a5d 2019-08-22 stsp got cat -r $testroot/repo $commit_id > $testroot/stdout
61 01073a5d 2019-08-22 stsp cmp -s $testroot/stdout.expected $testroot/stdout
62 01073a5d 2019-08-22 stsp ret="$?"
63 01073a5d 2019-08-22 stsp if [ "$ret" != "0" ]; then
64 01073a5d 2019-08-22 stsp diff -u $testroot/stdout.expected $testroot/stdout
65 01073a5d 2019-08-22 stsp test_done "$testroot" "$ret"
66 01073a5d 2019-08-22 stsp return 1
67 01073a5d 2019-08-22 stsp fi
68 01073a5d 2019-08-22 stsp
69 01073a5d 2019-08-22 stsp # TODO: test cat tag
70 01073a5d 2019-08-22 stsp
71 01073a5d 2019-08-22 stsp test_done "$testroot" "$ret"
72 01073a5d 2019-08-22 stsp
73 01073a5d 2019-08-22 stsp }
74 01073a5d 2019-08-22 stsp
75 896e9b6f 2019-08-26 stsp function test_cat_path {
76 896e9b6f 2019-08-26 stsp local testroot=`test_init cat_path`
77 896e9b6f 2019-08-26 stsp local commit_id=`git_show_head $testroot/repo`
78 896e9b6f 2019-08-26 stsp local author_time=`git_show_author_time $testroot/repo`
79 896e9b6f 2019-08-26 stsp local alpha_id=`got tree -r $testroot/repo -i | grep 'alpha$' | cut -d' ' -f 1`
80 896e9b6f 2019-08-26 stsp local gamma_id=`got tree -r $testroot/repo -i | grep 'gamma/$' | cut -d' ' -f 1`
81 896e9b6f 2019-08-26 stsp local delta_id=`got tree -r $testroot/repo -i gamma | grep 'delta$' | cut -d' ' -f 1`
82 896e9b6f 2019-08-26 stsp
83 896e9b6f 2019-08-26 stsp # cat blob by path
84 896e9b6f 2019-08-26 stsp echo "alpha" > $testroot/stdout.expected
85 896e9b6f 2019-08-26 stsp got cat -r $testroot/repo alpha > $testroot/stdout
86 896e9b6f 2019-08-26 stsp cmp -s $testroot/stdout.expected $testroot/stdout
87 896e9b6f 2019-08-26 stsp ret="$?"
88 896e9b6f 2019-08-26 stsp if [ "$ret" != "0" ]; then
89 896e9b6f 2019-08-26 stsp diff -u $testroot/stdout.expected $testroot/stdout
90 896e9b6f 2019-08-26 stsp test_done "$testroot" "$ret"
91 896e9b6f 2019-08-26 stsp return 1
92 896e9b6f 2019-08-26 stsp fi
93 896e9b6f 2019-08-26 stsp
94 896e9b6f 2019-08-26 stsp # cat tree by path
95 896e9b6f 2019-08-26 stsp echo "$delta_id 0100644 delta" > $testroot/stdout.expected
96 896e9b6f 2019-08-26 stsp got cat -r $testroot/repo gamma > $testroot/stdout
97 896e9b6f 2019-08-26 stsp cmp -s $testroot/stdout.expected $testroot/stdout
98 896e9b6f 2019-08-26 stsp ret="$?"
99 896e9b6f 2019-08-26 stsp if [ "$ret" != "0" ]; then
100 896e9b6f 2019-08-26 stsp diff -u $testroot/stdout.expected $testroot/stdout
101 896e9b6f 2019-08-26 stsp test_done "$testroot" "$ret"
102 896e9b6f 2019-08-26 stsp return 1
103 896e9b6f 2019-08-26 stsp fi
104 896e9b6f 2019-08-26 stsp
105 896e9b6f 2019-08-26 stsp (cd $testroot && got checkout repo wt > /dev/null)
106 896e9b6f 2019-08-26 stsp echo "modified alpha" > $testroot/wt/alpha
107 896e9b6f 2019-08-26 stsp (cd $testroot/wt && got commit -m "changed alpha" > /dev/null)
108 896e9b6f 2019-08-26 stsp local commit_id2=`git_show_head $testroot/repo`
109 896e9b6f 2019-08-26 stsp local author_time2=`git_show_author_time $testroot/repo`
110 896e9b6f 2019-08-26 stsp local tree_commit2=`git_show_tree $testroot/repo`
111 896e9b6f 2019-08-26 stsp
112 896e9b6f 2019-08-26 stsp # cat blob by path in specific commit
113 896e9b6f 2019-08-26 stsp echo "alpha" > $testroot/stdout.expected
114 896e9b6f 2019-08-26 stsp got cat -r $testroot/repo -c $commit_id alpha > $testroot/stdout
115 896e9b6f 2019-08-26 stsp cmp -s $testroot/stdout.expected $testroot/stdout
116 896e9b6f 2019-08-26 stsp ret="$?"
117 896e9b6f 2019-08-26 stsp if [ "$ret" != "0" ]; then
118 896e9b6f 2019-08-26 stsp diff -u $testroot/stdout.expected $testroot/stdout
119 896e9b6f 2019-08-26 stsp test_done "$testroot" "$ret"
120 896e9b6f 2019-08-26 stsp return 1
121 896e9b6f 2019-08-26 stsp fi
122 896e9b6f 2019-08-26 stsp echo "modified alpha" > $testroot/stdout.expected
123 896e9b6f 2019-08-26 stsp got cat -r $testroot/repo -c $commit_id2 alpha > $testroot/stdout
124 896e9b6f 2019-08-26 stsp cmp -s $testroot/stdout.expected $testroot/stdout
125 896e9b6f 2019-08-26 stsp ret="$?"
126 896e9b6f 2019-08-26 stsp if [ "$ret" != "0" ]; then
127 896e9b6f 2019-08-26 stsp diff -u $testroot/stdout.expected $testroot/stdout
128 896e9b6f 2019-08-26 stsp test_done "$testroot" "$ret"
129 896e9b6f 2019-08-26 stsp return 1
130 896e9b6f 2019-08-26 stsp fi
131 896e9b6f 2019-08-26 stsp
132 896e9b6f 2019-08-26 stsp # resolve ambiguities between paths and other arguments
133 896e9b6f 2019-08-26 stsp echo "new file called master" > $testroot/wt/master
134 896e9b6f 2019-08-26 stsp echo "new file called $commit_id2" > $testroot/wt/$commit_id2
135 896e9b6f 2019-08-26 stsp (cd $testroot/wt && got add master $commit_id2 > /dev/null)
136 896e9b6f 2019-08-26 stsp (cd $testroot/wt && got commit -m "added clashing paths" > /dev/null)
137 896e9b6f 2019-08-26 stsp local commit_id3=`git_show_head $testroot/repo`
138 896e9b6f 2019-08-26 stsp local author_time3=`git_show_author_time $testroot/repo`
139 896e9b6f 2019-08-26 stsp
140 896e9b6f 2019-08-26 stsp # references and object IDs override paths:
141 896e9b6f 2019-08-26 stsp echo -n "tree " > $testroot/stdout.expected
142 896e9b6f 2019-08-26 stsp git_show_tree $testroot/repo >> $testroot/stdout.expected
143 896e9b6f 2019-08-26 stsp echo >> $testroot/stdout.expected
144 896e9b6f 2019-08-26 stsp echo "numparents 1" >> $testroot/stdout.expected
145 896e9b6f 2019-08-26 stsp echo "parent $commit_id2" >> $testroot/stdout.expected
146 896e9b6f 2019-08-26 stsp echo "author $GOT_AUTHOR $author_time3 +0000" >> $testroot/stdout.expected
147 896e9b6f 2019-08-26 stsp echo "committer $GOT_AUTHOR $author_time3 +0000" \
148 896e9b6f 2019-08-26 stsp >> $testroot/stdout.expected
149 896e9b6f 2019-08-26 stsp echo "messagelen 22" >> $testroot/stdout.expected
150 896e9b6f 2019-08-26 stsp printf "\nadded clashing paths\n" >> $testroot/stdout.expected
151 896e9b6f 2019-08-26 stsp
152 896e9b6f 2019-08-26 stsp for arg in master $commit_id3; do
153 896e9b6f 2019-08-26 stsp got cat -r $testroot/repo $arg > $testroot/stdout
154 896e9b6f 2019-08-26 stsp cmp -s $testroot/stdout.expected $testroot/stdout
155 896e9b6f 2019-08-26 stsp ret="$?"
156 896e9b6f 2019-08-26 stsp if [ "$ret" != "0" ]; then
157 896e9b6f 2019-08-26 stsp diff -u $testroot/stdout.expected $testroot/stdout
158 896e9b6f 2019-08-26 stsp test_done "$testroot" "$ret"
159 896e9b6f 2019-08-26 stsp return 1
160 896e9b6f 2019-08-26 stsp fi
161 896e9b6f 2019-08-26 stsp done
162 896e9b6f 2019-08-26 stsp
163 896e9b6f 2019-08-26 stsp echo "tree $tree_commit2" > $testroot/stdout.expected
164 896e9b6f 2019-08-26 stsp echo "numparents 1" >> $testroot/stdout.expected
165 896e9b6f 2019-08-26 stsp echo "parent $commit_id" >> $testroot/stdout.expected
166 896e9b6f 2019-08-26 stsp echo "author $GOT_AUTHOR $author_time2 +0000" >> $testroot/stdout.expected
167 896e9b6f 2019-08-26 stsp echo "committer $GOT_AUTHOR $author_time2 +0000" \
168 896e9b6f 2019-08-26 stsp >> $testroot/stdout.expected
169 896e9b6f 2019-08-26 stsp echo "messagelen 15" >> $testroot/stdout.expected
170 896e9b6f 2019-08-26 stsp printf "\nchanged alpha\n" >> $testroot/stdout.expected
171 896e9b6f 2019-08-26 stsp
172 896e9b6f 2019-08-26 stsp got cat -r $testroot/repo $commit_id2 > $testroot/stdout
173 896e9b6f 2019-08-26 stsp cmp -s $testroot/stdout.expected $testroot/stdout
174 896e9b6f 2019-08-26 stsp ret="$?"
175 896e9b6f 2019-08-26 stsp if [ "$ret" != "0" ]; then
176 896e9b6f 2019-08-26 stsp diff -u $testroot/stdout.expected $testroot/stdout
177 896e9b6f 2019-08-26 stsp test_done "$testroot" "$ret"
178 896e9b6f 2019-08-26 stsp return 1
179 896e9b6f 2019-08-26 stsp fi
180 896e9b6f 2019-08-26 stsp
181 896e9b6f 2019-08-26 stsp # force resolution of path 'master'
182 896e9b6f 2019-08-26 stsp echo "new file called master" > $testroot/stdout.expected
183 896e9b6f 2019-08-26 stsp got cat -r $testroot/repo -P master > $testroot/stdout
184 896e9b6f 2019-08-26 stsp cmp -s $testroot/stdout.expected $testroot/stdout
185 896e9b6f 2019-08-26 stsp ret="$?"
186 896e9b6f 2019-08-26 stsp if [ "$ret" != "0" ]; then
187 896e9b6f 2019-08-26 stsp diff -u $testroot/stdout.expected $testroot/stdout
188 896e9b6f 2019-08-26 stsp test_done "$testroot" "$ret"
189 896e9b6f 2019-08-26 stsp return 1
190 896e9b6f 2019-08-26 stsp fi
191 896e9b6f 2019-08-26 stsp
192 896e9b6f 2019-08-26 stsp # force resolution of path "$commit_id2"
193 896e9b6f 2019-08-26 stsp echo "new file called $commit_id2" > $testroot/stdout.expected
194 896e9b6f 2019-08-26 stsp got cat -r $testroot/repo -P $commit_id2 > $testroot/stdout
195 896e9b6f 2019-08-26 stsp cmp -s $testroot/stdout.expected $testroot/stdout
196 896e9b6f 2019-08-26 stsp ret="$?"
197 896e9b6f 2019-08-26 stsp if [ "$ret" != "0" ]; then
198 896e9b6f 2019-08-26 stsp diff -u $testroot/stdout.expected $testroot/stdout
199 896e9b6f 2019-08-26 stsp test_done "$testroot" "$ret"
200 896e9b6f 2019-08-26 stsp return 1
201 896e9b6f 2019-08-26 stsp fi
202 896e9b6f 2019-08-26 stsp test_done "$testroot" "$ret"
203 896e9b6f 2019-08-26 stsp }
204 896e9b6f 2019-08-26 stsp
205 01073a5d 2019-08-22 stsp run_test test_cat_basic
206 896e9b6f 2019-08-26 stsp run_test test_cat_path