Blame


1 234035bc 2019-06-01 stsp #!/bin/sh
2 234035bc 2019-06-01 stsp #
3 234035bc 2019-06-01 stsp # Copyright (c) 2019 Stefan Sperling <stsp@openbsd.org>
4 234035bc 2019-06-01 stsp #
5 234035bc 2019-06-01 stsp # Permission to use, copy, modify, and distribute this software for any
6 234035bc 2019-06-01 stsp # purpose with or without fee is hereby granted, provided that the above
7 234035bc 2019-06-01 stsp # copyright notice and this permission notice appear in all copies.
8 234035bc 2019-06-01 stsp #
9 234035bc 2019-06-01 stsp # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 234035bc 2019-06-01 stsp # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 234035bc 2019-06-01 stsp # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 234035bc 2019-06-01 stsp # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 234035bc 2019-06-01 stsp # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 234035bc 2019-06-01 stsp # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 234035bc 2019-06-01 stsp # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 234035bc 2019-06-01 stsp
17 234035bc 2019-06-01 stsp . ./common.sh
18 234035bc 2019-06-01 stsp
19 f6cae3ed 2020-09-13 naddy test_cherrypick_basic() {
20 234035bc 2019-06-01 stsp local testroot=`test_init cherrypick_basic`
21 234035bc 2019-06-01 stsp
22 234035bc 2019-06-01 stsp got checkout $testroot/repo $testroot/wt > /dev/null
23 234035bc 2019-06-01 stsp ret="$?"
24 234035bc 2019-06-01 stsp if [ "$ret" != "0" ]; then
25 234035bc 2019-06-01 stsp test_done "$testroot" "$ret"
26 234035bc 2019-06-01 stsp return 1
27 234035bc 2019-06-01 stsp fi
28 234035bc 2019-06-01 stsp
29 234035bc 2019-06-01 stsp (cd $testroot/repo && git checkout -q -b newbranch)
30 234035bc 2019-06-01 stsp echo "modified delta on branch" > $testroot/repo/gamma/delta
31 234035bc 2019-06-01 stsp git_commit $testroot/repo -m "committing to delta on newbranch"
32 234035bc 2019-06-01 stsp
33 234035bc 2019-06-01 stsp echo "modified alpha on branch" > $testroot/repo/alpha
34 234035bc 2019-06-01 stsp (cd $testroot/repo && git rm -q beta)
35 234035bc 2019-06-01 stsp echo "new file on branch" > $testroot/repo/epsilon/new
36 234035bc 2019-06-01 stsp (cd $testroot/repo && git add epsilon/new)
37 234035bc 2019-06-01 stsp git_commit $testroot/repo -m "committing more changes on newbranch"
38 234035bc 2019-06-01 stsp
39 234035bc 2019-06-01 stsp local branch_rev=`git_show_head $testroot/repo`
40 234035bc 2019-06-01 stsp
41 243a13f5 2021-09-02 stsp echo "modified new file on branch" > $testroot/repo/epsilon/new
42 243a13f5 2021-09-02 stsp git_commit $testroot/repo -m "committing more changes on newbranch"
43 243a13f5 2021-09-02 stsp local branch_rev2=`git_show_head $testroot/repo`
44 243a13f5 2021-09-02 stsp
45 234035bc 2019-06-01 stsp (cd $testroot/wt && got cherrypick $branch_rev > $testroot/stdout)
46 234035bc 2019-06-01 stsp
47 234035bc 2019-06-01 stsp echo "G alpha" > $testroot/stdout.expected
48 234035bc 2019-06-01 stsp echo "D beta" >> $testroot/stdout.expected
49 234035bc 2019-06-01 stsp echo "A epsilon/new" >> $testroot/stdout.expected
50 a7648d7a 2019-06-02 stsp echo "Merged commit $branch_rev" >> $testroot/stdout.expected
51 234035bc 2019-06-01 stsp
52 234035bc 2019-06-01 stsp cmp -s $testroot/stdout.expected $testroot/stdout
53 234035bc 2019-06-01 stsp ret="$?"
54 234035bc 2019-06-01 stsp if [ "$ret" != "0" ]; then
55 234035bc 2019-06-01 stsp diff -u $testroot/stdout.expected $testroot/stdout
56 234035bc 2019-06-01 stsp test_done "$testroot" "$ret"
57 234035bc 2019-06-01 stsp return 1
58 234035bc 2019-06-01 stsp fi
59 234035bc 2019-06-01 stsp
60 234035bc 2019-06-01 stsp echo "modified alpha on branch" > $testroot/content.expected
61 234035bc 2019-06-01 stsp cat $testroot/wt/alpha > $testroot/content
62 234035bc 2019-06-01 stsp cmp -s $testroot/content.expected $testroot/content
63 234035bc 2019-06-01 stsp ret="$?"
64 234035bc 2019-06-01 stsp if [ "$ret" != "0" ]; then
65 234035bc 2019-06-01 stsp diff -u $testroot/content.expected $testroot/content
66 234035bc 2019-06-01 stsp test_done "$testroot" "$ret"
67 234035bc 2019-06-01 stsp return 1
68 234035bc 2019-06-01 stsp fi
69 234035bc 2019-06-01 stsp
70 234035bc 2019-06-01 stsp if [ -e $testroot/wt/beta ]; then
71 234035bc 2019-06-01 stsp echo "removed file beta still exists on disk" >&2
72 234035bc 2019-06-01 stsp test_done "$testroot" "1"
73 234035bc 2019-06-01 stsp return 1
74 234035bc 2019-06-01 stsp fi
75 234035bc 2019-06-01 stsp
76 234035bc 2019-06-01 stsp echo "new file on branch" > $testroot/content.expected
77 234035bc 2019-06-01 stsp cat $testroot/wt/epsilon/new > $testroot/content
78 234035bc 2019-06-01 stsp cmp -s $testroot/content.expected $testroot/content
79 234035bc 2019-06-01 stsp ret="$?"
80 234035bc 2019-06-01 stsp if [ "$ret" != "0" ]; then
81 234035bc 2019-06-01 stsp diff -u $testroot/content.expected $testroot/content
82 234035bc 2019-06-01 stsp test_done "$testroot" "$ret"
83 234035bc 2019-06-01 stsp return 1
84 234035bc 2019-06-01 stsp fi
85 234035bc 2019-06-01 stsp
86 2b92fad7 2019-06-02 stsp echo 'M alpha' > $testroot/stdout.expected
87 2b92fad7 2019-06-02 stsp echo 'D beta' >> $testroot/stdout.expected
88 2b92fad7 2019-06-02 stsp echo 'A epsilon/new' >> $testroot/stdout.expected
89 2b92fad7 2019-06-02 stsp
90 2b92fad7 2019-06-02 stsp (cd $testroot/wt && got status > $testroot/stdout)
91 2b92fad7 2019-06-02 stsp
92 2b92fad7 2019-06-02 stsp cmp -s $testroot/stdout.expected $testroot/stdout
93 2b92fad7 2019-06-02 stsp ret="$?"
94 2b92fad7 2019-06-02 stsp if [ "$ret" != "0" ]; then
95 2b92fad7 2019-06-02 stsp diff -u $testroot/stdout.expected $testroot/stdout
96 243a13f5 2021-09-02 stsp test_done "$testroot" "$ret"
97 243a13f5 2021-09-02 stsp return 1
98 2b92fad7 2019-06-02 stsp fi
99 243a13f5 2021-09-02 stsp
100 243a13f5 2021-09-02 stsp (cd $testroot/wt && got cherrypick $branch_rev2 > $testroot/stdout)
101 243a13f5 2021-09-02 stsp
102 243a13f5 2021-09-02 stsp echo "G epsilon/new" > $testroot/stdout.expected
103 243a13f5 2021-09-02 stsp echo "Merged commit $branch_rev2" >> $testroot/stdout.expected
104 243a13f5 2021-09-02 stsp
105 243a13f5 2021-09-02 stsp cmp -s $testroot/stdout.expected $testroot/stdout
106 243a13f5 2021-09-02 stsp ret="$?"
107 243a13f5 2021-09-02 stsp if [ "$ret" != "0" ]; then
108 243a13f5 2021-09-02 stsp diff -u $testroot/stdout.expected $testroot/stdout
109 243a13f5 2021-09-02 stsp test_done "$testroot" "$ret"
110 243a13f5 2021-09-02 stsp return 1
111 243a13f5 2021-09-02 stsp fi
112 243a13f5 2021-09-02 stsp
113 243a13f5 2021-09-02 stsp echo 'M alpha' > $testroot/stdout.expected
114 243a13f5 2021-09-02 stsp echo 'D beta' >> $testroot/stdout.expected
115 243a13f5 2021-09-02 stsp echo 'A epsilon/new' >> $testroot/stdout.expected
116 243a13f5 2021-09-02 stsp
117 243a13f5 2021-09-02 stsp (cd $testroot/wt && got status > $testroot/stdout)
118 243a13f5 2021-09-02 stsp
119 243a13f5 2021-09-02 stsp cmp -s $testroot/stdout.expected $testroot/stdout
120 243a13f5 2021-09-02 stsp ret="$?"
121 243a13f5 2021-09-02 stsp if [ "$ret" != "0" ]; then
122 243a13f5 2021-09-02 stsp diff -u $testroot/stdout.expected $testroot/stdout
123 243a13f5 2021-09-02 stsp fi
124 234035bc 2019-06-01 stsp test_done "$testroot" "$ret"
125 234035bc 2019-06-01 stsp }
126 234035bc 2019-06-01 stsp
127 f6cae3ed 2020-09-13 naddy test_cherrypick_root_commit() {
128 03415a1a 2019-06-02 stsp local testroot=`test_init cherrypick_root_commit`
129 03415a1a 2019-06-02 stsp
130 03415a1a 2019-06-02 stsp got checkout $testroot/repo $testroot/wt > /dev/null
131 03415a1a 2019-06-02 stsp ret="$?"
132 03415a1a 2019-06-02 stsp if [ "$ret" != "0" ]; then
133 03415a1a 2019-06-02 stsp test_done "$testroot" "$ret"
134 03415a1a 2019-06-02 stsp return 1
135 03415a1a 2019-06-02 stsp fi
136 03415a1a 2019-06-02 stsp
137 03415a1a 2019-06-02 stsp (cd $testroot/repo && git checkout -q -b newbranch)
138 03415a1a 2019-06-02 stsp (cd $testroot/repo && git rm -q alpha)
139 03415a1a 2019-06-02 stsp (cd $testroot/repo && git rm -q beta)
140 03415a1a 2019-06-02 stsp (cd $testroot/repo && git rm -q epsilon/zeta)
141 03415a1a 2019-06-02 stsp (cd $testroot/repo && git rm -q gamma/delta)
142 03415a1a 2019-06-02 stsp mkdir -p $testroot/repo/epsilon
143 03415a1a 2019-06-02 stsp echo "new file on branch" > $testroot/repo/epsilon/new
144 03415a1a 2019-06-02 stsp (cd $testroot/repo && git add epsilon/new)
145 03415a1a 2019-06-02 stsp git_commit $testroot/repo -m "committing on newbranch"
146 03415a1a 2019-06-02 stsp
147 03415a1a 2019-06-02 stsp echo "modified new file on branch" >> $testroot/repo/epsilon/new
148 03415a1a 2019-06-02 stsp git_commit $testroot/repo -m "committing on newbranch again"
149 03415a1a 2019-06-02 stsp
150 03415a1a 2019-06-02 stsp tree=`git_show_tree $testroot/repo`
151 03415a1a 2019-06-02 stsp root_commit=`git_commit_tree $testroot/repo "new root commit" $tree`
152 03415a1a 2019-06-02 stsp
153 03415a1a 2019-06-02 stsp (cd $testroot/wt && got cherrypick $root_commit > $testroot/stdout)
154 03415a1a 2019-06-02 stsp
155 03415a1a 2019-06-02 stsp echo "A epsilon/new" > $testroot/stdout.expected
156 a7648d7a 2019-06-02 stsp echo "Merged commit $root_commit" >> $testroot/stdout.expected
157 03415a1a 2019-06-02 stsp
158 03415a1a 2019-06-02 stsp cmp -s $testroot/stdout.expected $testroot/stdout
159 03415a1a 2019-06-02 stsp ret="$?"
160 03415a1a 2019-06-02 stsp if [ "$ret" != "0" ]; then
161 03415a1a 2019-06-02 stsp diff -u $testroot/stdout.expected $testroot/stdout
162 03415a1a 2019-06-02 stsp test_done "$testroot" "$ret"
163 03415a1a 2019-06-02 stsp return 1
164 03415a1a 2019-06-02 stsp fi
165 03415a1a 2019-06-02 stsp
166 03415a1a 2019-06-02 stsp echo "new file on branch" > $testroot/content.expected
167 03415a1a 2019-06-02 stsp echo "modified new file on branch" >> $testroot/content.expected
168 03415a1a 2019-06-02 stsp cat $testroot/wt/epsilon/new > $testroot/content
169 03415a1a 2019-06-02 stsp cmp -s $testroot/content.expected $testroot/content
170 03415a1a 2019-06-02 stsp ret="$?"
171 03415a1a 2019-06-02 stsp if [ "$ret" != "0" ]; then
172 03415a1a 2019-06-02 stsp diff -u $testroot/content.expected $testroot/content
173 03415a1a 2019-06-02 stsp test_done "$testroot" "$ret"
174 03415a1a 2019-06-02 stsp return 1
175 03415a1a 2019-06-02 stsp fi
176 03415a1a 2019-06-02 stsp
177 03415a1a 2019-06-02 stsp echo 'A epsilon/new' > $testroot/stdout.expected
178 03415a1a 2019-06-02 stsp
179 03415a1a 2019-06-02 stsp (cd $testroot/wt && got status > $testroot/stdout)
180 03415a1a 2019-06-02 stsp
181 03415a1a 2019-06-02 stsp cmp -s $testroot/stdout.expected $testroot/stdout
182 03415a1a 2019-06-02 stsp ret="$?"
183 03415a1a 2019-06-02 stsp if [ "$ret" != "0" ]; then
184 03415a1a 2019-06-02 stsp diff -u $testroot/stdout.expected $testroot/stdout
185 03415a1a 2019-06-02 stsp fi
186 03415a1a 2019-06-02 stsp test_done "$testroot" "$ret"
187 03415a1a 2019-06-02 stsp }
188 03415a1a 2019-06-02 stsp
189 f6cae3ed 2020-09-13 naddy test_cherrypick_into_work_tree_with_conflicts() {
190 ceb466a7 2020-04-18 stsp local testroot=`test_init cherrypick_into_work_tree_with_conflicts`
191 ceb466a7 2020-04-18 stsp
192 ceb466a7 2020-04-18 stsp got checkout $testroot/repo $testroot/wt > /dev/null
193 ceb466a7 2020-04-18 stsp ret="$?"
194 ceb466a7 2020-04-18 stsp if [ "$ret" != "0" ]; then
195 ceb466a7 2020-04-18 stsp test_done "$testroot" "$ret"
196 ceb466a7 2020-04-18 stsp return 1
197 ceb466a7 2020-04-18 stsp fi
198 ceb466a7 2020-04-18 stsp
199 ceb466a7 2020-04-18 stsp (cd $testroot/repo && git checkout -q -b newbranch)
200 ceb466a7 2020-04-18 stsp echo "modified delta on branch" > $testroot/repo/gamma/delta
201 ceb466a7 2020-04-18 stsp git_commit $testroot/repo -m "committing to delta on newbranch"
202 ceb466a7 2020-04-18 stsp
203 ceb466a7 2020-04-18 stsp echo "modified alpha on branch" > $testroot/repo/alpha
204 ceb466a7 2020-04-18 stsp (cd $testroot/repo && git rm -q beta)
205 ceb466a7 2020-04-18 stsp echo "new file on branch" > $testroot/repo/epsilon/new
206 ceb466a7 2020-04-18 stsp (cd $testroot/repo && git add epsilon/new)
207 ceb466a7 2020-04-18 stsp git_commit $testroot/repo -m "committing more changes on newbranch"
208 ceb466a7 2020-04-18 stsp
209 ceb466a7 2020-04-18 stsp local branch_rev=`git_show_head $testroot/repo`
210 ceb466a7 2020-04-18 stsp
211 ceb466a7 2020-04-18 stsp # fake a merge conflict
212 ceb466a7 2020-04-18 stsp echo '<<<<<<<' > $testroot/wt/alpha
213 ceb466a7 2020-04-18 stsp echo 'alpha' >> $testroot/wt/alpha
214 ceb466a7 2020-04-18 stsp echo '=======' >> $testroot/wt/alpha
215 ceb466a7 2020-04-18 stsp echo 'alpha, too' >> $testroot/wt/alpha
216 ceb466a7 2020-04-18 stsp echo '>>>>>>>' >> $testroot/wt/alpha
217 ceb466a7 2020-04-18 stsp cp $testroot/wt/alpha $testroot/content.expected
218 ceb466a7 2020-04-18 stsp
219 ceb466a7 2020-04-18 stsp echo "C alpha" > $testroot/stdout.expected
220 ceb466a7 2020-04-18 stsp (cd $testroot/wt && got status > $testroot/stdout)
221 ceb466a7 2020-04-18 stsp cmp -s $testroot/stdout.expected $testroot/stdout
222 ceb466a7 2020-04-18 stsp ret="$?"
223 ceb466a7 2020-04-18 stsp if [ "$ret" != "0" ]; then
224 ceb466a7 2020-04-18 stsp diff -u $testroot/stdout.expected $testroot/stdout
225 ceb466a7 2020-04-18 stsp test_done "$testroot" "$ret"
226 ceb466a7 2020-04-18 stsp return 1
227 ceb466a7 2020-04-18 stsp fi
228 ceb466a7 2020-04-18 stsp
229 ceb466a7 2020-04-18 stsp (cd $testroot/wt && got cherrypick $branch_rev \
230 ceb466a7 2020-04-18 stsp > $testroot/stdout 2> $testroot/stderr)
231 ceb466a7 2020-04-18 stsp ret="$?"
232 54c39596 2020-12-28 stsp if [ "$ret" = "0" ]; then
233 ceb466a7 2020-04-18 stsp echo "cherrypick succeeded unexpectedly" >&2
234 ceb466a7 2020-04-18 stsp test_done "$testroot" "1"
235 ceb466a7 2020-04-18 stsp return 1
236 ceb466a7 2020-04-18 stsp fi
237 ceb466a7 2020-04-18 stsp
238 ceb466a7 2020-04-18 stsp echo -n > $testroot/stdout.expected
239 ceb466a7 2020-04-18 stsp echo -n "got: work tree contains conflicted files; " \
240 ceb466a7 2020-04-18 stsp > $testroot/stderr.expected
241 ceb466a7 2020-04-18 stsp echo "these conflicts must be resolved first" \
242 ceb466a7 2020-04-18 stsp >> $testroot/stderr.expected
243 ceb466a7 2020-04-18 stsp
244 ceb466a7 2020-04-18 stsp cmp -s $testroot/stdout.expected $testroot/stdout
245 ceb466a7 2020-04-18 stsp ret="$?"
246 ceb466a7 2020-04-18 stsp if [ "$ret" != "0" ]; then
247 ceb466a7 2020-04-18 stsp diff -u $testroot/stdout.expected $testroot/stdout
248 ceb466a7 2020-04-18 stsp test_done "$testroot" "$ret"
249 ceb466a7 2020-04-18 stsp return 1
250 ceb466a7 2020-04-18 stsp fi
251 ceb466a7 2020-04-18 stsp
252 ceb466a7 2020-04-18 stsp cmp -s $testroot/stderr.expected $testroot/stderr
253 ceb466a7 2020-04-18 stsp ret="$?"
254 ceb466a7 2020-04-18 stsp if [ "$ret" != "0" ]; then
255 ceb466a7 2020-04-18 stsp diff -u $testroot/stderr.expected $testroot/stderr
256 ceb466a7 2020-04-18 stsp test_done "$testroot" "$ret"
257 ceb466a7 2020-04-18 stsp return 1
258 ceb466a7 2020-04-18 stsp fi
259 ceb466a7 2020-04-18 stsp
260 ceb466a7 2020-04-18 stsp cmp -s $testroot/content.expected $testroot/wt/alpha
261 ceb466a7 2020-04-18 stsp ret="$?"
262 ceb466a7 2020-04-18 stsp if [ "$ret" != "0" ]; then
263 ceb466a7 2020-04-18 stsp diff -u $testroot/content.expected $testroot/wt/alpha
264 e7303626 2020-05-14 stsp fi
265 e7303626 2020-05-14 stsp test_done "$testroot" "$ret"
266 e7303626 2020-05-14 stsp }
267 ed99f061 2021-09-03 stsp
268 ed99f061 2021-09-03 stsp test_cherrypick_into_work_tree_with_mixed_commits() {
269 ed99f061 2021-09-03 stsp local testroot=`test_init cherrypick_into_work_tree_with_mixed_commits`
270 ed99f061 2021-09-03 stsp local first_rev=`git_show_head $testroot/repo`
271 ed99f061 2021-09-03 stsp
272 ed99f061 2021-09-03 stsp echo "modified alpha" > $testroot/repo/alpha
273 ed99f061 2021-09-03 stsp git_commit $testroot/repo -m "committing to alpha"
274 ed99f061 2021-09-03 stsp local second_rev=`git_show_head $testroot/repo`
275 ed99f061 2021-09-03 stsp
276 ed99f061 2021-09-03 stsp got checkout $testroot/repo $testroot/wt > /dev/null
277 ed99f061 2021-09-03 stsp ret="$?"
278 ed99f061 2021-09-03 stsp if [ "$ret" != "0" ]; then
279 ed99f061 2021-09-03 stsp test_done "$testroot" "$ret"
280 ed99f061 2021-09-03 stsp return 1
281 ed99f061 2021-09-03 stsp fi
282 ed99f061 2021-09-03 stsp
283 ed99f061 2021-09-03 stsp (cd $testroot/repo && git checkout -q -b newbranch)
284 ed99f061 2021-09-03 stsp echo "modified delta on branch" > $testroot/repo/gamma/delta
285 ed99f061 2021-09-03 stsp git_commit $testroot/repo -m "committing to delta on newbranch"
286 e7303626 2020-05-14 stsp
287 ed99f061 2021-09-03 stsp (cd $testroot/repo && git rm -q beta)
288 ed99f061 2021-09-03 stsp echo "new file on branch" > $testroot/repo/epsilon/new
289 ed99f061 2021-09-03 stsp (cd $testroot/repo && git add epsilon/new)
290 ed99f061 2021-09-03 stsp git_commit $testroot/repo -m "committing more changes on newbranch"
291 ed99f061 2021-09-03 stsp
292 ed99f061 2021-09-03 stsp local branch_rev=`git_show_head $testroot/repo`
293 ed99f061 2021-09-03 stsp
294 ed99f061 2021-09-03 stsp (cd $testroot/wt && got update -c $first_rev alpha >/dev/null)
295 ed99f061 2021-09-03 stsp
296 ed99f061 2021-09-03 stsp (cd $testroot/wt && got cherrypick $branch_rev \
297 ed99f061 2021-09-03 stsp > $testroot/stdout 2> $testroot/stderr)
298 ed99f061 2021-09-03 stsp ret="$?"
299 ed99f061 2021-09-03 stsp if [ "$ret" = "0" ]; then
300 ed99f061 2021-09-03 stsp echo "cherrypick succeeded unexpectedly" >&2
301 ed99f061 2021-09-03 stsp test_done "$testroot" "1"
302 ed99f061 2021-09-03 stsp return 1
303 ed99f061 2021-09-03 stsp fi
304 ed99f061 2021-09-03 stsp
305 ed99f061 2021-09-03 stsp echo -n > $testroot/stdout.expected
306 ed99f061 2021-09-03 stsp echo -n "got: work tree contains files from multiple base commits; " \
307 ed99f061 2021-09-03 stsp > $testroot/stderr.expected
308 ed99f061 2021-09-03 stsp echo "the entire work tree must be updated first" \
309 ed99f061 2021-09-03 stsp >> $testroot/stderr.expected
310 ed99f061 2021-09-03 stsp
311 ed99f061 2021-09-03 stsp cmp -s $testroot/stdout.expected $testroot/stdout
312 ed99f061 2021-09-03 stsp ret="$?"
313 ed99f061 2021-09-03 stsp if [ "$ret" != "0" ]; then
314 ed99f061 2021-09-03 stsp diff -u $testroot/stdout.expected $testroot/stdout
315 ed99f061 2021-09-03 stsp test_done "$testroot" "$ret"
316 ed99f061 2021-09-03 stsp return 1
317 ed99f061 2021-09-03 stsp fi
318 ed99f061 2021-09-03 stsp
319 ed99f061 2021-09-03 stsp cmp -s $testroot/stderr.expected $testroot/stderr
320 ed99f061 2021-09-03 stsp ret="$?"
321 ed99f061 2021-09-03 stsp if [ "$ret" != "0" ]; then
322 ed99f061 2021-09-03 stsp diff -u $testroot/stderr.expected $testroot/stderr
323 ed99f061 2021-09-03 stsp fi
324 ed99f061 2021-09-03 stsp test_done "$testroot" "$ret"
325 ed99f061 2021-09-03 stsp
326 ed99f061 2021-09-03 stsp }
327 ed99f061 2021-09-03 stsp
328 f6cae3ed 2020-09-13 naddy test_cherrypick_modified_submodule() {
329 e7303626 2020-05-14 stsp local testroot=`test_init cherrypick_modified_submodules`
330 e7303626 2020-05-14 stsp
331 e7303626 2020-05-14 stsp make_single_file_repo $testroot/repo2 foo
332 e7303626 2020-05-14 stsp
333 e7303626 2020-05-14 stsp (cd $testroot/repo && git submodule -q add ../repo2)
334 e7303626 2020-05-14 stsp (cd $testroot/repo && git commit -q -m 'adding submodule')
335 e7303626 2020-05-14 stsp
336 e7303626 2020-05-14 stsp got checkout $testroot/repo $testroot/wt > /dev/null
337 e7303626 2020-05-14 stsp
338 e7303626 2020-05-14 stsp echo "modified foo" > $testroot/repo2/foo
339 e7303626 2020-05-14 stsp (cd $testroot/repo2 && git commit -q -a -m 'modified a submodule')
340 e7303626 2020-05-14 stsp
341 e7303626 2020-05-14 stsp (cd $testroot/repo && git checkout -q -b newbranch)
342 e7303626 2020-05-14 stsp # Update the repo/repo2 submodule link on newbranch
343 e7303626 2020-05-14 stsp (cd $testroot/repo && git -C repo2 pull -q)
344 e7303626 2020-05-14 stsp (cd $testroot/repo && git add repo2)
345 e7303626 2020-05-14 stsp git_commit $testroot/repo -m "modified submodule link"
346 e7303626 2020-05-14 stsp local commit_id=`git_show_head $testroot/repo`
347 e7303626 2020-05-14 stsp
348 e7303626 2020-05-14 stsp # This cherrypick is a no-op because Got's file index
349 e7303626 2020-05-14 stsp # does not track submodules.
350 e7303626 2020-05-14 stsp (cd $testroot/wt && got cherrypick $commit_id > $testroot/stdout)
351 e7303626 2020-05-14 stsp
352 e7303626 2020-05-14 stsp echo -n > $testroot/stdout.expected
353 e7303626 2020-05-14 stsp cmp -s $testroot/stdout.expected $testroot/stdout
354 e7303626 2020-05-14 stsp ret="$?"
355 e7303626 2020-05-14 stsp if [ "$ret" != "0" ]; then
356 e7303626 2020-05-14 stsp diff -u $testroot/stdout.expected $testroot/stdout
357 e7303626 2020-05-14 stsp fi
358 e7303626 2020-05-14 stsp test_done "$testroot" "$ret"
359 e7303626 2020-05-14 stsp }
360 e7303626 2020-05-14 stsp
361 f6cae3ed 2020-09-13 naddy test_cherrypick_added_submodule() {
362 e7303626 2020-05-14 stsp local testroot=`test_init cherrypick_added_submodules`
363 e7303626 2020-05-14 stsp
364 e7303626 2020-05-14 stsp got checkout $testroot/repo $testroot/wt > /dev/null
365 e7303626 2020-05-14 stsp
366 e7303626 2020-05-14 stsp make_single_file_repo $testroot/repo2 foo
367 e7303626 2020-05-14 stsp
368 e7303626 2020-05-14 stsp # Add the repo/repo2 submodule on newbranch
369 e7303626 2020-05-14 stsp (cd $testroot/repo && git checkout -q -b newbranch)
370 e7303626 2020-05-14 stsp (cd $testroot/repo && git submodule -q add ../repo2)
371 e7303626 2020-05-14 stsp (cd $testroot/repo && git commit -q -m 'adding submodule')
372 e7303626 2020-05-14 stsp local commit_id=`git_show_head $testroot/repo`
373 e7303626 2020-05-14 stsp
374 e7303626 2020-05-14 stsp (cd $testroot/wt && got cherrypick $commit_id > $testroot/stdout)
375 e7303626 2020-05-14 stsp
376 e7303626 2020-05-14 stsp echo "A .gitmodules" > $testroot/stdout.expected
377 e7303626 2020-05-14 stsp echo "Merged commit $commit_id" >> $testroot/stdout.expected
378 e7303626 2020-05-14 stsp cmp -s $testroot/stdout.expected $testroot/stdout
379 e7303626 2020-05-14 stsp ret="$?"
380 e7303626 2020-05-14 stsp if [ "$ret" != "0" ]; then
381 e7303626 2020-05-14 stsp diff -u $testroot/stdout.expected $testroot/stdout
382 ceb466a7 2020-04-18 stsp fi
383 ceb466a7 2020-04-18 stsp test_done "$testroot" "$ret"
384 ceb466a7 2020-04-18 stsp }
385 ceb466a7 2020-04-18 stsp
386 f6cae3ed 2020-09-13 naddy test_cherrypick_conflict_wt_file_vs_repo_submodule() {
387 e7303626 2020-05-14 stsp local testroot=`test_init cherrypick_conflict_wt_file_vs_repo_submodule`
388 e7303626 2020-05-14 stsp
389 e7303626 2020-05-14 stsp got checkout $testroot/repo $testroot/wt > /dev/null
390 e7303626 2020-05-14 stsp
391 e7303626 2020-05-14 stsp # Add a file which will clash with the submodule
392 e7303626 2020-05-14 stsp echo "This is a file called repo2" > $testroot/wt/repo2
393 e7303626 2020-05-14 stsp (cd $testroot/wt && got add repo2 > /dev/null)
394 e7303626 2020-05-14 stsp (cd $testroot/wt && got commit -m 'add file repo2' > /dev/null)
395 e7303626 2020-05-14 stsp ret="$?"
396 e7303626 2020-05-14 stsp if [ "$ret" != "0" ]; then
397 e7303626 2020-05-14 stsp echo "commit failed unexpectedly" >&2
398 e7303626 2020-05-14 stsp test_done "$testroot" "1"
399 e7303626 2020-05-14 stsp return 1
400 e7303626 2020-05-14 stsp fi
401 e7303626 2020-05-14 stsp
402 e7303626 2020-05-14 stsp make_single_file_repo $testroot/repo2 foo
403 e7303626 2020-05-14 stsp
404 e7303626 2020-05-14 stsp # Add the repo/repo2 submodule on newbranch
405 e7303626 2020-05-14 stsp (cd $testroot/repo && git checkout -q -b newbranch)
406 e7303626 2020-05-14 stsp (cd $testroot/repo && git submodule -q add ../repo2)
407 e7303626 2020-05-14 stsp (cd $testroot/repo && git commit -q -m 'adding submodule')
408 e7303626 2020-05-14 stsp local commit_id=`git_show_head $testroot/repo`
409 e7303626 2020-05-14 stsp
410 e7303626 2020-05-14 stsp # Modify the clashing file such that any modifications brought
411 e7303626 2020-05-14 stsp # in by 'got cherrypick' would require a merge.
412 e7303626 2020-05-14 stsp echo "This file was changed" > $testroot/wt/repo2
413 e7303626 2020-05-14 stsp
414 e7303626 2020-05-14 stsp (cd $testroot/wt && got update >/dev/null)
415 e7303626 2020-05-14 stsp (cd $testroot/wt && got cherrypick $commit_id > $testroot/stdout)
416 e7303626 2020-05-14 stsp
417 e7303626 2020-05-14 stsp echo "A .gitmodules" > $testroot/stdout.expected
418 e7303626 2020-05-14 stsp echo "Merged commit $commit_id" >> $testroot/stdout.expected
419 e7303626 2020-05-14 stsp cmp -s $testroot/stdout.expected $testroot/stdout
420 e7303626 2020-05-14 stsp ret="$?"
421 e7303626 2020-05-14 stsp if [ "$ret" != "0" ]; then
422 e7303626 2020-05-14 stsp diff -u $testroot/stdout.expected $testroot/stdout
423 e7303626 2020-05-14 stsp test_done "$testroot" "$ret"
424 e7303626 2020-05-14 stsp return 1
425 e7303626 2020-05-14 stsp fi
426 e7303626 2020-05-14 stsp
427 e7303626 2020-05-14 stsp (cd $testroot/wt && got status > $testroot/stdout)
428 e7303626 2020-05-14 stsp
429 e7303626 2020-05-14 stsp echo "A .gitmodules" > $testroot/stdout.expected
430 e7303626 2020-05-14 stsp echo "M repo2" >> $testroot/stdout.expected
431 e7303626 2020-05-14 stsp cmp -s $testroot/stdout.expected $testroot/stdout
432 e7303626 2020-05-14 stsp ret="$?"
433 e7303626 2020-05-14 stsp if [ "$ret" != "0" ]; then
434 e7303626 2020-05-14 stsp diff -u $testroot/stdout.expected $testroot/stdout
435 e7303626 2020-05-14 stsp fi
436 e7303626 2020-05-14 stsp test_done "$testroot" "$ret"
437 af57b12a 2020-07-23 stsp }
438 af57b12a 2020-07-23 stsp
439 f6cae3ed 2020-09-13 naddy test_cherrypick_modified_symlinks() {
440 af57b12a 2020-07-23 stsp local testroot=`test_init cherrypick_modified_symlinks`
441 af57b12a 2020-07-23 stsp
442 af57b12a 2020-07-23 stsp (cd $testroot/repo && ln -s alpha alpha.link)
443 af57b12a 2020-07-23 stsp (cd $testroot/repo && ln -s epsilon epsilon.link)
444 af57b12a 2020-07-23 stsp (cd $testroot/repo && ln -s /etc/passwd passwd.link)
445 af57b12a 2020-07-23 stsp (cd $testroot/repo && ln -s ../beta epsilon/beta.link)
446 af57b12a 2020-07-23 stsp (cd $testroot/repo && ln -s nonexistent nonexistent.link)
447 af57b12a 2020-07-23 stsp (cd $testroot/repo && git add .)
448 af57b12a 2020-07-23 stsp git_commit $testroot/repo -m "add symlinks"
449 af57b12a 2020-07-23 stsp local commit_id1=`git_show_head $testroot/repo`
450 af57b12a 2020-07-23 stsp
451 ace90326 2021-09-27 thomas got tree -r $testroot/repo -R -c $commit_id1 \
452 ace90326 2021-09-27 thomas > $testroot/stdout
453 ace90326 2021-09-27 thomas cat > $testroot/stdout.expected <<EOF
454 ace90326 2021-09-27 thomas alpha
455 ace90326 2021-09-27 thomas alpha.link@ -> alpha
456 ace90326 2021-09-27 thomas beta
457 ace90326 2021-09-27 thomas epsilon/
458 ace90326 2021-09-27 thomas epsilon/beta.link@ -> ../beta
459 ace90326 2021-09-27 thomas epsilon/zeta
460 ace90326 2021-09-27 thomas epsilon.link@ -> epsilon
461 ace90326 2021-09-27 thomas gamma/
462 ace90326 2021-09-27 thomas gamma/delta
463 ace90326 2021-09-27 thomas nonexistent.link@ -> nonexistent
464 ace90326 2021-09-27 thomas passwd.link@ -> /etc/passwd
465 ace90326 2021-09-27 thomas EOF
466 ace90326 2021-09-27 thomas cmp -s $testroot/stdout.expected $testroot/stdout
467 ace90326 2021-09-27 thomas ret="$?"
468 ace90326 2021-09-27 thomas if [ "$ret" != "0" ]; then
469 ace90326 2021-09-27 thomas diff -u $testroot/stdout.expected $testroot/stdout
470 ace90326 2021-09-27 thomas test_done "$testroot" "$ret"
471 ace90326 2021-09-27 thomas return 1
472 ace90326 2021-09-27 thomas fi
473 ace90326 2021-09-27 thomas
474 af57b12a 2020-07-23 stsp got branch -r $testroot/repo foo
475 af57b12a 2020-07-23 stsp
476 af57b12a 2020-07-23 stsp got checkout -b foo $testroot/repo $testroot/wt > /dev/null
477 af57b12a 2020-07-23 stsp
478 af57b12a 2020-07-23 stsp (cd $testroot/repo && ln -sf beta alpha.link)
479 dd6165e4 2021-09-21 thomas.ad (cd $testroot/repo && ln -sfT gamma epsilon.link)
480 af57b12a 2020-07-23 stsp (cd $testroot/repo && ln -sf ../gamma/delta epsilon/beta.link)
481 ace90326 2021-09-27 thomas (cd $testroot/repo && ln -sf .got/foo $testroot/repo/dotgotfoo.link)
482 af57b12a 2020-07-23 stsp (cd $testroot/repo && git rm -q nonexistent.link)
483 af57b12a 2020-07-23 stsp (cd $testroot/repo && ln -sf epsilon/zeta zeta.link)
484 af57b12a 2020-07-23 stsp (cd $testroot/repo && git add .)
485 af57b12a 2020-07-23 stsp git_commit $testroot/repo -m "change symlinks"
486 af57b12a 2020-07-23 stsp local commit_id2=`git_show_head $testroot/repo`
487 af57b12a 2020-07-23 stsp
488 af57b12a 2020-07-23 stsp (cd $testroot/wt && got cherrypick $commit_id2 > $testroot/stdout)
489 af57b12a 2020-07-23 stsp
490 af57b12a 2020-07-23 stsp echo "G alpha.link" > $testroot/stdout.expected
491 af57b12a 2020-07-23 stsp echo "G epsilon/beta.link" >> $testroot/stdout.expected
492 af57b12a 2020-07-23 stsp echo "A dotgotfoo.link" >> $testroot/stdout.expected
493 af57b12a 2020-07-23 stsp echo "G epsilon.link" >> $testroot/stdout.expected
494 af57b12a 2020-07-23 stsp echo "D nonexistent.link" >> $testroot/stdout.expected
495 af57b12a 2020-07-23 stsp echo "A zeta.link" >> $testroot/stdout.expected
496 af57b12a 2020-07-23 stsp echo "Merged commit $commit_id2" >> $testroot/stdout.expected
497 af57b12a 2020-07-23 stsp cmp -s $testroot/stdout.expected $testroot/stdout
498 af57b12a 2020-07-23 stsp ret="$?"
499 af57b12a 2020-07-23 stsp if [ "$ret" != "0" ]; then
500 af57b12a 2020-07-23 stsp diff -u $testroot/stdout.expected $testroot/stdout
501 af57b12a 2020-07-23 stsp test_done "$testroot" "$ret"
502 af57b12a 2020-07-23 stsp return 1
503 af57b12a 2020-07-23 stsp fi
504 af57b12a 2020-07-23 stsp
505 af57b12a 2020-07-23 stsp if ! [ -h $testroot/wt/alpha.link ]; then
506 af57b12a 2020-07-23 stsp echo "alpha.link is not a symlink"
507 af57b12a 2020-07-23 stsp test_done "$testroot" "1"
508 af57b12a 2020-07-23 stsp return 1
509 af57b12a 2020-07-23 stsp fi
510 af57b12a 2020-07-23 stsp
511 af57b12a 2020-07-23 stsp readlink $testroot/wt/alpha.link > $testroot/stdout
512 af57b12a 2020-07-23 stsp echo "beta" > $testroot/stdout.expected
513 af57b12a 2020-07-23 stsp cmp -s $testroot/stdout.expected $testroot/stdout
514 af57b12a 2020-07-23 stsp ret="$?"
515 af57b12a 2020-07-23 stsp if [ "$ret" != "0" ]; then
516 af57b12a 2020-07-23 stsp diff -u $testroot/stdout.expected $testroot/stdout
517 af57b12a 2020-07-23 stsp test_done "$testroot" "$ret"
518 af57b12a 2020-07-23 stsp return 1
519 af57b12a 2020-07-23 stsp fi
520 af57b12a 2020-07-23 stsp
521 ace90326 2021-09-27 thomas if ! [ -h $testroot/wt/dotgotfoo.link ]; then
522 ace90326 2021-09-27 thomas echo "dotgotfoo.link is not a symlink"
523 ace90326 2021-09-27 thomas test_done "$testroot" "1"
524 ace90326 2021-09-27 thomas return 1
525 ace90326 2021-09-27 thomas fi
526 ace90326 2021-09-27 thomas
527 ace90326 2021-09-27 thomas readlink $testroot/wt/dotgotfoo.link > $testroot/stdout
528 ace90326 2021-09-27 thomas echo ".got/foo" > $testroot/stdout.expected
529 ace90326 2021-09-27 thomas cmp -s $testroot/stdout.expected $testroot/stdout
530 ace90326 2021-09-27 thomas ret="$?"
531 ace90326 2021-09-27 thomas if [ "$ret" != "0" ]; then
532 ace90326 2021-09-27 thomas diff -u $testroot/stdout.expected $testroot/stdout
533 ace90326 2021-09-27 thomas test_done "$testroot" "$ret"
534 ace90326 2021-09-27 thomas return 1
535 ace90326 2021-09-27 thomas fi
536 ace90326 2021-09-27 thomas
537 af57b12a 2020-07-23 stsp if ! [ -h $testroot/wt/epsilon.link ]; then
538 af57b12a 2020-07-23 stsp echo "epsilon.link is not a symlink"
539 af57b12a 2020-07-23 stsp test_done "$testroot" "1"
540 af57b12a 2020-07-23 stsp return 1
541 af57b12a 2020-07-23 stsp fi
542 af57b12a 2020-07-23 stsp
543 af57b12a 2020-07-23 stsp readlink $testroot/wt/epsilon.link > $testroot/stdout
544 af57b12a 2020-07-23 stsp echo "gamma" > $testroot/stdout.expected
545 af57b12a 2020-07-23 stsp cmp -s $testroot/stdout.expected $testroot/stdout
546 af57b12a 2020-07-23 stsp ret="$?"
547 af57b12a 2020-07-23 stsp if [ "$ret" != "0" ]; then
548 af57b12a 2020-07-23 stsp diff -u $testroot/stdout.expected $testroot/stdout
549 af57b12a 2020-07-23 stsp test_done "$testroot" "$ret"
550 af57b12a 2020-07-23 stsp return 1
551 af57b12a 2020-07-23 stsp fi
552 af57b12a 2020-07-23 stsp
553 af57b12a 2020-07-23 stsp if [ -h $testroot/wt/passwd.link ]; then
554 af57b12a 2020-07-23 stsp echo -n "passwd.link symlink points outside of work tree: " >&2
555 af57b12a 2020-07-23 stsp readlink $testroot/wt/passwd.link >&2
556 af57b12a 2020-07-23 stsp test_done "$testroot" "1"
557 af57b12a 2020-07-23 stsp return 1
558 af57b12a 2020-07-23 stsp fi
559 af57b12a 2020-07-23 stsp
560 af57b12a 2020-07-23 stsp echo -n "/etc/passwd" > $testroot/content.expected
561 af57b12a 2020-07-23 stsp cp $testroot/wt/passwd.link $testroot/content
562 af57b12a 2020-07-23 stsp
563 af57b12a 2020-07-23 stsp cmp -s $testroot/content.expected $testroot/content
564 af57b12a 2020-07-23 stsp ret="$?"
565 af57b12a 2020-07-23 stsp if [ "$ret" != "0" ]; then
566 af57b12a 2020-07-23 stsp diff -u $testroot/content.expected $testroot/content
567 af57b12a 2020-07-23 stsp test_done "$testroot" "$ret"
568 af57b12a 2020-07-23 stsp return 1
569 af57b12a 2020-07-23 stsp fi
570 af57b12a 2020-07-23 stsp
571 af57b12a 2020-07-23 stsp readlink $testroot/wt/epsilon/beta.link > $testroot/stdout
572 af57b12a 2020-07-23 stsp echo "../gamma/delta" > $testroot/stdout.expected
573 e26bafba 2020-07-23 stsp cmp -s $testroot/stdout.expected $testroot/stdout
574 e26bafba 2020-07-23 stsp ret="$?"
575 e26bafba 2020-07-23 stsp if [ "$ret" != "0" ]; then
576 e26bafba 2020-07-23 stsp diff -u $testroot/stdout.expected $testroot/stdout
577 e26bafba 2020-07-23 stsp test_done "$testroot" "$ret"
578 e26bafba 2020-07-23 stsp return 1
579 e26bafba 2020-07-23 stsp fi
580 e26bafba 2020-07-23 stsp
581 e26bafba 2020-07-23 stsp if [ -h $testroot/wt/nonexistent.link ]; then
582 e26bafba 2020-07-23 stsp echo -n "nonexistent.link still exists on disk: " >&2
583 e26bafba 2020-07-23 stsp readlink $testroot/wt/nonexistent.link >&2
584 e26bafba 2020-07-23 stsp test_done "$testroot" "1"
585 e26bafba 2020-07-23 stsp return 1
586 e26bafba 2020-07-23 stsp fi
587 e26bafba 2020-07-23 stsp
588 ace90326 2021-09-27 thomas (cd $testroot/wt && got commit -m 'commit cherrypick result' \
589 ace90326 2021-09-27 thomas > /dev/null 2>$testroot/stderr)
590 ace90326 2021-09-27 thomas ret="$?"
591 ace90326 2021-09-27 thomas if [ "$ret" == "0" ]; then
592 ace90326 2021-09-27 thomas echo "got commit succeeded unexpectedly" >&2
593 ace90326 2021-09-27 thomas test_done "$testroot" "$ret"
594 ace90326 2021-09-27 thomas return 1
595 ace90326 2021-09-27 thomas fi
596 ace90326 2021-09-27 thomas echo -n "got: $testroot/wt/dotgotfoo.link: symbolic link points " \
597 ace90326 2021-09-27 thomas > $testroot/stderr.expected
598 ace90326 2021-09-27 thomas echo "outside of paths under version control" \
599 ace90326 2021-09-27 thomas >> $testroot/stderr.expected
600 ace90326 2021-09-27 thomas cmp -s $testroot/stderr.expected $testroot/stderr
601 ace90326 2021-09-27 thomas ret="$?"
602 ace90326 2021-09-27 thomas if [ "$ret" != "0" ]; then
603 ace90326 2021-09-27 thomas diff -u $testroot/stderr.expected $testroot/stderr
604 ace90326 2021-09-27 thomas test_done "$testroot" "$ret"
605 ace90326 2021-09-27 thomas return 1
606 ace90326 2021-09-27 thomas fi
607 ace90326 2021-09-27 thomas
608 ace90326 2021-09-27 thomas (cd $testroot/wt && got commit -S -m 'commit cherrypick result' \
609 ace90326 2021-09-27 thomas > /dev/null)
610 ace90326 2021-09-27 thomas ret="$?"
611 ace90326 2021-09-27 thomas if [ "$ret" != "0" ]; then
612 ace90326 2021-09-27 thomas echo "got commit failed unexpectedly" >&2
613 ace90326 2021-09-27 thomas test_done "$testroot" "$ret"
614 ace90326 2021-09-27 thomas return 1
615 ace90326 2021-09-27 thomas fi
616 ace90326 2021-09-27 thomas local commit_id2=`git_show_head $testroot/repo`
617 ace90326 2021-09-27 thomas
618 ace90326 2021-09-27 thomas got tree -r $testroot/repo -R -c $commit_id2 \
619 ace90326 2021-09-27 thomas > $testroot/stdout
620 ace90326 2021-09-27 thomas cat > $testroot/stdout.expected <<EOF
621 ace90326 2021-09-27 thomas alpha
622 ace90326 2021-09-27 thomas alpha.link@ -> beta
623 ace90326 2021-09-27 thomas beta
624 ace90326 2021-09-27 thomas dotgotfoo.link@ -> .got/foo
625 ace90326 2021-09-27 thomas epsilon/
626 ace90326 2021-09-27 thomas epsilon/beta.link@ -> ../gamma/delta
627 ace90326 2021-09-27 thomas epsilon/zeta
628 ace90326 2021-09-27 thomas epsilon.link@ -> gamma
629 ace90326 2021-09-27 thomas gamma/
630 ace90326 2021-09-27 thomas gamma/delta
631 ace90326 2021-09-27 thomas passwd.link@ -> /etc/passwd
632 ace90326 2021-09-27 thomas zeta.link@ -> epsilon/zeta
633 ace90326 2021-09-27 thomas EOF
634 ace90326 2021-09-27 thomas cmp -s $testroot/stdout.expected $testroot/stdout
635 ace90326 2021-09-27 thomas ret="$?"
636 ace90326 2021-09-27 thomas if [ "$ret" != "0" ]; then
637 ace90326 2021-09-27 thomas diff -u $testroot/stdout.expected $testroot/stdout
638 ace90326 2021-09-27 thomas fi
639 ace90326 2021-09-27 thomas test_done "$testroot" "$ret"
640 e26bafba 2020-07-23 stsp }
641 e26bafba 2020-07-23 stsp
642 f6cae3ed 2020-09-13 naddy test_cherrypick_symlink_conflicts() {
643 e26bafba 2020-07-23 stsp local testroot=`test_init cherrypick_symlink_conflicts`
644 e26bafba 2020-07-23 stsp
645 e26bafba 2020-07-23 stsp (cd $testroot/repo && ln -s alpha alpha.link)
646 e26bafba 2020-07-23 stsp (cd $testroot/repo && ln -s epsilon epsilon.link)
647 e26bafba 2020-07-23 stsp (cd $testroot/repo && ln -s /etc/passwd passwd.link)
648 e26bafba 2020-07-23 stsp (cd $testroot/repo && ln -s ../beta epsilon/beta.link)
649 e26bafba 2020-07-23 stsp (cd $testroot/repo && ln -s nonexistent nonexistent.link)
650 e26bafba 2020-07-23 stsp (cd $testroot/repo && ln -sf epsilon/zeta zeta.link)
651 e26bafba 2020-07-23 stsp (cd $testroot/repo && git add .)
652 e26bafba 2020-07-23 stsp git_commit $testroot/repo -m "add symlinks"
653 e26bafba 2020-07-23 stsp local commit_id1=`git_show_head $testroot/repo`
654 e26bafba 2020-07-23 stsp
655 e26bafba 2020-07-23 stsp (cd $testroot/repo && ln -sf beta alpha.link)
656 fba9f79c 2020-07-23 stsp (cd $testroot/repo && ln -sf beta boo.link)
657 dd6165e4 2021-09-21 thomas.ad (cd $testroot/repo && ln -sfT gamma epsilon.link)
658 e26bafba 2020-07-23 stsp (cd $testroot/repo && ln -sf ../gamma/delta epsilon/beta.link)
659 e26bafba 2020-07-23 stsp echo 'this is regular file foo' > $testroot/repo/dotgotfoo.link
660 e26bafba 2020-07-23 stsp (cd $testroot/repo && ln -sf .got/bar dotgotbar.link)
661 e26bafba 2020-07-23 stsp (cd $testroot/repo && git rm -q nonexistent.link)
662 e26bafba 2020-07-23 stsp (cd $testroot/repo && ln -sf gamma/delta zeta.link)
663 e26bafba 2020-07-23 stsp (cd $testroot/repo && ln -sf alpha new.link)
664 e26bafba 2020-07-23 stsp (cd $testroot/repo && git add .)
665 e26bafba 2020-07-23 stsp git_commit $testroot/repo -m "change symlinks"
666 e26bafba 2020-07-23 stsp local commit_id2=`git_show_head $testroot/repo`
667 e26bafba 2020-07-23 stsp
668 e26bafba 2020-07-23 stsp got branch -r $testroot/repo -c $commit_id1 foo
669 e26bafba 2020-07-23 stsp got checkout -b foo $testroot/repo $testroot/wt > /dev/null
670 e26bafba 2020-07-23 stsp
671 e26bafba 2020-07-23 stsp # modified symlink to file A vs modified symlink to file B
672 e26bafba 2020-07-23 stsp (cd $testroot/wt && ln -sf gamma/delta alpha.link)
673 e26bafba 2020-07-23 stsp # modified symlink to dir A vs modified symlink to file B
674 dd6165e4 2021-09-21 thomas.ad (cd $testroot/wt && ln -sfT beta epsilon.link)
675 e26bafba 2020-07-23 stsp # modeified symlink to file A vs modified symlink to dir B
676 dd6165e4 2021-09-21 thomas.ad (cd $testroot/wt && ln -sfT ../gamma epsilon/beta.link)
677 e26bafba 2020-07-23 stsp # added regular file A vs added bad symlink to file A
678 ace90326 2021-09-27 thomas (cd $testroot/wt && ln -sf .got/foo dotgotfoo.link)
679 3b9f0f87 2020-07-23 stsp (cd $testroot/wt && got add dotgotfoo.link > /dev/null)
680 e26bafba 2020-07-23 stsp # added bad symlink to file A vs added regular file A
681 e26bafba 2020-07-23 stsp echo 'this is regular file bar' > $testroot/wt/dotgotbar.link
682 d219f183 2020-07-23 stsp (cd $testroot/wt && got add dotgotbar.link > /dev/null)
683 fba9f79c 2020-07-23 stsp # added symlink to file A vs unversioned file A
684 fba9f79c 2020-07-23 stsp echo 'this is unversioned file boo' > $testroot/wt/boo.link
685 e26bafba 2020-07-23 stsp # removed symlink to non-existent file A vs modified symlink
686 e26bafba 2020-07-23 stsp # to nonexistent file B
687 e26bafba 2020-07-23 stsp (cd $testroot/wt && ln -sf nonexistent2 nonexistent.link)
688 e26bafba 2020-07-23 stsp # modified symlink to file A vs removed symlink to file A
689 e26bafba 2020-07-23 stsp (cd $testroot/wt && got rm zeta.link > /dev/null)
690 e26bafba 2020-07-23 stsp # added symlink to file A vs added symlink to file B
691 e26bafba 2020-07-23 stsp (cd $testroot/wt && ln -sf beta new.link)
692 e26bafba 2020-07-23 stsp (cd $testroot/wt && got add new.link > /dev/null)
693 35213c7c 2020-07-23 stsp (cd $testroot/wt && got commit -S -m "change symlinks on foo" \
694 e26bafba 2020-07-23 stsp > /dev/null)
695 e26bafba 2020-07-23 stsp
696 e26bafba 2020-07-23 stsp (cd $testroot/wt && got update >/dev/null)
697 e26bafba 2020-07-23 stsp (cd $testroot/wt && got cherrypick $commit_id2 > $testroot/stdout)
698 e26bafba 2020-07-23 stsp
699 e26bafba 2020-07-23 stsp echo -n > $testroot/stdout.expected
700 11cc08c1 2020-07-23 stsp echo "C alpha.link" >> $testroot/stdout.expected
701 11cc08c1 2020-07-23 stsp echo "C epsilon/beta.link" >> $testroot/stdout.expected
702 c90c8ce3 2020-07-23 stsp echo "? boo.link" >> $testroot/stdout.expected
703 11cc08c1 2020-07-23 stsp echo "C epsilon.link" >> $testroot/stdout.expected
704 fba9f79c 2020-07-23 stsp echo "C dotgotbar.link" >> $testroot/stdout.expected
705 3b9f0f87 2020-07-23 stsp echo "C dotgotfoo.link" >> $testroot/stdout.expected
706 e26bafba 2020-07-23 stsp echo "D nonexistent.link" >> $testroot/stdout.expected
707 e26bafba 2020-07-23 stsp echo "! zeta.link" >> $testroot/stdout.expected
708 11cc08c1 2020-07-23 stsp echo "C new.link" >> $testroot/stdout.expected
709 e26bafba 2020-07-23 stsp echo "Merged commit $commit_id2" >> $testroot/stdout.expected
710 3b9f0f87 2020-07-23 stsp echo "Files with new merge conflicts: 6" >> $testroot/stdout.expected
711 0ef68859 2021-09-28 thomas echo -n "Files which had incoming changes but could not be found " \
712 0ef68859 2021-09-28 thomas >> $testroot/stdout.expected
713 0ef68859 2021-09-28 thomas echo "in the work tree: 1" >> $testroot/stdout.expected
714 0ef68859 2021-09-28 thomas echo -n "Files not merged because an unversioned file was found in " \
715 0ef68859 2021-09-28 thomas >> $testroot/stdout.expected
716 0ef68859 2021-09-28 thomas echo "the work tree: 1" >> $testroot/stdout.expected
717 e26bafba 2020-07-23 stsp cmp -s $testroot/stdout.expected $testroot/stdout
718 e26bafba 2020-07-23 stsp ret="$?"
719 e26bafba 2020-07-23 stsp if [ "$ret" != "0" ]; then
720 e26bafba 2020-07-23 stsp diff -u $testroot/stdout.expected $testroot/stdout
721 e26bafba 2020-07-23 stsp test_done "$testroot" "$ret"
722 e26bafba 2020-07-23 stsp return 1
723 e26bafba 2020-07-23 stsp fi
724 e26bafba 2020-07-23 stsp
725 11cc08c1 2020-07-23 stsp if [ -h $testroot/wt/alpha.link ]; then
726 11cc08c1 2020-07-23 stsp echo "alpha.link is a symlink"
727 e26bafba 2020-07-23 stsp test_done "$testroot" "1"
728 e26bafba 2020-07-23 stsp return 1
729 e26bafba 2020-07-23 stsp fi
730 e26bafba 2020-07-23 stsp
731 11cc08c1 2020-07-23 stsp echo "<<<<<<< merged change: commit $commit_id2" \
732 283102fc 2020-07-23 stsp > $testroot/content.expected
733 11cc08c1 2020-07-23 stsp echo "beta" >> $testroot/content.expected
734 11cc08c1 2020-07-23 stsp echo "3-way merge base: commit $commit_id1" \
735 11cc08c1 2020-07-23 stsp >> $testroot/content.expected
736 11cc08c1 2020-07-23 stsp echo "alpha" >> $testroot/content.expected
737 11cc08c1 2020-07-23 stsp echo "=======" >> $testroot/content.expected
738 11cc08c1 2020-07-23 stsp echo "gamma/delta" >> $testroot/content.expected
739 11cc08c1 2020-07-23 stsp echo '>>>>>>>' >> $testroot/content.expected
740 11cc08c1 2020-07-23 stsp echo -n "" >> $testroot/content.expected
741 11cc08c1 2020-07-23 stsp
742 11cc08c1 2020-07-23 stsp cp $testroot/wt/alpha.link $testroot/content
743 fba9f79c 2020-07-23 stsp cmp -s $testroot/content.expected $testroot/content
744 fba9f79c 2020-07-23 stsp ret="$?"
745 fba9f79c 2020-07-23 stsp if [ "$ret" != "0" ]; then
746 fba9f79c 2020-07-23 stsp diff -u $testroot/content.expected $testroot/content
747 fba9f79c 2020-07-23 stsp test_done "$testroot" "$ret"
748 fba9f79c 2020-07-23 stsp return 1
749 fba9f79c 2020-07-23 stsp fi
750 fba9f79c 2020-07-23 stsp
751 c90c8ce3 2020-07-23 stsp if [ -h $testroot/wt/boo.link ]; then
752 c90c8ce3 2020-07-23 stsp echo "boo.link is a symlink"
753 fba9f79c 2020-07-23 stsp test_done "$testroot" "1"
754 fba9f79c 2020-07-23 stsp return 1
755 fba9f79c 2020-07-23 stsp fi
756 fba9f79c 2020-07-23 stsp
757 c90c8ce3 2020-07-23 stsp echo "this is unversioned file boo" > $testroot/content.expected
758 fba9f79c 2020-07-23 stsp cp $testroot/wt/boo.link $testroot/content
759 11cc08c1 2020-07-23 stsp cmp -s $testroot/content.expected $testroot/content
760 e26bafba 2020-07-23 stsp ret="$?"
761 e26bafba 2020-07-23 stsp if [ "$ret" != "0" ]; then
762 11cc08c1 2020-07-23 stsp diff -u $testroot/content.expected $testroot/content
763 e26bafba 2020-07-23 stsp test_done "$testroot" "$ret"
764 e26bafba 2020-07-23 stsp return 1
765 e26bafba 2020-07-23 stsp fi
766 e26bafba 2020-07-23 stsp
767 11cc08c1 2020-07-23 stsp if [ -h $testroot/wt/epsilon.link ]; then
768 11cc08c1 2020-07-23 stsp echo "epsilon.link is a symlink"
769 e26bafba 2020-07-23 stsp test_done "$testroot" "1"
770 e26bafba 2020-07-23 stsp return 1
771 e26bafba 2020-07-23 stsp fi
772 e26bafba 2020-07-23 stsp
773 11cc08c1 2020-07-23 stsp echo "<<<<<<< merged change: commit $commit_id2" \
774 283102fc 2020-07-23 stsp > $testroot/content.expected
775 11cc08c1 2020-07-23 stsp echo "gamma" >> $testroot/content.expected
776 11cc08c1 2020-07-23 stsp echo "3-way merge base: commit $commit_id1" \
777 11cc08c1 2020-07-23 stsp >> $testroot/content.expected
778 11cc08c1 2020-07-23 stsp echo "epsilon" >> $testroot/content.expected
779 11cc08c1 2020-07-23 stsp echo "=======" >> $testroot/content.expected
780 11cc08c1 2020-07-23 stsp echo "beta" >> $testroot/content.expected
781 11cc08c1 2020-07-23 stsp echo '>>>>>>>' >> $testroot/content.expected
782 11cc08c1 2020-07-23 stsp echo -n "" >> $testroot/content.expected
783 11cc08c1 2020-07-23 stsp
784 11cc08c1 2020-07-23 stsp cp $testroot/wt/epsilon.link $testroot/content
785 11cc08c1 2020-07-23 stsp cmp -s $testroot/content.expected $testroot/content
786 af57b12a 2020-07-23 stsp ret="$?"
787 af57b12a 2020-07-23 stsp if [ "$ret" != "0" ]; then
788 11cc08c1 2020-07-23 stsp diff -u $testroot/content.expected $testroot/content
789 af57b12a 2020-07-23 stsp test_done "$testroot" "$ret"
790 af57b12a 2020-07-23 stsp return 1
791 af57b12a 2020-07-23 stsp fi
792 af57b12a 2020-07-23 stsp
793 e26bafba 2020-07-23 stsp if [ -h $testroot/wt/passwd.link ]; then
794 e26bafba 2020-07-23 stsp echo -n "passwd.link symlink points outside of work tree: " >&2
795 e26bafba 2020-07-23 stsp readlink $testroot/wt/passwd.link >&2
796 e26bafba 2020-07-23 stsp test_done "$testroot" "1"
797 e26bafba 2020-07-23 stsp return 1
798 e26bafba 2020-07-23 stsp fi
799 e26bafba 2020-07-23 stsp
800 e26bafba 2020-07-23 stsp echo -n "/etc/passwd" > $testroot/content.expected
801 e26bafba 2020-07-23 stsp cp $testroot/wt/passwd.link $testroot/content
802 e26bafba 2020-07-23 stsp
803 e26bafba 2020-07-23 stsp cmp -s $testroot/content.expected $testroot/content
804 e26bafba 2020-07-23 stsp ret="$?"
805 e26bafba 2020-07-23 stsp if [ "$ret" != "0" ]; then
806 e26bafba 2020-07-23 stsp diff -u $testroot/content.expected $testroot/content
807 e26bafba 2020-07-23 stsp test_done "$testroot" "$ret"
808 e26bafba 2020-07-23 stsp return 1
809 e26bafba 2020-07-23 stsp fi
810 e26bafba 2020-07-23 stsp
811 11cc08c1 2020-07-23 stsp if [ -h $testroot/wt/epsilon/beta.link ]; then
812 11cc08c1 2020-07-23 stsp echo "epsilon/beta.link is a symlink"
813 11cc08c1 2020-07-23 stsp test_done "$testroot" "1"
814 11cc08c1 2020-07-23 stsp return 1
815 11cc08c1 2020-07-23 stsp fi
816 11cc08c1 2020-07-23 stsp
817 11cc08c1 2020-07-23 stsp echo "<<<<<<< merged change: commit $commit_id2" \
818 283102fc 2020-07-23 stsp > $testroot/content.expected
819 11cc08c1 2020-07-23 stsp echo "../gamma/delta" >> $testroot/content.expected
820 11cc08c1 2020-07-23 stsp echo "3-way merge base: commit $commit_id1" \
821 11cc08c1 2020-07-23 stsp >> $testroot/content.expected
822 11cc08c1 2020-07-23 stsp echo "../beta" >> $testroot/content.expected
823 11cc08c1 2020-07-23 stsp echo "=======" >> $testroot/content.expected
824 11cc08c1 2020-07-23 stsp echo "../gamma" >> $testroot/content.expected
825 11cc08c1 2020-07-23 stsp echo '>>>>>>>' >> $testroot/content.expected
826 11cc08c1 2020-07-23 stsp echo -n "" >> $testroot/content.expected
827 11cc08c1 2020-07-23 stsp
828 11cc08c1 2020-07-23 stsp cp $testroot/wt/epsilon/beta.link $testroot/content
829 11cc08c1 2020-07-23 stsp cmp -s $testroot/content.expected $testroot/content
830 e26bafba 2020-07-23 stsp ret="$?"
831 e26bafba 2020-07-23 stsp if [ "$ret" != "0" ]; then
832 11cc08c1 2020-07-23 stsp diff -u $testroot/content.expected $testroot/content
833 e26bafba 2020-07-23 stsp test_done "$testroot" "$ret"
834 e26bafba 2020-07-23 stsp return 1
835 e26bafba 2020-07-23 stsp fi
836 e26bafba 2020-07-23 stsp
837 af57b12a 2020-07-23 stsp if [ -h $testroot/wt/nonexistent.link ]; then
838 af57b12a 2020-07-23 stsp echo -n "nonexistent.link still exists on disk: " >&2
839 af57b12a 2020-07-23 stsp readlink $testroot/wt/nonexistent.link >&2
840 af57b12a 2020-07-23 stsp test_done "$testroot" "1"
841 af57b12a 2020-07-23 stsp return 1
842 af57b12a 2020-07-23 stsp fi
843 af57b12a 2020-07-23 stsp
844 e26bafba 2020-07-23 stsp if [ -h $testroot/wt/dotgotfoo.link ]; then
845 e26bafba 2020-07-23 stsp echo "dotgotfoo.link is a symlink"
846 e26bafba 2020-07-23 stsp test_done "$testroot" "1"
847 e26bafba 2020-07-23 stsp return 1
848 e26bafba 2020-07-23 stsp fi
849 e26bafba 2020-07-23 stsp
850 3b9f0f87 2020-07-23 stsp echo "<<<<<<< merged change: commit $commit_id2" \
851 3b9f0f87 2020-07-23 stsp > $testroot/content.expected
852 3b9f0f87 2020-07-23 stsp echo "this is regular file foo" >> $testroot/content.expected
853 3b9f0f87 2020-07-23 stsp echo "=======" >> $testroot/content.expected
854 ace90326 2021-09-27 thomas echo -n ".got/foo" >> $testroot/content.expected
855 3b9f0f87 2020-07-23 stsp echo '>>>>>>>' >> $testroot/content.expected
856 e26bafba 2020-07-23 stsp cp $testroot/wt/dotgotfoo.link $testroot/content
857 e26bafba 2020-07-23 stsp cmp -s $testroot/content.expected $testroot/content
858 e26bafba 2020-07-23 stsp ret="$?"
859 e26bafba 2020-07-23 stsp if [ "$ret" != "0" ]; then
860 e26bafba 2020-07-23 stsp diff -u $testroot/content.expected $testroot/content
861 e26bafba 2020-07-23 stsp test_done "$testroot" "$ret"
862 e26bafba 2020-07-23 stsp return 1
863 e26bafba 2020-07-23 stsp fi
864 e26bafba 2020-07-23 stsp
865 e26bafba 2020-07-23 stsp if [ -h $testroot/wt/dotgotbar.link ]; then
866 e26bafba 2020-07-23 stsp echo "dotgotbar.link is a symlink"
867 e26bafba 2020-07-23 stsp test_done "$testroot" "1"
868 e26bafba 2020-07-23 stsp return 1
869 e26bafba 2020-07-23 stsp fi
870 d219f183 2020-07-23 stsp echo "<<<<<<< merged change: commit $commit_id2" \
871 d219f183 2020-07-23 stsp > $testroot/content.expected
872 d219f183 2020-07-23 stsp echo -n ".got/bar" >> $testroot/content.expected
873 d219f183 2020-07-23 stsp echo "=======" >> $testroot/content.expected
874 d219f183 2020-07-23 stsp echo "this is regular file bar" >> $testroot/content.expected
875 d219f183 2020-07-23 stsp echo '>>>>>>>' >> $testroot/content.expected
876 d219f183 2020-07-23 stsp echo -n "" >> $testroot/content.expected
877 e26bafba 2020-07-23 stsp cp $testroot/wt/dotgotbar.link $testroot/content
878 e26bafba 2020-07-23 stsp cmp -s $testroot/content.expected $testroot/content
879 e26bafba 2020-07-23 stsp ret="$?"
880 e26bafba 2020-07-23 stsp if [ "$ret" != "0" ]; then
881 e26bafba 2020-07-23 stsp diff -u $testroot/content.expected $testroot/content
882 e26bafba 2020-07-23 stsp test_done "$testroot" "$ret"
883 e26bafba 2020-07-23 stsp return 1
884 e26bafba 2020-07-23 stsp fi
885 e26bafba 2020-07-23 stsp
886 11cc08c1 2020-07-23 stsp if [ -h $testroot/wt/new.link ]; then
887 11cc08c1 2020-07-23 stsp echo "new.link is a symlink"
888 e26bafba 2020-07-23 stsp test_done "$testroot" "1"
889 e26bafba 2020-07-23 stsp return 1
890 e26bafba 2020-07-23 stsp fi
891 e26bafba 2020-07-23 stsp
892 11cc08c1 2020-07-23 stsp echo "<<<<<<< merged change: commit $commit_id2" \
893 283102fc 2020-07-23 stsp > $testroot/content.expected
894 11cc08c1 2020-07-23 stsp echo "alpha" >> $testroot/content.expected
895 11cc08c1 2020-07-23 stsp echo "=======" >> $testroot/content.expected
896 11cc08c1 2020-07-23 stsp echo "beta" >> $testroot/content.expected
897 11cc08c1 2020-07-23 stsp echo '>>>>>>>' >> $testroot/content.expected
898 11cc08c1 2020-07-23 stsp echo -n "" >> $testroot/content.expected
899 11cc08c1 2020-07-23 stsp
900 11cc08c1 2020-07-23 stsp cp $testroot/wt/new.link $testroot/content
901 11cc08c1 2020-07-23 stsp cmp -s $testroot/content.expected $testroot/content
902 e26bafba 2020-07-23 stsp ret="$?"
903 e26bafba 2020-07-23 stsp if [ "$ret" != "0" ]; then
904 11cc08c1 2020-07-23 stsp diff -u $testroot/content.expected $testroot/content
905 e26bafba 2020-07-23 stsp test_done "$testroot" "$ret"
906 e26bafba 2020-07-23 stsp return 1
907 e26bafba 2020-07-23 stsp fi
908 e26bafba 2020-07-23 stsp
909 e26bafba 2020-07-23 stsp echo "A dotgotfoo.link" > $testroot/stdout.expected
910 e26bafba 2020-07-23 stsp echo "M new.link" >> $testroot/stdout.expected
911 e26bafba 2020-07-23 stsp echo "D nonexistent.link" >> $testroot/stdout.expected
912 e26bafba 2020-07-23 stsp (cd $testroot/wt && got status > $testroot/stdout)
913 e26bafba 2020-07-23 stsp if [ "$ret" != "0" ]; then
914 e26bafba 2020-07-23 stsp diff -u $testroot/stdout.expected $testroot/stdout
915 e26bafba 2020-07-23 stsp test_done "$testroot" "$ret"
916 e26bafba 2020-07-23 stsp return 1
917 e26bafba 2020-07-23 stsp fi
918 e26bafba 2020-07-23 stsp
919 af57b12a 2020-07-23 stsp test_done "$testroot" "0"
920 69d57f3d 2020-07-31 stsp }
921 69d57f3d 2020-07-31 stsp
922 f6cae3ed 2020-09-13 naddy test_cherrypick_with_path_prefix_and_empty_tree() {
923 69d57f3d 2020-07-31 stsp local testroot=`test_init cherrypick_with_path_prefix_and_empty_tree 1`
924 69d57f3d 2020-07-31 stsp
925 69d57f3d 2020-07-31 stsp (cd $testroot/repo && git commit --allow-empty \
926 69d57f3d 2020-07-31 stsp -m "initial empty commit" >/dev/null)
927 69d57f3d 2020-07-31 stsp
928 69d57f3d 2020-07-31 stsp (cd $testroot/repo && got br bar >/dev/null)
929 69d57f3d 2020-07-31 stsp
930 69d57f3d 2020-07-31 stsp mkdir -p $testroot/repo/epsilon
931 69d57f3d 2020-07-31 stsp echo "file foo" > $testroot/repo/epsilon/foo
932 69d57f3d 2020-07-31 stsp (cd $testroot/repo && git add .)
933 69d57f3d 2020-07-31 stsp git_commit $testroot/repo -m "add file foo"
934 69d57f3d 2020-07-31 stsp local commit_id=`git_show_head $testroot/repo`
935 69d57f3d 2020-07-31 stsp
936 69d57f3d 2020-07-31 stsp got checkout -b bar $testroot/repo $testroot/wt > /dev/null
937 69d57f3d 2020-07-31 stsp ret="$?"
938 69d57f3d 2020-07-31 stsp if [ "$ret" != "0" ]; then
939 69d57f3d 2020-07-31 stsp echo "got checkout failed unexpectedly" >&2
940 69d57f3d 2020-07-31 stsp test_done "$testroot" "$ret"
941 69d57f3d 2020-07-31 stsp return 1
942 69d57f3d 2020-07-31 stsp fi
943 69d57f3d 2020-07-31 stsp
944 69d57f3d 2020-07-31 stsp mkdir -p $testroot/wt/epsilon
945 69d57f3d 2020-07-31 stsp echo "new file" > $testroot/wt/epsilon/new
946 69d57f3d 2020-07-31 stsp (cd $testroot/wt && got add epsilon/new >/dev/null)
947 69d57f3d 2020-07-31 stsp (cd $testroot/wt && got commit -m "add file on branch bar" > /dev/null)
948 69d57f3d 2020-07-31 stsp
949 69d57f3d 2020-07-31 stsp got checkout -b bar -p epsilon $testroot/repo $testroot/wt2 > /dev/null
950 69d57f3d 2020-07-31 stsp ret="$?"
951 69d57f3d 2020-07-31 stsp if [ "$ret" != "0" ]; then
952 69d57f3d 2020-07-31 stsp echo "got checkout failed unexpectedly" >&2
953 69d57f3d 2020-07-31 stsp test_done "$testroot" "$ret"
954 69d57f3d 2020-07-31 stsp return 1
955 69d57f3d 2020-07-31 stsp fi
956 69d57f3d 2020-07-31 stsp (cd $testroot/wt2 && got cherrypick $commit_id > $testroot/stdout)
957 69d57f3d 2020-07-31 stsp
958 69d57f3d 2020-07-31 stsp echo "A foo" > $testroot/stdout.expected
959 69d57f3d 2020-07-31 stsp echo "Merged commit $commit_id" >> $testroot/stdout.expected
960 cce854ad 2021-04-13 stsp
961 cce854ad 2021-04-13 stsp cmp -s $testroot/stdout.expected $testroot/stdout
962 cce854ad 2021-04-13 stsp ret="$?"
963 cce854ad 2021-04-13 stsp if [ "$ret" != "0" ]; then
964 cce854ad 2021-04-13 stsp diff -u $testroot/stdout.expected $testroot/stdout
965 cce854ad 2021-04-13 stsp fi
966 cce854ad 2021-04-13 stsp test_done "$testroot" "$ret"
967 cce854ad 2021-04-13 stsp }
968 cce854ad 2021-04-13 stsp
969 cce854ad 2021-04-13 stsp test_cherrypick_conflict_no_eol() {
970 cce854ad 2021-04-13 stsp local testroot=`test_init cherrypick_conflict_no_eol 1`
971 cce854ad 2021-04-13 stsp local content_a="aaa\naaa\naaa\naaa\naaa\naaa\n"
972 cce854ad 2021-04-13 stsp local content_b="aaa\naaa\nbbb\naaa\naaa\naaa\naaa"
973 cce854ad 2021-04-13 stsp local content_c="aaa\naaa\nccc\naaa\naaa\naaa\naaa"
974 cce854ad 2021-04-13 stsp
975 cce854ad 2021-04-13 stsp printf "$content_a" > $testroot/repo/a
976 cce854ad 2021-04-13 stsp (cd $testroot/repo && git add a)
977 cce854ad 2021-04-13 stsp git_commit $testroot/repo -m "initial commit"
978 cce854ad 2021-04-13 stsp
979 cce854ad 2021-04-13 stsp (cd $testroot/repo && got branch newbranch)
980 cce854ad 2021-04-13 stsp
981 cce854ad 2021-04-13 stsp printf "$content_b" > $testroot/repo/a
982 cce854ad 2021-04-13 stsp git_commit $testroot/repo -m "change bbb"
983 69d57f3d 2020-07-31 stsp
984 cce854ad 2021-04-13 stsp printf "$content_c" > $testroot/repo/a
985 cce854ad 2021-04-13 stsp git_commit $testroot/repo -m "change ccc"
986 cce854ad 2021-04-13 stsp local ccc_commit=`git_show_head $testroot/repo`
987 cce854ad 2021-04-13 stsp
988 cce854ad 2021-04-13 stsp got checkout -b newbranch $testroot/repo $testroot/wt > /dev/null
989 cce854ad 2021-04-13 stsp ret="$?"
990 cce854ad 2021-04-13 stsp if [ "$ret" != "0" ]; then
991 cce854ad 2021-04-13 stsp test_done "$testroot" "$ret"
992 cce854ad 2021-04-13 stsp return 1
993 cce854ad 2021-04-13 stsp fi
994 cce854ad 2021-04-13 stsp
995 cce854ad 2021-04-13 stsp (cd $testroot/wt && got cherrypick $ccc_commit > $testroot/stdout)
996 cce854ad 2021-04-13 stsp
997 cce854ad 2021-04-13 stsp echo "C a" > $testroot/stdout.expected
998 cce854ad 2021-04-13 stsp echo "Merged commit $ccc_commit" >> $testroot/stdout.expected
999 cce854ad 2021-04-13 stsp echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
1000 cce854ad 2021-04-13 stsp
1001 69d57f3d 2020-07-31 stsp cmp -s $testroot/stdout.expected $testroot/stdout
1002 69d57f3d 2020-07-31 stsp ret="$?"
1003 69d57f3d 2020-07-31 stsp if [ "$ret" != "0" ]; then
1004 69d57f3d 2020-07-31 stsp diff -u $testroot/stdout.expected $testroot/stdout
1005 cce854ad 2021-04-13 stsp fi
1006 cce854ad 2021-04-13 stsp test_done "$testroot" "$ret"
1007 cce854ad 2021-04-13 stsp }
1008 cce854ad 2021-04-13 stsp
1009 cce854ad 2021-04-13 stsp test_cherrypick_conflict_no_eol2() {
1010 cce854ad 2021-04-13 stsp local testroot=`test_init cherrypick_conflict_no_eol2 1`
1011 cce854ad 2021-04-13 stsp local content_a="aaa\naaa\naaa\naaa\naaa\naaa"
1012 cce854ad 2021-04-13 stsp local content_b="aaa\naaa\nbbb\naaa\naaa\naaa"
1013 cce854ad 2021-04-13 stsp local content_c="aaa\naaa\nbbb\naaa\naaa\naaa\n"
1014 cce854ad 2021-04-13 stsp
1015 cce854ad 2021-04-13 stsp printf "$content_a" > $testroot/repo/a
1016 cce854ad 2021-04-13 stsp (cd $testroot/repo && git add a)
1017 cce854ad 2021-04-13 stsp git_commit $testroot/repo -m "initial commit"
1018 cce854ad 2021-04-13 stsp
1019 cce854ad 2021-04-13 stsp (cd $testroot/repo && got branch newbranch)
1020 cce854ad 2021-04-13 stsp
1021 cce854ad 2021-04-13 stsp printf "$content_b" > $testroot/repo/a
1022 cce854ad 2021-04-13 stsp git_commit $testroot/repo -m "change bbb"
1023 cce854ad 2021-04-13 stsp
1024 cce854ad 2021-04-13 stsp printf "$content_c" > $testroot/repo/a
1025 cce854ad 2021-04-13 stsp git_commit $testroot/repo -m "change ccc"
1026 cce854ad 2021-04-13 stsp local ccc_commit=`git_show_head $testroot/repo`
1027 cce854ad 2021-04-13 stsp
1028 cce854ad 2021-04-13 stsp got checkout -b newbranch $testroot/repo $testroot/wt > /dev/null
1029 cce854ad 2021-04-13 stsp ret="$?"
1030 cce854ad 2021-04-13 stsp if [ "$ret" != "0" ]; then
1031 cce854ad 2021-04-13 stsp test_done "$testroot" "$ret"
1032 cce854ad 2021-04-13 stsp return 1
1033 69d57f3d 2020-07-31 stsp fi
1034 cce854ad 2021-04-13 stsp
1035 cce854ad 2021-04-13 stsp (cd $testroot/wt && got cherrypick $ccc_commit \
1036 cce854ad 2021-04-13 stsp > $testroot/stdout 2> $testroot/stderr)
1037 cce854ad 2021-04-13 stsp
1038 cce854ad 2021-04-13 stsp echo "C a" > $testroot/stdout.expected
1039 cce854ad 2021-04-13 stsp echo "Merged commit $ccc_commit" >> $testroot/stdout.expected
1040 cce854ad 2021-04-13 stsp echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
1041 cce854ad 2021-04-13 stsp
1042 cce854ad 2021-04-13 stsp cmp -s $testroot/stdout.expected $testroot/stdout
1043 cce854ad 2021-04-13 stsp ret="$?"
1044 cce854ad 2021-04-13 stsp if [ "$ret" != "0" ]; then
1045 54d5be07 2021-06-03 stsp diff -u $testroot/stdout.expected $testroot/stdout
1046 3cd22b21 2021-05-31 stsp fi
1047 3cd22b21 2021-05-31 stsp test_done "$testroot" "$ret"
1048 3cd22b21 2021-05-31 stsp }
1049 3cd22b21 2021-05-31 stsp
1050 3cd22b21 2021-05-31 stsp test_cherrypick_unrelated_changes() {
1051 3cd22b21 2021-05-31 stsp local testroot=`test_init cherrypick_unrelated_changes`
1052 3cd22b21 2021-05-31 stsp
1053 3cd22b21 2021-05-31 stsp # Sorry about the large HERE document but I have not found
1054 3cd22b21 2021-05-31 stsp # a smaller reproduction recipe yet...
1055 3cd22b21 2021-05-31 stsp cat > $testroot/repo/reference.c <<EOF
1056 3cd22b21 2021-05-31 stsp const struct got_error *
1057 3cd22b21 2021-05-31 stsp got_ref_alloc(struct got_reference **ref, const char *name,
1058 3cd22b21 2021-05-31 stsp struct got_object_id *id)
1059 3cd22b21 2021-05-31 stsp {
1060 3cd22b21 2021-05-31 stsp if (!is_valid_ref_name(name))
1061 3cd22b21 2021-05-31 stsp return got_error_path(name, GOT_ERR_BAD_REF_NAME);
1062 3cd22b21 2021-05-31 stsp
1063 3cd22b21 2021-05-31 stsp return alloc_ref(ref, name, id, 0);
1064 3cd22b21 2021-05-31 stsp }
1065 3cd22b21 2021-05-31 stsp
1066 3cd22b21 2021-05-31 stsp static const struct got_error *
1067 3cd22b21 2021-05-31 stsp parse_packed_ref_line(struct got_reference **ref, const char *abs_refname,
1068 3cd22b21 2021-05-31 stsp const char *line)
1069 3cd22b21 2021-05-31 stsp {
1070 3cd22b21 2021-05-31 stsp struct got_object_id id;
1071 3cd22b21 2021-05-31 stsp const char *name;
1072 3cd22b21 2021-05-31 stsp
1073 3cd22b21 2021-05-31 stsp *ref = NULL;
1074 3cd22b21 2021-05-31 stsp
1075 3cd22b21 2021-05-31 stsp if (line[0] == '#' || line[0] == '^')
1076 3cd22b21 2021-05-31 stsp return NULL;
1077 3cd22b21 2021-05-31 stsp
1078 3cd22b21 2021-05-31 stsp if (!got_parse_sha1_digest(id.sha1, line))
1079 3cd22b21 2021-05-31 stsp return got_error(GOT_ERR_BAD_REF_DATA);
1080 3cd22b21 2021-05-31 stsp
1081 3cd22b21 2021-05-31 stsp if (abs_refname) {
1082 3cd22b21 2021-05-31 stsp if (strcmp(line + SHA1_DIGEST_STRING_LENGTH, abs_refname) != 0)
1083 3cd22b21 2021-05-31 stsp return NULL;
1084 3cd22b21 2021-05-31 stsp name = abs_refname;
1085 3cd22b21 2021-05-31 stsp } else
1086 3cd22b21 2021-05-31 stsp name = line + SHA1_DIGEST_STRING_LENGTH;
1087 3cd22b21 2021-05-31 stsp
1088 3cd22b21 2021-05-31 stsp return alloc_ref(ref, name, &id, GOT_REF_IS_PACKED);
1089 3cd22b21 2021-05-31 stsp }
1090 3cd22b21 2021-05-31 stsp
1091 3cd22b21 2021-05-31 stsp static const struct got_error *
1092 3cd22b21 2021-05-31 stsp open_packed_ref(struct got_reference **ref, FILE *f, const char **subdirs,
1093 3cd22b21 2021-05-31 stsp int nsubdirs, const char *refname)
1094 3cd22b21 2021-05-31 stsp {
1095 3cd22b21 2021-05-31 stsp const struct got_error *err = NULL;
1096 3cd22b21 2021-05-31 stsp char *abs_refname;
1097 3cd22b21 2021-05-31 stsp char *line = NULL;
1098 3cd22b21 2021-05-31 stsp size_t linesize = 0;
1099 3cd22b21 2021-05-31 stsp ssize_t linelen;
1100 3cd22b21 2021-05-31 stsp int i, ref_is_absolute = (strncmp(refname, "refs/", 5) == 0);
1101 3cd22b21 2021-05-31 stsp
1102 3cd22b21 2021-05-31 stsp *ref = NULL;
1103 3cd22b21 2021-05-31 stsp
1104 3cd22b21 2021-05-31 stsp if (ref_is_absolute)
1105 3cd22b21 2021-05-31 stsp abs_refname = (char *)refname;
1106 3cd22b21 2021-05-31 stsp do {
1107 3cd22b21 2021-05-31 stsp linelen = getline(&line, &linesize, f);
1108 3cd22b21 2021-05-31 stsp if (linelen == -1) {
1109 3cd22b21 2021-05-31 stsp if (feof(f))
1110 3cd22b21 2021-05-31 stsp break;
1111 3cd22b21 2021-05-31 stsp err = got_ferror(f, GOT_ERR_BAD_REF_DATA);
1112 3cd22b21 2021-05-31 stsp break;
1113 3cd22b21 2021-05-31 stsp }
1114 3cd22b21 2021-05-31 stsp if (linelen > 0 && line[linelen - 1] == '\n')
1115 3cd22b21 2021-05-31 stsp line[linelen - 1] = '\0';
1116 3cd22b21 2021-05-31 stsp for (i = 0; i < nsubdirs; i++) {
1117 3cd22b21 2021-05-31 stsp if (!ref_is_absolute &&
1118 3cd22b21 2021-05-31 stsp asprintf(&abs_refname, "refs/%s/%s", subdirs[i],
1119 3cd22b21 2021-05-31 stsp refname) == -1)
1120 3cd22b21 2021-05-31 stsp return got_error_from_errno("asprintf");
1121 3cd22b21 2021-05-31 stsp err = parse_packed_ref_line(ref, abs_refname, line);
1122 3cd22b21 2021-05-31 stsp if (!ref_is_absolute)
1123 3cd22b21 2021-05-31 stsp free(abs_refname);
1124 3cd22b21 2021-05-31 stsp if (err || *ref != NULL)
1125 3cd22b21 2021-05-31 stsp break;
1126 3cd22b21 2021-05-31 stsp }
1127 3cd22b21 2021-05-31 stsp if (err)
1128 3cd22b21 2021-05-31 stsp break;
1129 3cd22b21 2021-05-31 stsp } while (*ref == NULL);
1130 3cd22b21 2021-05-31 stsp free(line);
1131 3cd22b21 2021-05-31 stsp
1132 3cd22b21 2021-05-31 stsp return err;
1133 3cd22b21 2021-05-31 stsp }
1134 3cd22b21 2021-05-31 stsp
1135 3cd22b21 2021-05-31 stsp static const struct got_error *
1136 3cd22b21 2021-05-31 stsp open_ref(struct got_reference **ref, const char *path_refs, const char *subdir,
1137 3cd22b21 2021-05-31 stsp const char *name, int lock)
1138 3cd22b21 2021-05-31 stsp {
1139 3cd22b21 2021-05-31 stsp const struct got_error *err = NULL;
1140 3cd22b21 2021-05-31 stsp char *path = NULL;
1141 3cd22b21 2021-05-31 stsp char *absname = NULL;
1142 3cd22b21 2021-05-31 stsp int ref_is_absolute = (strncmp(name, "refs/", 5) == 0);
1143 3cd22b21 2021-05-31 stsp int ref_is_well_known = (subdir[0] == '\0' && is_well_known_ref(name));
1144 3cd22b21 2021-05-31 stsp
1145 3cd22b21 2021-05-31 stsp *ref = NULL;
1146 3cd22b21 2021-05-31 stsp
1147 3cd22b21 2021-05-31 stsp if (ref_is_absolute || ref_is_well_known) {
1148 3cd22b21 2021-05-31 stsp if (asprintf(&path, "%s/%s", path_refs, name) == -1)
1149 3cd22b21 2021-05-31 stsp return got_error_from_errno("asprintf");
1150 3cd22b21 2021-05-31 stsp absname = (char *)name;
1151 3cd22b21 2021-05-31 stsp } else {
1152 3cd22b21 2021-05-31 stsp if (asprintf(&path, "%s/%s%s%s", path_refs, subdir,
1153 3cd22b21 2021-05-31 stsp subdir[0] ? "/" : "", name) == -1)
1154 3cd22b21 2021-05-31 stsp return got_error_from_errno("asprintf");
1155 3cd22b21 2021-05-31 stsp
1156 3cd22b21 2021-05-31 stsp if (asprintf(&absname, "refs/%s%s%s",
1157 3cd22b21 2021-05-31 stsp subdir, subdir[0] ? "/" : "", name) == -1) {
1158 3cd22b21 2021-05-31 stsp err = got_error_from_errno("asprintf");
1159 3cd22b21 2021-05-31 stsp goto done;
1160 3cd22b21 2021-05-31 stsp }
1161 3cd22b21 2021-05-31 stsp }
1162 3cd22b21 2021-05-31 stsp
1163 3cd22b21 2021-05-31 stsp err = parse_ref_file(ref, name, absname, path, lock);
1164 3cd22b21 2021-05-31 stsp done:
1165 3cd22b21 2021-05-31 stsp if (!ref_is_absolute && !ref_is_well_known)
1166 3cd22b21 2021-05-31 stsp free(absname);
1167 3cd22b21 2021-05-31 stsp free(path);
1168 3cd22b21 2021-05-31 stsp return err;
1169 3cd22b21 2021-05-31 stsp }
1170 3cd22b21 2021-05-31 stsp
1171 3cd22b21 2021-05-31 stsp const struct got_error *
1172 3cd22b21 2021-05-31 stsp got_ref_open(struct got_reference **ref, struct got_repository *repo,
1173 3cd22b21 2021-05-31 stsp const char *refname, int lock)
1174 3cd22b21 2021-05-31 stsp {
1175 3cd22b21 2021-05-31 stsp const struct got_error *err = NULL;
1176 3cd22b21 2021-05-31 stsp char *path_refs = NULL;
1177 3cd22b21 2021-05-31 stsp const char *subdirs[] = {
1178 3cd22b21 2021-05-31 stsp GOT_REF_HEADS, GOT_REF_TAGS, GOT_REF_REMOTES
1179 3cd22b21 2021-05-31 stsp };
1180 3cd22b21 2021-05-31 stsp size_t i;
1181 3cd22b21 2021-05-31 stsp int well_known = is_well_known_ref(refname);
1182 3cd22b21 2021-05-31 stsp struct got_lockfile *lf = NULL;
1183 3cd22b21 2021-05-31 stsp
1184 3cd22b21 2021-05-31 stsp *ref = NULL;
1185 3cd22b21 2021-05-31 stsp
1186 3cd22b21 2021-05-31 stsp path_refs = get_refs_dir_path(repo, refname);
1187 3cd22b21 2021-05-31 stsp if (path_refs == NULL) {
1188 3cd22b21 2021-05-31 stsp err = got_error_from_errno2("get_refs_dir_path", refname);
1189 3cd22b21 2021-05-31 stsp goto done;
1190 3cd22b21 2021-05-31 stsp }
1191 3cd22b21 2021-05-31 stsp
1192 3cd22b21 2021-05-31 stsp if (well_known) {
1193 3cd22b21 2021-05-31 stsp err = open_ref(ref, path_refs, "", refname, lock);
1194 3cd22b21 2021-05-31 stsp } else {
1195 3cd22b21 2021-05-31 stsp char *packed_refs_path;
1196 3cd22b21 2021-05-31 stsp FILE *f;
1197 3cd22b21 2021-05-31 stsp
1198 3cd22b21 2021-05-31 stsp /* Search on-disk refs before packed refs! */
1199 3cd22b21 2021-05-31 stsp for (i = 0; i < nitems(subdirs); i++) {
1200 3cd22b21 2021-05-31 stsp err = open_ref(ref, path_refs, subdirs[i], refname,
1201 3cd22b21 2021-05-31 stsp lock);
1202 3cd22b21 2021-05-31 stsp if ((err && err->code != GOT_ERR_NOT_REF) || *ref)
1203 3cd22b21 2021-05-31 stsp goto done;
1204 3cd22b21 2021-05-31 stsp }
1205 3cd22b21 2021-05-31 stsp
1206 3cd22b21 2021-05-31 stsp packed_refs_path = got_repo_get_path_packed_refs(repo);
1207 3cd22b21 2021-05-31 stsp if (packed_refs_path == NULL) {
1208 3cd22b21 2021-05-31 stsp err = got_error_from_errno(
1209 3cd22b21 2021-05-31 stsp "got_repo_get_path_packed_refs");
1210 3cd22b21 2021-05-31 stsp goto done;
1211 3cd22b21 2021-05-31 stsp }
1212 3cd22b21 2021-05-31 stsp
1213 3cd22b21 2021-05-31 stsp if (lock) {
1214 3cd22b21 2021-05-31 stsp err = got_lockfile_lock(&lf, packed_refs_path);
1215 3cd22b21 2021-05-31 stsp if (err)
1216 3cd22b21 2021-05-31 stsp goto done;
1217 3cd22b21 2021-05-31 stsp }
1218 3cd22b21 2021-05-31 stsp f = fopen(packed_refs_path, "rb");
1219 3cd22b21 2021-05-31 stsp free(packed_refs_path);
1220 3cd22b21 2021-05-31 stsp if (f != NULL) {
1221 3cd22b21 2021-05-31 stsp err = open_packed_ref(ref, f, subdirs, nitems(subdirs),
1222 3cd22b21 2021-05-31 stsp refname);
1223 3cd22b21 2021-05-31 stsp if (!err) {
1224 3cd22b21 2021-05-31 stsp if (fclose(f) == EOF) {
1225 3cd22b21 2021-05-31 stsp err = got_error_from_errno("fclose");
1226 3cd22b21 2021-05-31 stsp got_ref_close(*ref);
1227 3cd22b21 2021-05-31 stsp *ref = NULL;
1228 3cd22b21 2021-05-31 stsp } else if (*ref)
1229 3cd22b21 2021-05-31 stsp (*ref)->lf = lf;
1230 3cd22b21 2021-05-31 stsp }
1231 3cd22b21 2021-05-31 stsp }
1232 3cd22b21 2021-05-31 stsp }
1233 3cd22b21 2021-05-31 stsp done:
1234 3cd22b21 2021-05-31 stsp if (!err && *ref == NULL)
1235 3cd22b21 2021-05-31 stsp err = got_error_not_ref(refname);
1236 3cd22b21 2021-05-31 stsp if (err && lf)
1237 3cd22b21 2021-05-31 stsp got_lockfile_unlock(lf);
1238 3cd22b21 2021-05-31 stsp free(path_refs);
1239 3cd22b21 2021-05-31 stsp return err;
1240 3cd22b21 2021-05-31 stsp }
1241 3cd22b21 2021-05-31 stsp
1242 3cd22b21 2021-05-31 stsp struct got_reference *
1243 3cd22b21 2021-05-31 stsp got_ref_dup(struct got_reference *ref)
1244 3cd22b21 2021-05-31 stsp {
1245 3cd22b21 2021-05-31 stsp struct got_reference *ret;
1246 3cd22b21 2021-05-31 stsp
1247 3cd22b21 2021-05-31 stsp ret = calloc(1, sizeof(*ret));
1248 3cd22b21 2021-05-31 stsp if (ret == NULL)
1249 3cd22b21 2021-05-31 stsp return NULL;
1250 3cd22b21 2021-05-31 stsp
1251 3cd22b21 2021-05-31 stsp ret->flags = ref->flags;
1252 3cd22b21 2021-05-31 stsp if (ref->flags & GOT_REF_IS_SYMBOLIC) {
1253 3cd22b21 2021-05-31 stsp ret->ref.symref.name = strdup(ref->ref.symref.name);
1254 3cd22b21 2021-05-31 stsp if (ret->ref.symref.name == NULL) {
1255 3cd22b21 2021-05-31 stsp free(ret);
1256 3cd22b21 2021-05-31 stsp return NULL;
1257 3cd22b21 2021-05-31 stsp }
1258 3cd22b21 2021-05-31 stsp ret->ref.symref.ref = strdup(ref->ref.symref.ref);
1259 3cd22b21 2021-05-31 stsp if (ret->ref.symref.ref == NULL) {
1260 3cd22b21 2021-05-31 stsp free(ret->ref.symref.name);
1261 3cd22b21 2021-05-31 stsp free(ret);
1262 3cd22b21 2021-05-31 stsp return NULL;
1263 3cd22b21 2021-05-31 stsp }
1264 3cd22b21 2021-05-31 stsp } else {
1265 3cd22b21 2021-05-31 stsp ret->ref.ref.name = strdup(ref->ref.ref.name);
1266 3cd22b21 2021-05-31 stsp if (ret->ref.ref.name == NULL) {
1267 3cd22b21 2021-05-31 stsp free(ret);
1268 3cd22b21 2021-05-31 stsp return NULL;
1269 3cd22b21 2021-05-31 stsp }
1270 3cd22b21 2021-05-31 stsp memcpy(ret->ref.ref.sha1, ref->ref.ref.sha1,
1271 3cd22b21 2021-05-31 stsp sizeof(ret->ref.ref.sha1));
1272 3cd22b21 2021-05-31 stsp }
1273 3cd22b21 2021-05-31 stsp
1274 3cd22b21 2021-05-31 stsp return ret;
1275 3cd22b21 2021-05-31 stsp }
1276 3cd22b21 2021-05-31 stsp
1277 3cd22b21 2021-05-31 stsp const struct got_error *
1278 3cd22b21 2021-05-31 stsp got_reflist_entry_dup(struct got_reflist_entry **newp,
1279 3cd22b21 2021-05-31 stsp struct got_reflist_entry *re)
1280 3cd22b21 2021-05-31 stsp {
1281 3cd22b21 2021-05-31 stsp const struct got_error *err = NULL;
1282 3cd22b21 2021-05-31 stsp struct got_reflist_entry *new;
1283 3cd22b21 2021-05-31 stsp
1284 3cd22b21 2021-05-31 stsp *newp = NULL;
1285 3cd22b21 2021-05-31 stsp
1286 3cd22b21 2021-05-31 stsp new = malloc(sizeof(*new));
1287 3cd22b21 2021-05-31 stsp if (new == NULL)
1288 3cd22b21 2021-05-31 stsp return got_error_from_errno("malloc");
1289 3cd22b21 2021-05-31 stsp
1290 3cd22b21 2021-05-31 stsp new->ref = got_ref_dup(re->ref);
1291 3cd22b21 2021-05-31 stsp if (new->ref == NULL) {
1292 3cd22b21 2021-05-31 stsp err = got_error_from_errno("got_ref_dup");
1293 3cd22b21 2021-05-31 stsp free(new);
1294 3cd22b21 2021-05-31 stsp return err;
1295 3cd22b21 2021-05-31 stsp }
1296 3cd22b21 2021-05-31 stsp
1297 3cd22b21 2021-05-31 stsp *newp = new;
1298 3cd22b21 2021-05-31 stsp return NULL;
1299 3cd22b21 2021-05-31 stsp }
1300 3cd22b21 2021-05-31 stsp
1301 3cd22b21 2021-05-31 stsp void
1302 3cd22b21 2021-05-31 stsp got_ref_list_free(struct got_reflist_head *refs)
1303 3cd22b21 2021-05-31 stsp {
1304 3cd22b21 2021-05-31 stsp struct got_reflist_entry *re;
1305 3cd22b21 2021-05-31 stsp
1306 3cd22b21 2021-05-31 stsp while ((re = TAILQ_FIRST(refs))) {
1307 3cd22b21 2021-05-31 stsp TAILQ_REMOVE(refs, re, entry);
1308 3cd22b21 2021-05-31 stsp free(re);
1309 3cd22b21 2021-05-31 stsp }
1310 3cd22b21 2021-05-31 stsp
1311 3cd22b21 2021-05-31 stsp }
1312 3cd22b21 2021-05-31 stsp EOF
1313 3cd22b21 2021-05-31 stsp (cd $testroot/repo && git add reference.c)
1314 3cd22b21 2021-05-31 stsp git_commit $testroot/repo -m "added reference.c file"
1315 3cd22b21 2021-05-31 stsp local base_commit=`git_show_head $testroot/repo`
1316 3cd22b21 2021-05-31 stsp
1317 3cd22b21 2021-05-31 stsp got checkout $testroot/repo $testroot/wt > /dev/null
1318 3cd22b21 2021-05-31 stsp ret="$?"
1319 3cd22b21 2021-05-31 stsp if [ "$ret" != "0" ]; then
1320 3cd22b21 2021-05-31 stsp test_done "$testroot" "$ret"
1321 3cd22b21 2021-05-31 stsp return 1
1322 cce854ad 2021-04-13 stsp fi
1323 3cd22b21 2021-05-31 stsp
1324 3cd22b21 2021-05-31 stsp (cd $testroot/repo && git checkout -q -b newbranch)
1325 3cd22b21 2021-05-31 stsp ed -s $testroot/repo/reference.c <<EOF
1326 3cd22b21 2021-05-31 stsp 91a
1327 3cd22b21 2021-05-31 stsp if (!is_valid_ref_name(name))
1328 3cd22b21 2021-05-31 stsp return got_error_path(name, GOT_ERR_BAD_REF_NAME);
1329 3cd22b21 2021-05-31 stsp
1330 3cd22b21 2021-05-31 stsp .
1331 3cd22b21 2021-05-31 stsp w
1332 3cd22b21 2021-05-31 stsp q
1333 3cd22b21 2021-05-31 stsp EOF
1334 3cd22b21 2021-05-31 stsp git_commit $testroot/repo -m "added lines on newbranch"
1335 3cd22b21 2021-05-31 stsp local branch_rev1=`git_show_head $testroot/repo`
1336 3cd22b21 2021-05-31 stsp
1337 3cd22b21 2021-05-31 stsp ed -s $testroot/repo/reference.c <<EOF
1338 3cd22b21 2021-05-31 stsp 255a
1339 3cd22b21 2021-05-31 stsp got_ref_close(re->ref);
1340 3cd22b21 2021-05-31 stsp .
1341 3cd22b21 2021-05-31 stsp w
1342 3cd22b21 2021-05-31 stsp q
1343 3cd22b21 2021-05-31 stsp EOF
1344 3cd22b21 2021-05-31 stsp git_commit $testroot/repo -m "more lines on newbranch"
1345 3cd22b21 2021-05-31 stsp
1346 3cd22b21 2021-05-31 stsp local branch_rev2=`git_show_head $testroot/repo`
1347 3cd22b21 2021-05-31 stsp
1348 3cd22b21 2021-05-31 stsp (cd $testroot/wt && got cherrypick $branch_rev2 > $testroot/stdout)
1349 3cd22b21 2021-05-31 stsp
1350 3cd22b21 2021-05-31 stsp echo "G reference.c" > $testroot/stdout.expected
1351 3cd22b21 2021-05-31 stsp echo "Merged commit $branch_rev2" >> $testroot/stdout.expected
1352 3cd22b21 2021-05-31 stsp
1353 3cd22b21 2021-05-31 stsp cmp -s $testroot/stdout.expected $testroot/stdout
1354 3cd22b21 2021-05-31 stsp ret="$?"
1355 3cd22b21 2021-05-31 stsp if [ "$ret" != "0" ]; then
1356 3cd22b21 2021-05-31 stsp diff -u $testroot/stdout.expected $testroot/stdout
1357 3cd22b21 2021-05-31 stsp test_done "$testroot" "$ret"
1358 3cd22b21 2021-05-31 stsp return 1
1359 3cd22b21 2021-05-31 stsp fi
1360 3cd22b21 2021-05-31 stsp
1361 3cd22b21 2021-05-31 stsp cat > $testroot/diff.expected <<EOF
1362 3cd22b21 2021-05-31 stsp --- reference.c
1363 3cd22b21 2021-05-31 stsp +++ reference.c
1364 3cd22b21 2021-05-31 stsp @@ -250,6 +250,7 @@ got_ref_list_free(struct got_reflist_head *refs)
1365 3cd22b21 2021-05-31 stsp
1366 3cd22b21 2021-05-31 stsp while ((re = TAILQ_FIRST(refs))) {
1367 3cd22b21 2021-05-31 stsp TAILQ_REMOVE(refs, re, entry);
1368 3cd22b21 2021-05-31 stsp + got_ref_close(re->ref);
1369 3cd22b21 2021-05-31 stsp free(re);
1370 3cd22b21 2021-05-31 stsp }
1371 3cd22b21 2021-05-31 stsp
1372 3cd22b21 2021-05-31 stsp EOF
1373 3cd22b21 2021-05-31 stsp (cd $testroot/wt && got diff |
1374 3cd22b21 2021-05-31 stsp egrep -v '^(diff|blob|file)' > $testroot/diff)
1375 3cd22b21 2021-05-31 stsp cmp -s $testroot/diff.expected $testroot/diff
1376 3cd22b21 2021-05-31 stsp ret="$?"
1377 3cd22b21 2021-05-31 stsp if [ "$ret" != "0" ]; then
1378 54d5be07 2021-06-03 stsp diff -u $testroot/diff.expected $testroot/diff
1379 3cd22b21 2021-05-31 stsp fi
1380 0baddd91 2021-09-03 stsp
1381 0baddd91 2021-09-03 stsp test_done "$testroot" "$ret"
1382 0baddd91 2021-09-03 stsp }
1383 0baddd91 2021-09-03 stsp
1384 0baddd91 2021-09-03 stsp test_cherrypick_same_branch() {
1385 0baddd91 2021-09-03 stsp local testroot=`test_init cherrypick_same_branch`
1386 0baddd91 2021-09-03 stsp
1387 0baddd91 2021-09-03 stsp got checkout $testroot/repo $testroot/wt > /dev/null
1388 0baddd91 2021-09-03 stsp ret="$?"
1389 0baddd91 2021-09-03 stsp if [ "$ret" != "0" ]; then
1390 0baddd91 2021-09-03 stsp test_done "$testroot" "$ret"
1391 0baddd91 2021-09-03 stsp return 1
1392 0baddd91 2021-09-03 stsp fi
1393 0baddd91 2021-09-03 stsp
1394 0baddd91 2021-09-03 stsp (cd $testroot/repo && git checkout -q -b newbranch)
1395 0baddd91 2021-09-03 stsp echo "modified delta on branch" > $testroot/repo/gamma/delta
1396 0baddd91 2021-09-03 stsp git_commit $testroot/repo -m "committing to delta on newbranch"
1397 0baddd91 2021-09-03 stsp
1398 0baddd91 2021-09-03 stsp echo "modified alpha on branch" > $testroot/repo/alpha
1399 0baddd91 2021-09-03 stsp (cd $testroot/repo && git rm -q beta)
1400 0baddd91 2021-09-03 stsp echo "new file on branch" > $testroot/repo/epsilon/new
1401 0baddd91 2021-09-03 stsp (cd $testroot/repo && git add epsilon/new)
1402 0baddd91 2021-09-03 stsp git_commit $testroot/repo -m "committing more changes on newbranch"
1403 3cd22b21 2021-05-31 stsp
1404 0baddd91 2021-09-03 stsp local branch_rev=`git_show_head $testroot/repo`
1405 0baddd91 2021-09-03 stsp
1406 0baddd91 2021-09-03 stsp # picking a commit from the branch's own history does not make
1407 0baddd91 2021-09-03 stsp # sense but we should have test coverage for this case regardless
1408 0baddd91 2021-09-03 stsp (cd $testroot/wt && got up -b newbranch > /dev/null)
1409 0baddd91 2021-09-03 stsp (cd $testroot/wt && got cherrypick $branch_rev > $testroot/stdout)
1410 0baddd91 2021-09-03 stsp
1411 0baddd91 2021-09-03 stsp echo "G alpha" > $testroot/stdout.expected
1412 0baddd91 2021-09-03 stsp echo "! beta" >> $testroot/stdout.expected
1413 0baddd91 2021-09-03 stsp echo "G epsilon/new" >> $testroot/stdout.expected
1414 0baddd91 2021-09-03 stsp echo "Merged commit $branch_rev" >> $testroot/stdout.expected
1415 0ef68859 2021-09-28 thomas echo -n "Files which had incoming changes but could not be found " \
1416 0ef68859 2021-09-28 thomas >> $testroot/stdout.expected
1417 0ef68859 2021-09-28 thomas echo "in the work tree: 1" >> $testroot/stdout.expected
1418 0baddd91 2021-09-03 stsp
1419 0baddd91 2021-09-03 stsp cmp -s $testroot/stdout.expected $testroot/stdout
1420 0baddd91 2021-09-03 stsp ret="$?"
1421 0baddd91 2021-09-03 stsp if [ "$ret" != "0" ]; then
1422 0baddd91 2021-09-03 stsp diff -u $testroot/stdout.expected $testroot/stdout
1423 0baddd91 2021-09-03 stsp fi
1424 69d57f3d 2020-07-31 stsp test_done "$testroot" "$ret"
1425 e7303626 2020-05-14 stsp }
1426 e7303626 2020-05-14 stsp
1427 dc2a05aa 2021-10-08 thomas test_cherrypick_dot_on_a_line_by_itself() {
1428 dc2a05aa 2021-10-08 thomas local testroot=`test_init cherrypick_dot_on_a_line_by_itself`
1429 0baddd91 2021-09-03 stsp
1430 dc2a05aa 2021-10-08 thomas got checkout $testroot/repo $testroot/wt > /dev/null
1431 dc2a05aa 2021-10-08 thomas ret="$?"
1432 dc2a05aa 2021-10-08 thomas if [ "$ret" != "0" ]; then
1433 dc2a05aa 2021-10-08 thomas test_done "$testroot" "$ret"
1434 dc2a05aa 2021-10-08 thomas return 1
1435 dc2a05aa 2021-10-08 thomas fi
1436 dc2a05aa 2021-10-08 thomas
1437 dc2a05aa 2021-10-08 thomas (cd $testroot/repo && git checkout -q -b newbranch)
1438 461f6aed 2021-10-12 thomas printf "modified\n:delta\n.\non\n:branch\n" > $testroot/repo/gamma/delta
1439 dc2a05aa 2021-10-08 thomas git_commit $testroot/repo -m "committing to delta on newbranch"
1440 dc2a05aa 2021-10-08 thomas local branch_rev=`git_show_head $testroot/repo`
1441 dc2a05aa 2021-10-08 thomas
1442 dc2a05aa 2021-10-08 thomas (cd $testroot/wt && got cherrypick newbranch > $testroot/stdout)
1443 dc2a05aa 2021-10-08 thomas
1444 dc2a05aa 2021-10-08 thomas echo "G gamma/delta" >> $testroot/stdout.expected
1445 dc2a05aa 2021-10-08 thomas echo "Merged commit $branch_rev" >> $testroot/stdout.expected
1446 dc2a05aa 2021-10-08 thomas
1447 dc2a05aa 2021-10-08 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1448 dc2a05aa 2021-10-08 thomas ret="$?"
1449 dc2a05aa 2021-10-08 thomas if [ "$ret" != "0" ]; then
1450 dc2a05aa 2021-10-08 thomas diff -u $testroot/stdout.expected $testroot/stdout
1451 dc2a05aa 2021-10-08 thomas test_done "$testroot" "$ret"
1452 dc2a05aa 2021-10-08 thomas return 1
1453 dc2a05aa 2021-10-08 thomas fi
1454 dc2a05aa 2021-10-08 thomas
1455 461f6aed 2021-10-12 thomas printf "modified\n:delta\n.\non\n:branch\n" > $testroot/content.expected
1456 dc2a05aa 2021-10-08 thomas cat $testroot/wt/gamma/delta > $testroot/content
1457 dc2a05aa 2021-10-08 thomas cmp -s $testroot/content.expected $testroot/content
1458 dc2a05aa 2021-10-08 thomas ret="$?"
1459 dc2a05aa 2021-10-08 thomas if [ "$ret" != "0" ]; then
1460 461f6aed 2021-10-12 thomas diff -u $testroot/content.expected $testroot/content
1461 dc2a05aa 2021-10-08 thomas fi
1462 dc2a05aa 2021-10-08 thomas test_done "$testroot" "$ret"
1463 24f136e0 2021-11-20 thomas }
1464 24f136e0 2021-11-20 thomas
1465 24f136e0 2021-11-20 thomas test_cherrypick_binary_file() {
1466 24f136e0 2021-11-20 thomas local testroot=`test_init cherrypick_binary_file`
1467 24f136e0 2021-11-20 thomas local commit_id0=`git_show_head $testroot/repo`
1468 24f136e0 2021-11-20 thomas
1469 24f136e0 2021-11-20 thomas got checkout $testroot/repo $testroot/wt > /dev/null
1470 24f136e0 2021-11-20 thomas ret="$?"
1471 24f136e0 2021-11-20 thomas if [ "$ret" != "0" ]; then
1472 24f136e0 2021-11-20 thomas test_done "$testroot" "$ret"
1473 24f136e0 2021-11-20 thomas return 1
1474 24f136e0 2021-11-20 thomas fi
1475 24f136e0 2021-11-20 thomas
1476 24f136e0 2021-11-20 thomas cp /bin/ls $testroot/wt/foo
1477 24f136e0 2021-11-20 thomas chmod 755 $testroot/wt/foo
1478 24f136e0 2021-11-20 thomas (cd $testroot/wt && got add foo >/dev/null)
1479 24f136e0 2021-11-20 thomas (cd $testroot/wt && got commit -m 'add binary file' > /dev/null)
1480 24f136e0 2021-11-20 thomas local commit_id1=`git_show_head $testroot/repo`
1481 24f136e0 2021-11-20 thomas
1482 24f136e0 2021-11-20 thomas cp /bin/cat $testroot/wt/foo
1483 24f136e0 2021-11-20 thomas chmod 755 $testroot/wt/foo
1484 24f136e0 2021-11-20 thomas (cd $testroot/wt && got commit -m 'change binary file' > /dev/null)
1485 24f136e0 2021-11-20 thomas local commit_id2=`git_show_head $testroot/repo`
1486 24f136e0 2021-11-20 thomas
1487 24f136e0 2021-11-20 thomas cp /bin/cp $testroot/wt/foo
1488 24f136e0 2021-11-20 thomas chmod 755 $testroot/wt/foo
1489 24f136e0 2021-11-20 thomas (cd $testroot/wt && got commit -m 'change binary file' > /dev/null)
1490 24f136e0 2021-11-20 thomas local commit_id3=`git_show_head $testroot/repo`
1491 24f136e0 2021-11-20 thomas
1492 24f136e0 2021-11-20 thomas (cd $testroot/wt && got rm foo >/dev/null)
1493 24f136e0 2021-11-20 thomas (cd $testroot/wt && got commit -m 'remove binary file' > /dev/null)
1494 24f136e0 2021-11-20 thomas local commit_id4=`git_show_head $testroot/repo`
1495 24f136e0 2021-11-20 thomas
1496 24f136e0 2021-11-20 thomas # backdate the work tree to make it usable for cherry-picking
1497 24f136e0 2021-11-20 thomas (cd $testroot/wt && got up -c $commit_id0 > /dev/null)
1498 24f136e0 2021-11-20 thomas
1499 24f136e0 2021-11-20 thomas # cherry-pick addition of a binary file
1500 24f136e0 2021-11-20 thomas (cd $testroot/wt && got cy $commit_id1 > $testroot/stdout)
1501 24f136e0 2021-11-20 thomas
1502 24f136e0 2021-11-20 thomas echo "A foo" > $testroot/stdout.expected
1503 24f136e0 2021-11-20 thomas echo "Merged commit $commit_id1" >> $testroot/stdout.expected
1504 24f136e0 2021-11-20 thomas
1505 24f136e0 2021-11-20 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1506 24f136e0 2021-11-20 thomas ret="$?"
1507 24f136e0 2021-11-20 thomas if [ "$ret" != "0" ]; then
1508 24f136e0 2021-11-20 thomas diff -u $testroot/stdout.expected $testroot/stdout
1509 24f136e0 2021-11-20 thomas test_done "$testroot" "$ret"
1510 24f136e0 2021-11-20 thomas return 1
1511 24f136e0 2021-11-20 thomas fi
1512 24f136e0 2021-11-20 thomas
1513 24f136e0 2021-11-20 thomas cp /bin/ls $testroot/content.expected
1514 24f136e0 2021-11-20 thomas chmod 755 $testroot/content.expected
1515 24f136e0 2021-11-20 thomas cp $testroot/wt/foo $testroot/content
1516 24f136e0 2021-11-20 thomas cmp -s $testroot/content.expected $testroot/content
1517 24f136e0 2021-11-20 thomas ret="$?"
1518 24f136e0 2021-11-20 thomas if [ "$ret" != "0" ]; then
1519 24f136e0 2021-11-20 thomas diff -u $testroot/content.expected $testroot/content
1520 24f136e0 2021-11-20 thomas test_done "$testroot" "$ret"
1521 24f136e0 2021-11-20 thomas return 1
1522 24f136e0 2021-11-20 thomas fi
1523 24f136e0 2021-11-20 thomas
1524 24f136e0 2021-11-20 thomas # cherry-pick modification of a binary file
1525 24f136e0 2021-11-20 thomas (cd $testroot/wt && got cy $commit_id2 > $testroot/stdout)
1526 24f136e0 2021-11-20 thomas
1527 24f136e0 2021-11-20 thomas echo "G foo" > $testroot/stdout.expected
1528 24f136e0 2021-11-20 thomas echo "Merged commit $commit_id2" >> $testroot/stdout.expected
1529 24f136e0 2021-11-20 thomas
1530 24f136e0 2021-11-20 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1531 24f136e0 2021-11-20 thomas ret="$?"
1532 24f136e0 2021-11-20 thomas if [ "$ret" != "0" ]; then
1533 24f136e0 2021-11-20 thomas diff -u $testroot/stdout.expected $testroot/stdout
1534 24f136e0 2021-11-20 thomas test_done "$testroot" "$ret"
1535 24f136e0 2021-11-20 thomas return 1
1536 24f136e0 2021-11-20 thomas fi
1537 24f136e0 2021-11-20 thomas
1538 24f136e0 2021-11-20 thomas cp /bin/cat $testroot/content.expected
1539 24f136e0 2021-11-20 thomas chmod 755 $testroot/content.expected
1540 24f136e0 2021-11-20 thomas cp $testroot/wt/foo $testroot/content
1541 24f136e0 2021-11-20 thomas cmp -s $testroot/content.expected $testroot/content
1542 24f136e0 2021-11-20 thomas ret="$?"
1543 24f136e0 2021-11-20 thomas if [ "$ret" != "0" ]; then
1544 24f136e0 2021-11-20 thomas diff -u $testroot/content.expected $testroot/content
1545 24f136e0 2021-11-20 thomas test_done "$testroot" "$ret"
1546 24f136e0 2021-11-20 thomas return 1
1547 24f136e0 2021-11-20 thomas fi
1548 24f136e0 2021-11-20 thomas
1549 24f136e0 2021-11-20 thomas # cherry-pick conflicting addition of a binary file
1550 24f136e0 2021-11-20 thomas (cd $testroot/wt && got cy $commit_id1 > $testroot/stdout)
1551 24f136e0 2021-11-20 thomas
1552 24f136e0 2021-11-20 thomas echo "C foo" > $testroot/stdout.expected
1553 24f136e0 2021-11-20 thomas echo "Merged commit $commit_id1" >> $testroot/stdout.expected
1554 24f136e0 2021-11-20 thomas echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
1555 24f136e0 2021-11-20 thomas
1556 24f136e0 2021-11-20 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1557 24f136e0 2021-11-20 thomas ret="$?"
1558 24f136e0 2021-11-20 thomas if [ "$ret" != "0" ]; then
1559 24f136e0 2021-11-20 thomas diff -u $testroot/stdout.expected $testroot/stdout
1560 24f136e0 2021-11-20 thomas test_done "$testroot" "$ret"
1561 24f136e0 2021-11-20 thomas return 1
1562 24f136e0 2021-11-20 thomas fi
1563 24f136e0 2021-11-20 thomas
1564 24f136e0 2021-11-20 thomas echo "Binary files differ and cannot be merged automatically:" \
1565 24f136e0 2021-11-20 thomas > $testroot/content.expected
1566 24f136e0 2021-11-20 thomas echo "<<<<<<< merged change: commit $commit_id1" \
1567 24f136e0 2021-11-20 thomas >> $testroot/content.expected
1568 24f136e0 2021-11-20 thomas echo -n "file " >> $testroot/content.expected
1569 24f136e0 2021-11-20 thomas ls $testroot/wt/foo-1-* >> $testroot/content.expected
1570 24f136e0 2021-11-20 thomas echo '=======' >> $testroot/content.expected
1571 24f136e0 2021-11-20 thomas echo -n "file " >> $testroot/content.expected
1572 24f136e0 2021-11-20 thomas ls $testroot/wt/foo-2-* >> $testroot/content.expected
1573 24f136e0 2021-11-20 thomas echo '>>>>>>>' >> $testroot/content.expected
1574 24f136e0 2021-11-20 thomas cp $testroot/wt/foo $testroot/content
1575 24f136e0 2021-11-20 thomas cmp -s $testroot/content.expected $testroot/content
1576 24f136e0 2021-11-20 thomas ret="$?"
1577 24f136e0 2021-11-20 thomas if [ "$ret" != "0" ]; then
1578 24f136e0 2021-11-20 thomas diff -u $testroot/content.expected $testroot/content
1579 24f136e0 2021-11-20 thomas test_done "$testroot" "$ret"
1580 24f136e0 2021-11-20 thomas return 1
1581 24f136e0 2021-11-20 thomas fi
1582 24f136e0 2021-11-20 thomas
1583 24f136e0 2021-11-20 thomas # revert local changes to allow further testing
1584 24f136e0 2021-11-20 thomas (cd $testroot/wt && got revert -R . >/dev/null)
1585 24f136e0 2021-11-20 thomas
1586 24f136e0 2021-11-20 thomas (cd $testroot/wt && got status > $testroot/stdout)
1587 24f136e0 2021-11-20 thomas echo '? foo' > $testroot/stdout.expected
1588 24f136e0 2021-11-20 thomas echo -n '? ' >> $testroot/stdout.expected
1589 24f136e0 2021-11-20 thomas (cd $testroot/wt && ls foo-1-* >> $testroot/stdout.expected)
1590 24f136e0 2021-11-20 thomas echo -n '? ' >> $testroot/stdout.expected
1591 24f136e0 2021-11-20 thomas (cd $testroot/wt && ls foo-2-* >> $testroot/stdout.expected)
1592 24f136e0 2021-11-20 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1593 24f136e0 2021-11-20 thomas ret="$?"
1594 24f136e0 2021-11-20 thomas if [ "$ret" != "0" ]; then
1595 24f136e0 2021-11-20 thomas diff -u $testroot/stdout.expected $testroot/stdout
1596 24f136e0 2021-11-20 thomas test_done "$testroot" "$ret"
1597 24f136e0 2021-11-20 thomas return 1
1598 24f136e0 2021-11-20 thomas fi
1599 24f136e0 2021-11-20 thomas
1600 24f136e0 2021-11-20 thomas # tidy up
1601 24f136e0 2021-11-20 thomas rm $testroot/wt/foo $testroot/wt/foo-1-* $testroot/wt/foo-2-*
1602 24f136e0 2021-11-20 thomas (cd $testroot/wt && got up -c $commit_id1 > /dev/null)
1603 24f136e0 2021-11-20 thomas
1604 24f136e0 2021-11-20 thomas # cherry-pick conflicting modification of a binary file
1605 24f136e0 2021-11-20 thomas (cd $testroot/wt && got cy $commit_id3 > $testroot/stdout)
1606 24f136e0 2021-11-20 thomas
1607 24f136e0 2021-11-20 thomas echo "C foo" > $testroot/stdout.expected
1608 24f136e0 2021-11-20 thomas echo "Merged commit $commit_id3" >> $testroot/stdout.expected
1609 24f136e0 2021-11-20 thomas echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
1610 24f136e0 2021-11-20 thomas
1611 24f136e0 2021-11-20 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1612 24f136e0 2021-11-20 thomas ret="$?"
1613 24f136e0 2021-11-20 thomas if [ "$ret" != "0" ]; then
1614 24f136e0 2021-11-20 thomas diff -u $testroot/stdout.expected $testroot/stdout
1615 24f136e0 2021-11-20 thomas test_done "$testroot" "$ret"
1616 24f136e0 2021-11-20 thomas return 1
1617 24f136e0 2021-11-20 thomas fi
1618 24f136e0 2021-11-20 thomas
1619 24f136e0 2021-11-20 thomas echo "Binary files differ and cannot be merged automatically:" \
1620 24f136e0 2021-11-20 thomas > $testroot/content.expected
1621 24f136e0 2021-11-20 thomas echo '<<<<<<<' >> $testroot/content.expected
1622 24f136e0 2021-11-20 thomas echo -n "file " >> $testroot/content.expected
1623 24f136e0 2021-11-20 thomas ls $testroot/wt/foo-1-* >> $testroot/content.expected
1624 24f136e0 2021-11-20 thomas echo "||||||| 3-way merge base: commit $commit_id2" \
1625 24f136e0 2021-11-20 thomas >> $testroot/content.expected
1626 24f136e0 2021-11-20 thomas echo -n "file " >> $testroot/content.expected
1627 24f136e0 2021-11-20 thomas ls $testroot/wt/foo-orig-* >> $testroot/content.expected
1628 24f136e0 2021-11-20 thomas echo '=======' >> $testroot/content.expected
1629 24f136e0 2021-11-20 thomas echo -n "file " >> $testroot/content.expected
1630 24f136e0 2021-11-20 thomas ls $testroot/wt/foo-2-* >> $testroot/content.expected
1631 24f136e0 2021-11-20 thomas echo ">>>>>>> merged change: commit $commit_id3" \
1632 24f136e0 2021-11-20 thomas >> $testroot/content.expected
1633 24f136e0 2021-11-20 thomas cp $testroot/wt/foo $testroot/content
1634 24f136e0 2021-11-20 thomas cmp -s $testroot/content.expected $testroot/content
1635 24f136e0 2021-11-20 thomas ret="$?"
1636 24f136e0 2021-11-20 thomas if [ "$ret" != "0" ]; then
1637 24f136e0 2021-11-20 thomas diff -u $testroot/content.expected $testroot/content
1638 24f136e0 2021-11-20 thomas test_done "$testroot" "$ret"
1639 24f136e0 2021-11-20 thomas return 1
1640 24f136e0 2021-11-20 thomas fi
1641 24f136e0 2021-11-20 thomas
1642 24f136e0 2021-11-20 thomas cp /bin/ls $testroot/content.expected
1643 24f136e0 2021-11-20 thomas chmod 755 $testroot/content.expected
1644 24f136e0 2021-11-20 thomas cat $testroot/wt/foo-1-* > $testroot/content
1645 24f136e0 2021-11-20 thomas cmp -s $testroot/content.expected $testroot/content
1646 24f136e0 2021-11-20 thomas ret="$?"
1647 24f136e0 2021-11-20 thomas if [ "$ret" != "0" ]; then
1648 24f136e0 2021-11-20 thomas diff -u $testroot/content.expected $testroot/content
1649 24f136e0 2021-11-20 thomas test_done "$testroot" "$ret"
1650 24f136e0 2021-11-20 thomas return 1
1651 24f136e0 2021-11-20 thomas fi
1652 24f136e0 2021-11-20 thomas
1653 24f136e0 2021-11-20 thomas cp /bin/cp $testroot/content.expected
1654 24f136e0 2021-11-20 thomas chmod 755 $testroot/content.expected
1655 24f136e0 2021-11-20 thomas cat $testroot/wt/foo-2-* > $testroot/content
1656 24f136e0 2021-11-20 thomas cmp -s $testroot/content.expected $testroot/content
1657 24f136e0 2021-11-20 thomas ret="$?"
1658 24f136e0 2021-11-20 thomas if [ "$ret" != "0" ]; then
1659 24f136e0 2021-11-20 thomas diff -u $testroot/content.expected $testroot/content
1660 24f136e0 2021-11-20 thomas test_done "$testroot" "$ret"
1661 24f136e0 2021-11-20 thomas return 1
1662 24f136e0 2021-11-20 thomas fi
1663 24f136e0 2021-11-20 thomas
1664 24f136e0 2021-11-20 thomas # revert local changes to allow further testing
1665 24f136e0 2021-11-20 thomas (cd $testroot/wt && got revert -R . > /dev/null)
1666 24f136e0 2021-11-20 thomas rm $testroot/wt/foo-1-*
1667 24f136e0 2021-11-20 thomas rm $testroot/wt/foo-2-*
1668 24f136e0 2021-11-20 thomas (cd $testroot/wt && got up -c $commit_id3 > /dev/null)
1669 24f136e0 2021-11-20 thomas
1670 24f136e0 2021-11-20 thomas # cherry-pick deletion of a binary file
1671 24f136e0 2021-11-20 thomas (cd $testroot/wt && got cy $commit_id4 > $testroot/stdout)
1672 24f136e0 2021-11-20 thomas
1673 24f136e0 2021-11-20 thomas echo "D foo" > $testroot/stdout.expected
1674 24f136e0 2021-11-20 thomas echo "Merged commit $commit_id4" >> $testroot/stdout.expected
1675 24f136e0 2021-11-20 thomas
1676 24f136e0 2021-11-20 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1677 24f136e0 2021-11-20 thomas ret="$?"
1678 24f136e0 2021-11-20 thomas if [ "$ret" != "0" ]; then
1679 24f136e0 2021-11-20 thomas diff -u $testroot/stdout.expected $testroot/stdout
1680 24f136e0 2021-11-20 thomas test_done "$testroot" "$ret"
1681 24f136e0 2021-11-20 thomas return 1
1682 24f136e0 2021-11-20 thomas fi
1683 24f136e0 2021-11-20 thomas
1684 24f136e0 2021-11-20 thomas if [ -e $testroot/wt/foo ]; then
1685 24f136e0 2021-11-20 thomas echo "removed file foo still exists on disk" >&2
1686 24f136e0 2021-11-20 thomas test_done "$testroot" "1"
1687 24f136e0 2021-11-20 thomas return 1
1688 24f136e0 2021-11-20 thomas fi
1689 24f136e0 2021-11-20 thomas test_done "$testroot" "0"
1690 dc2a05aa 2021-10-08 thomas }
1691 dc2a05aa 2021-10-08 thomas
1692 7fb414ae 2020-08-08 stsp test_parseargs "$@"
1693 234035bc 2019-06-01 stsp run_test test_cherrypick_basic
1694 03415a1a 2019-06-02 stsp run_test test_cherrypick_root_commit
1695 ceb466a7 2020-04-18 stsp run_test test_cherrypick_into_work_tree_with_conflicts
1696 ed99f061 2021-09-03 stsp run_test test_cherrypick_into_work_tree_with_mixed_commits
1697 e7303626 2020-05-14 stsp run_test test_cherrypick_modified_submodule
1698 e7303626 2020-05-14 stsp run_test test_cherrypick_added_submodule
1699 e7303626 2020-05-14 stsp run_test test_cherrypick_conflict_wt_file_vs_repo_submodule
1700 af57b12a 2020-07-23 stsp run_test test_cherrypick_modified_symlinks
1701 e26bafba 2020-07-23 stsp run_test test_cherrypick_symlink_conflicts
1702 69d57f3d 2020-07-31 stsp run_test test_cherrypick_with_path_prefix_and_empty_tree
1703 cce854ad 2021-04-13 stsp run_test test_cherrypick_conflict_no_eol
1704 cce854ad 2021-04-13 stsp run_test test_cherrypick_conflict_no_eol2
1705 3cd22b21 2021-05-31 stsp run_test test_cherrypick_unrelated_changes
1706 0baddd91 2021-09-03 stsp run_test test_cherrypick_same_branch
1707 dc2a05aa 2021-10-08 thomas run_test test_cherrypick_dot_on_a_line_by_itself
1708 24f136e0 2021-11-20 thomas run_test test_cherrypick_binary_file