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_cat_basic {
20 local testroot=`test_init cat_basic`
21 local commit_id=`git_show_head $testroot/repo`
22 local author_time=`git_show_author_time $testroot/repo`
23 local alpha_id=`got tree -r $testroot/repo -i | grep 'alpha$' | cut -d' ' -f 1`
24 local gamma_id=`got tree -r $testroot/repo -i | grep 'gamma/$' | cut -d' ' -f 1`
25 local delta_id=`got tree -r $testroot/repo -i gamma | grep 'delta$' | cut -d' ' -f 1`
27 # cat blob
28 echo "alpha" > $testroot/stdout.expected
29 got cat -r $testroot/repo $alpha_id > $testroot/stdout
30 cmp -s $testroot/stdout.expected $testroot/stdout
31 ret="$?"
32 if [ "$ret" != "0" ]; then
33 diff -u $testroot/stdout.expected $testroot/stdout
34 test_done "$testroot" "$ret"
35 return 1
36 fi
38 # cat tree
39 echo "$delta_id 0100644 delta" > $testroot/stdout.expected
40 got cat -r $testroot/repo $gamma_id > $testroot/stdout
41 cmp -s $testroot/stdout.expected $testroot/stdout
42 ret="$?"
43 if [ "$ret" != "0" ]; then
44 diff -u $testroot/stdout.expected $testroot/stdout
45 test_done "$testroot" "$ret"
46 return 1
47 fi
49 # cat commit
50 echo -n "tree " > $testroot/stdout.expected
51 git_show_tree $testroot/repo >> $testroot/stdout.expected
52 echo >> $testroot/stdout.expected
53 echo "numparents 0" >> $testroot/stdout.expected
54 echo "author $GOT_AUTHOR $author_time +0000" >> $testroot/stdout.expected
55 echo "committer $GOT_AUTHOR $author_time +0000" \
56 >> $testroot/stdout.expected
57 echo "messagelen 22" >> $testroot/stdout.expected
58 printf "\nadding the test tree\n" >> $testroot/stdout.expected
60 got cat -r $testroot/repo $commit_id > $testroot/stdout
61 cmp -s $testroot/stdout.expected $testroot/stdout
62 ret="$?"
63 if [ "$ret" != "0" ]; then
64 diff -u $testroot/stdout.expected $testroot/stdout
65 test_done "$testroot" "$ret"
66 return 1
67 fi
69 # TODO: test cat tag
71 test_done "$testroot" "$ret"
73 }
75 function test_cat_path {
76 local testroot=`test_init cat_path`
77 local commit_id=`git_show_head $testroot/repo`
78 local author_time=`git_show_author_time $testroot/repo`
79 local alpha_id=`got tree -r $testroot/repo -i | grep 'alpha$' | cut -d' ' -f 1`
80 local gamma_id=`got tree -r $testroot/repo -i | grep 'gamma/$' | cut -d' ' -f 1`
81 local delta_id=`got tree -r $testroot/repo -i gamma | grep 'delta$' | cut -d' ' -f 1`
83 # cat blob by path
84 echo "alpha" > $testroot/stdout.expected
85 got cat -r $testroot/repo alpha > $testroot/stdout
86 cmp -s $testroot/stdout.expected $testroot/stdout
87 ret="$?"
88 if [ "$ret" != "0" ]; then
89 diff -u $testroot/stdout.expected $testroot/stdout
90 test_done "$testroot" "$ret"
91 return 1
92 fi
94 # cat tree by path
95 echo "$delta_id 0100644 delta" > $testroot/stdout.expected
96 got cat -r $testroot/repo gamma > $testroot/stdout
97 cmp -s $testroot/stdout.expected $testroot/stdout
98 ret="$?"
99 if [ "$ret" != "0" ]; then
100 diff -u $testroot/stdout.expected $testroot/stdout
101 test_done "$testroot" "$ret"
102 return 1
103 fi
105 (cd $testroot && got checkout repo wt > /dev/null)
106 echo "modified alpha" > $testroot/wt/alpha
107 (cd $testroot/wt && got commit -m "changed alpha" > /dev/null)
108 local commit_id2=`git_show_head $testroot/repo`
109 local author_time2=`git_show_author_time $testroot/repo`
110 local tree_commit2=`git_show_tree $testroot/repo`
112 # cat blob by path in specific commit
113 echo "alpha" > $testroot/stdout.expected
114 got cat -r $testroot/repo -c $commit_id alpha > $testroot/stdout
115 cmp -s $testroot/stdout.expected $testroot/stdout
116 ret="$?"
117 if [ "$ret" != "0" ]; then
118 diff -u $testroot/stdout.expected $testroot/stdout
119 test_done "$testroot" "$ret"
120 return 1
121 fi
122 echo "modified alpha" > $testroot/stdout.expected
123 got cat -r $testroot/repo -c $commit_id2 alpha > $testroot/stdout
124 cmp -s $testroot/stdout.expected $testroot/stdout
125 ret="$?"
126 if [ "$ret" != "0" ]; then
127 diff -u $testroot/stdout.expected $testroot/stdout
128 test_done "$testroot" "$ret"
129 return 1
130 fi
132 # resolve ambiguities between paths and other arguments
133 echo "new file called master" > $testroot/wt/master
134 echo "new file called $commit_id2" > $testroot/wt/$commit_id2
135 (cd $testroot/wt && got add master $commit_id2 > /dev/null)
136 (cd $testroot/wt && got commit -m "added clashing paths" > /dev/null)
137 local commit_id3=`git_show_head $testroot/repo`
138 local author_time3=`git_show_author_time $testroot/repo`
140 # references and object IDs override paths:
141 echo -n "tree " > $testroot/stdout.expected
142 git_show_tree $testroot/repo >> $testroot/stdout.expected
143 echo >> $testroot/stdout.expected
144 echo "numparents 1" >> $testroot/stdout.expected
145 echo "parent $commit_id2" >> $testroot/stdout.expected
146 echo "author $GOT_AUTHOR $author_time3 +0000" >> $testroot/stdout.expected
147 echo "committer $GOT_AUTHOR $author_time3 +0000" \
148 >> $testroot/stdout.expected
149 echo "messagelen 22" >> $testroot/stdout.expected
150 printf "\nadded clashing paths\n" >> $testroot/stdout.expected
152 for arg in master $commit_id3; do
153 got cat -r $testroot/repo $arg > $testroot/stdout
154 cmp -s $testroot/stdout.expected $testroot/stdout
155 ret="$?"
156 if [ "$ret" != "0" ]; then
157 diff -u $testroot/stdout.expected $testroot/stdout
158 test_done "$testroot" "$ret"
159 return 1
160 fi
161 done
163 echo "tree $tree_commit2" > $testroot/stdout.expected
164 echo "numparents 1" >> $testroot/stdout.expected
165 echo "parent $commit_id" >> $testroot/stdout.expected
166 echo "author $GOT_AUTHOR $author_time2 +0000" >> $testroot/stdout.expected
167 echo "committer $GOT_AUTHOR $author_time2 +0000" \
168 >> $testroot/stdout.expected
169 echo "messagelen 15" >> $testroot/stdout.expected
170 printf "\nchanged alpha\n" >> $testroot/stdout.expected
172 got cat -r $testroot/repo $commit_id2 > $testroot/stdout
173 cmp -s $testroot/stdout.expected $testroot/stdout
174 ret="$?"
175 if [ "$ret" != "0" ]; then
176 diff -u $testroot/stdout.expected $testroot/stdout
177 test_done "$testroot" "$ret"
178 return 1
179 fi
181 # force resolution of path 'master'
182 echo "new file called master" > $testroot/stdout.expected
183 got cat -r $testroot/repo -P master > $testroot/stdout
184 cmp -s $testroot/stdout.expected $testroot/stdout
185 ret="$?"
186 if [ "$ret" != "0" ]; then
187 diff -u $testroot/stdout.expected $testroot/stdout
188 test_done "$testroot" "$ret"
189 return 1
190 fi
192 # force resolution of path "$commit_id2"
193 echo "new file called $commit_id2" > $testroot/stdout.expected
194 got cat -r $testroot/repo -P $commit_id2 > $testroot/stdout
195 cmp -s $testroot/stdout.expected $testroot/stdout
196 ret="$?"
197 if [ "$ret" != "0" ]; then
198 diff -u $testroot/stdout.expected $testroot/stdout
199 test_done "$testroot" "$ret"
200 return 1
201 fi
202 test_done "$testroot" "$ret"
205 run_test test_cat_basic
206 run_test test_cat_path