3 234035bc 2019-06-01 stsp # Copyright (c) 2019 Stefan Sperling <stsp@openbsd.org>
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.
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.
17 234035bc 2019-06-01 stsp . ./common.sh
19 f6cae3ed 2020-09-13 naddy test_cherrypick_basic() {
20 234035bc 2019-06-01 stsp local testroot=`test_init cherrypick_basic`
22 234035bc 2019-06-01 stsp got checkout $testroot/repo $testroot/wt > /dev/null
24 234035bc 2019-06-01 stsp if [ "$ret" != "0" ]; then
25 234035bc 2019-06-01 stsp test_done "$testroot" "$ret"
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"
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"
39 234035bc 2019-06-01 stsp local branch_rev=`git_show_head $testroot/repo`
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`
45 234035bc 2019-06-01 stsp (cd $testroot/wt && got cherrypick $branch_rev > $testroot/stdout)
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
52 234035bc 2019-06-01 stsp cmp -s $testroot/stdout.expected $testroot/stdout
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"
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
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"
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"
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
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"
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
90 2b92fad7 2019-06-02 stsp (cd $testroot/wt && got status > $testroot/stdout)
92 2b92fad7 2019-06-02 stsp cmp -s $testroot/stdout.expected $testroot/stdout
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"
100 243a13f5 2021-09-02 stsp (cd $testroot/wt && got cherrypick $branch_rev2 > $testroot/stdout)
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
105 243a13f5 2021-09-02 stsp cmp -s $testroot/stdout.expected $testroot/stdout
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"
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
117 243a13f5 2021-09-02 stsp (cd $testroot/wt && got status > $testroot/stdout)
119 243a13f5 2021-09-02 stsp cmp -s $testroot/stdout.expected $testroot/stdout
121 243a13f5 2021-09-02 stsp if [ "$ret" != "0" ]; then
122 243a13f5 2021-09-02 stsp diff -u $testroot/stdout.expected $testroot/stdout
124 234035bc 2019-06-01 stsp test_done "$testroot" "$ret"
127 f6cae3ed 2020-09-13 naddy test_cherrypick_root_commit() {
128 03415a1a 2019-06-02 stsp local testroot=`test_init cherrypick_root_commit`
130 03415a1a 2019-06-02 stsp got checkout $testroot/repo $testroot/wt > /dev/null
132 03415a1a 2019-06-02 stsp if [ "$ret" != "0" ]; then
133 03415a1a 2019-06-02 stsp test_done "$testroot" "$ret"
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"
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"
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`
153 03415a1a 2019-06-02 stsp (cd $testroot/wt && got cherrypick $root_commit > $testroot/stdout)
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
158 03415a1a 2019-06-02 stsp cmp -s $testroot/stdout.expected $testroot/stdout
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"
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
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"
177 03415a1a 2019-06-02 stsp echo 'A epsilon/new' > $testroot/stdout.expected
179 03415a1a 2019-06-02 stsp (cd $testroot/wt && got status > $testroot/stdout)
181 03415a1a 2019-06-02 stsp cmp -s $testroot/stdout.expected $testroot/stdout
183 03415a1a 2019-06-02 stsp if [ "$ret" != "0" ]; then
184 03415a1a 2019-06-02 stsp diff -u $testroot/stdout.expected $testroot/stdout
186 03415a1a 2019-06-02 stsp test_done "$testroot" "$ret"
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`
192 ceb466a7 2020-04-18 stsp got checkout $testroot/repo $testroot/wt > /dev/null
194 ceb466a7 2020-04-18 stsp if [ "$ret" != "0" ]; then
195 ceb466a7 2020-04-18 stsp test_done "$testroot" "$ret"
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"
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"
209 ceb466a7 2020-04-18 stsp local branch_rev=`git_show_head $testroot/repo`
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
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
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"
229 ceb466a7 2020-04-18 stsp (cd $testroot/wt && got cherrypick $branch_rev \
230 ceb466a7 2020-04-18 stsp > $testroot/stdout 2> $testroot/stderr)
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"
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
244 ceb466a7 2020-04-18 stsp cmp -s $testroot/stdout.expected $testroot/stdout
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"
252 ceb466a7 2020-04-18 stsp cmp -s $testroot/stderr.expected $testroot/stderr
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"
260 ceb466a7 2020-04-18 stsp cmp -s $testroot/content.expected $testroot/wt/alpha
262 ceb466a7 2020-04-18 stsp if [ "$ret" != "0" ]; then
263 ceb466a7 2020-04-18 stsp diff -u $testroot/content.expected $testroot/wt/alpha
265 e7303626 2020-05-14 stsp test_done "$testroot" "$ret"
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`
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`
276 ed99f061 2021-09-03 stsp got checkout $testroot/repo $testroot/wt > /dev/null
278 ed99f061 2021-09-03 stsp if [ "$ret" != "0" ]; then
279 ed99f061 2021-09-03 stsp test_done "$testroot" "$ret"
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"
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"
292 ed99f061 2021-09-03 stsp local branch_rev=`git_show_head $testroot/repo`
294 ed99f061 2021-09-03 stsp (cd $testroot/wt && got update -c $first_rev alpha >/dev/null)
296 ed99f061 2021-09-03 stsp (cd $testroot/wt && got cherrypick $branch_rev \
297 ed99f061 2021-09-03 stsp > $testroot/stdout 2> $testroot/stderr)
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"
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
311 ed99f061 2021-09-03 stsp cmp -s $testroot/stdout.expected $testroot/stdout
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"
319 ed99f061 2021-09-03 stsp cmp -s $testroot/stderr.expected $testroot/stderr
321 ed99f061 2021-09-03 stsp if [ "$ret" != "0" ]; then
322 ed99f061 2021-09-03 stsp diff -u $testroot/stderr.expected $testroot/stderr
324 ed99f061 2021-09-03 stsp test_done "$testroot" "$ret"
328 f6cae3ed 2020-09-13 naddy test_cherrypick_modified_submodule() {
329 e7303626 2020-05-14 stsp local testroot=`test_init cherrypick_modified_submodules`
331 e7303626 2020-05-14 stsp make_single_file_repo $testroot/repo2 foo
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')
336 e7303626 2020-05-14 stsp got checkout $testroot/repo $testroot/wt > /dev/null
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')
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`
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)
352 e7303626 2020-05-14 stsp echo -n > $testroot/stdout.expected
353 e7303626 2020-05-14 stsp cmp -s $testroot/stdout.expected $testroot/stdout
355 e7303626 2020-05-14 stsp if [ "$ret" != "0" ]; then
356 e7303626 2020-05-14 stsp diff -u $testroot/stdout.expected $testroot/stdout
358 e7303626 2020-05-14 stsp test_done "$testroot" "$ret"
361 f6cae3ed 2020-09-13 naddy test_cherrypick_added_submodule() {
362 e7303626 2020-05-14 stsp local testroot=`test_init cherrypick_added_submodules`
364 e7303626 2020-05-14 stsp got checkout $testroot/repo $testroot/wt > /dev/null
366 e7303626 2020-05-14 stsp make_single_file_repo $testroot/repo2 foo
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`
374 e7303626 2020-05-14 stsp (cd $testroot/wt && got cherrypick $commit_id > $testroot/stdout)
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
380 e7303626 2020-05-14 stsp if [ "$ret" != "0" ]; then
381 e7303626 2020-05-14 stsp diff -u $testroot/stdout.expected $testroot/stdout
383 ceb466a7 2020-04-18 stsp test_done "$testroot" "$ret"
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`
389 e7303626 2020-05-14 stsp got checkout $testroot/repo $testroot/wt > /dev/null
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)
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"
402 e7303626 2020-05-14 stsp make_single_file_repo $testroot/repo2 foo
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`
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
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)
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
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"
427 e7303626 2020-05-14 stsp (cd $testroot/wt && got status > $testroot/stdout)
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
433 e7303626 2020-05-14 stsp if [ "$ret" != "0" ]; then
434 e7303626 2020-05-14 stsp diff -u $testroot/stdout.expected $testroot/stdout
436 e7303626 2020-05-14 stsp test_done "$testroot" "$ret"
439 f6cae3ed 2020-09-13 naddy test_cherrypick_modified_symlinks() {
440 af57b12a 2020-07-23 stsp local testroot=`test_init cherrypick_modified_symlinks`
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`
451 af57b12a 2020-07-23 stsp got branch -r $testroot/repo foo
453 af57b12a 2020-07-23 stsp got checkout -b foo $testroot/repo $testroot/wt > /dev/null
455 af57b12a 2020-07-23 stsp (cd $testroot/repo && ln -sf beta alpha.link)
456 af57b12a 2020-07-23 stsp (cd $testroot/repo && ln -sfh gamma epsilon.link)
457 af57b12a 2020-07-23 stsp (cd $testroot/repo && ln -sf ../gamma/delta epsilon/beta.link)
458 af57b12a 2020-07-23 stsp (cd $testroot/repo && ln -sf .got/bar $testroot/repo/dotgotfoo.link)
459 af57b12a 2020-07-23 stsp (cd $testroot/repo && git rm -q nonexistent.link)
460 af57b12a 2020-07-23 stsp (cd $testroot/repo && ln -sf epsilon/zeta zeta.link)
461 af57b12a 2020-07-23 stsp (cd $testroot/repo && git add .)
462 af57b12a 2020-07-23 stsp git_commit $testroot/repo -m "change symlinks"
463 af57b12a 2020-07-23 stsp local commit_id2=`git_show_head $testroot/repo`
465 af57b12a 2020-07-23 stsp (cd $testroot/wt && got cherrypick $commit_id2 > $testroot/stdout)
467 af57b12a 2020-07-23 stsp echo "G alpha.link" > $testroot/stdout.expected
468 af57b12a 2020-07-23 stsp echo "G epsilon/beta.link" >> $testroot/stdout.expected
469 af57b12a 2020-07-23 stsp echo "A dotgotfoo.link" >> $testroot/stdout.expected
470 af57b12a 2020-07-23 stsp echo "G epsilon.link" >> $testroot/stdout.expected
471 af57b12a 2020-07-23 stsp echo "D nonexistent.link" >> $testroot/stdout.expected
472 af57b12a 2020-07-23 stsp echo "A zeta.link" >> $testroot/stdout.expected
473 af57b12a 2020-07-23 stsp echo "Merged commit $commit_id2" >> $testroot/stdout.expected
474 af57b12a 2020-07-23 stsp cmp -s $testroot/stdout.expected $testroot/stdout
476 af57b12a 2020-07-23 stsp if [ "$ret" != "0" ]; then
477 af57b12a 2020-07-23 stsp diff -u $testroot/stdout.expected $testroot/stdout
478 af57b12a 2020-07-23 stsp test_done "$testroot" "$ret"
482 af57b12a 2020-07-23 stsp if ! [ -h $testroot/wt/alpha.link ]; then
483 af57b12a 2020-07-23 stsp echo "alpha.link is not a symlink"
484 af57b12a 2020-07-23 stsp test_done "$testroot" "1"
488 af57b12a 2020-07-23 stsp readlink $testroot/wt/alpha.link > $testroot/stdout
489 af57b12a 2020-07-23 stsp echo "beta" > $testroot/stdout.expected
490 af57b12a 2020-07-23 stsp cmp -s $testroot/stdout.expected $testroot/stdout
492 af57b12a 2020-07-23 stsp if [ "$ret" != "0" ]; then
493 af57b12a 2020-07-23 stsp diff -u $testroot/stdout.expected $testroot/stdout
494 af57b12a 2020-07-23 stsp test_done "$testroot" "$ret"
498 af57b12a 2020-07-23 stsp if ! [ -h $testroot/wt/epsilon.link ]; then
499 af57b12a 2020-07-23 stsp echo "epsilon.link is not a symlink"
500 af57b12a 2020-07-23 stsp test_done "$testroot" "1"
504 af57b12a 2020-07-23 stsp readlink $testroot/wt/epsilon.link > $testroot/stdout
505 af57b12a 2020-07-23 stsp echo "gamma" > $testroot/stdout.expected
506 af57b12a 2020-07-23 stsp cmp -s $testroot/stdout.expected $testroot/stdout
508 af57b12a 2020-07-23 stsp if [ "$ret" != "0" ]; then
509 af57b12a 2020-07-23 stsp diff -u $testroot/stdout.expected $testroot/stdout
510 af57b12a 2020-07-23 stsp test_done "$testroot" "$ret"
514 af57b12a 2020-07-23 stsp if [ -h $testroot/wt/passwd.link ]; then
515 af57b12a 2020-07-23 stsp echo -n "passwd.link symlink points outside of work tree: " >&2
516 af57b12a 2020-07-23 stsp readlink $testroot/wt/passwd.link >&2
517 af57b12a 2020-07-23 stsp test_done "$testroot" "1"
521 af57b12a 2020-07-23 stsp echo -n "/etc/passwd" > $testroot/content.expected
522 af57b12a 2020-07-23 stsp cp $testroot/wt/passwd.link $testroot/content
524 af57b12a 2020-07-23 stsp cmp -s $testroot/content.expected $testroot/content
526 af57b12a 2020-07-23 stsp if [ "$ret" != "0" ]; then
527 af57b12a 2020-07-23 stsp diff -u $testroot/content.expected $testroot/content
528 af57b12a 2020-07-23 stsp test_done "$testroot" "$ret"
532 af57b12a 2020-07-23 stsp readlink $testroot/wt/epsilon/beta.link > $testroot/stdout
533 af57b12a 2020-07-23 stsp echo "../gamma/delta" > $testroot/stdout.expected
534 e26bafba 2020-07-23 stsp cmp -s $testroot/stdout.expected $testroot/stdout
536 e26bafba 2020-07-23 stsp if [ "$ret" != "0" ]; then
537 e26bafba 2020-07-23 stsp diff -u $testroot/stdout.expected $testroot/stdout
538 e26bafba 2020-07-23 stsp test_done "$testroot" "$ret"
542 e26bafba 2020-07-23 stsp if [ -h $testroot/wt/nonexistent.link ]; then
543 e26bafba 2020-07-23 stsp echo -n "nonexistent.link still exists on disk: " >&2
544 e26bafba 2020-07-23 stsp readlink $testroot/wt/nonexistent.link >&2
545 e26bafba 2020-07-23 stsp test_done "$testroot" "1"
549 e26bafba 2020-07-23 stsp test_done "$testroot" "0"
552 f6cae3ed 2020-09-13 naddy test_cherrypick_symlink_conflicts() {
553 e26bafba 2020-07-23 stsp local testroot=`test_init cherrypick_symlink_conflicts`
555 e26bafba 2020-07-23 stsp (cd $testroot/repo && ln -s alpha alpha.link)
556 e26bafba 2020-07-23 stsp (cd $testroot/repo && ln -s epsilon epsilon.link)
557 e26bafba 2020-07-23 stsp (cd $testroot/repo && ln -s /etc/passwd passwd.link)
558 e26bafba 2020-07-23 stsp (cd $testroot/repo && ln -s ../beta epsilon/beta.link)
559 e26bafba 2020-07-23 stsp (cd $testroot/repo && ln -s nonexistent nonexistent.link)
560 e26bafba 2020-07-23 stsp (cd $testroot/repo && ln -sf epsilon/zeta zeta.link)
561 e26bafba 2020-07-23 stsp (cd $testroot/repo && git add .)
562 e26bafba 2020-07-23 stsp git_commit $testroot/repo -m "add symlinks"
563 e26bafba 2020-07-23 stsp local commit_id1=`git_show_head $testroot/repo`
565 e26bafba 2020-07-23 stsp (cd $testroot/repo && ln -sf beta alpha.link)
566 fba9f79c 2020-07-23 stsp (cd $testroot/repo && ln -sf beta boo.link)
567 e26bafba 2020-07-23 stsp (cd $testroot/repo && ln -sfh gamma epsilon.link)
568 e26bafba 2020-07-23 stsp (cd $testroot/repo && ln -sf ../gamma/delta epsilon/beta.link)
569 e26bafba 2020-07-23 stsp echo 'this is regular file foo' > $testroot/repo/dotgotfoo.link
570 e26bafba 2020-07-23 stsp (cd $testroot/repo && ln -sf .got/bar dotgotbar.link)
571 e26bafba 2020-07-23 stsp (cd $testroot/repo && git rm -q nonexistent.link)
572 e26bafba 2020-07-23 stsp (cd $testroot/repo && ln -sf gamma/delta zeta.link)
573 e26bafba 2020-07-23 stsp (cd $testroot/repo && ln -sf alpha new.link)
574 e26bafba 2020-07-23 stsp (cd $testroot/repo && git add .)
575 e26bafba 2020-07-23 stsp git_commit $testroot/repo -m "change symlinks"
576 e26bafba 2020-07-23 stsp local commit_id2=`git_show_head $testroot/repo`
578 e26bafba 2020-07-23 stsp got branch -r $testroot/repo -c $commit_id1 foo
579 e26bafba 2020-07-23 stsp got checkout -b foo $testroot/repo $testroot/wt > /dev/null
581 e26bafba 2020-07-23 stsp # modified symlink to file A vs modified symlink to file B
582 e26bafba 2020-07-23 stsp (cd $testroot/wt && ln -sf gamma/delta alpha.link)
583 e26bafba 2020-07-23 stsp # modified symlink to dir A vs modified symlink to file B
584 e26bafba 2020-07-23 stsp (cd $testroot/wt && ln -sfh beta epsilon.link)
585 e26bafba 2020-07-23 stsp # modeified symlink to file A vs modified symlink to dir B
586 e26bafba 2020-07-23 stsp (cd $testroot/wt && ln -sfh ../gamma epsilon/beta.link)
587 e26bafba 2020-07-23 stsp # added regular file A vs added bad symlink to file A
588 e26bafba 2020-07-23 stsp (cd $testroot/wt && ln -sf .got/bar dotgotfoo.link)
589 3b9f0f87 2020-07-23 stsp (cd $testroot/wt && got add dotgotfoo.link > /dev/null)
590 e26bafba 2020-07-23 stsp # added bad symlink to file A vs added regular file A
591 e26bafba 2020-07-23 stsp echo 'this is regular file bar' > $testroot/wt/dotgotbar.link
592 d219f183 2020-07-23 stsp (cd $testroot/wt && got add dotgotbar.link > /dev/null)
593 fba9f79c 2020-07-23 stsp # added symlink to file A vs unversioned file A
594 fba9f79c 2020-07-23 stsp echo 'this is unversioned file boo' > $testroot/wt/boo.link
595 e26bafba 2020-07-23 stsp # removed symlink to non-existent file A vs modified symlink
596 e26bafba 2020-07-23 stsp # to nonexistent file B
597 e26bafba 2020-07-23 stsp (cd $testroot/wt && ln -sf nonexistent2 nonexistent.link)
598 e26bafba 2020-07-23 stsp # modified symlink to file A vs removed symlink to file A
599 e26bafba 2020-07-23 stsp (cd $testroot/wt && got rm zeta.link > /dev/null)
600 e26bafba 2020-07-23 stsp # added symlink to file A vs added symlink to file B
601 e26bafba 2020-07-23 stsp (cd $testroot/wt && ln -sf beta new.link)
602 e26bafba 2020-07-23 stsp (cd $testroot/wt && got add new.link > /dev/null)
603 35213c7c 2020-07-23 stsp (cd $testroot/wt && got commit -S -m "change symlinks on foo" \
604 e26bafba 2020-07-23 stsp > /dev/null)
606 e26bafba 2020-07-23 stsp (cd $testroot/wt && got update >/dev/null)
607 e26bafba 2020-07-23 stsp (cd $testroot/wt && got cherrypick $commit_id2 > $testroot/stdout)
609 e26bafba 2020-07-23 stsp echo -n > $testroot/stdout.expected
610 11cc08c1 2020-07-23 stsp echo "C alpha.link" >> $testroot/stdout.expected
611 11cc08c1 2020-07-23 stsp echo "C epsilon/beta.link" >> $testroot/stdout.expected
612 c90c8ce3 2020-07-23 stsp echo "? boo.link" >> $testroot/stdout.expected
613 11cc08c1 2020-07-23 stsp echo "C epsilon.link" >> $testroot/stdout.expected
614 fba9f79c 2020-07-23 stsp echo "C dotgotbar.link" >> $testroot/stdout.expected
615 3b9f0f87 2020-07-23 stsp echo "C dotgotfoo.link" >> $testroot/stdout.expected
616 e26bafba 2020-07-23 stsp echo "D nonexistent.link" >> $testroot/stdout.expected
617 e26bafba 2020-07-23 stsp echo "! zeta.link" >> $testroot/stdout.expected
618 11cc08c1 2020-07-23 stsp echo "C new.link" >> $testroot/stdout.expected
619 e26bafba 2020-07-23 stsp echo "Merged commit $commit_id2" >> $testroot/stdout.expected
620 3b9f0f87 2020-07-23 stsp echo "Files with new merge conflicts: 6" >> $testroot/stdout.expected
621 e26bafba 2020-07-23 stsp cmp -s $testroot/stdout.expected $testroot/stdout
623 e26bafba 2020-07-23 stsp if [ "$ret" != "0" ]; then
624 e26bafba 2020-07-23 stsp diff -u $testroot/stdout.expected $testroot/stdout
625 e26bafba 2020-07-23 stsp test_done "$testroot" "$ret"
629 11cc08c1 2020-07-23 stsp if [ -h $testroot/wt/alpha.link ]; then
630 11cc08c1 2020-07-23 stsp echo "alpha.link is a symlink"
631 e26bafba 2020-07-23 stsp test_done "$testroot" "1"
635 11cc08c1 2020-07-23 stsp echo "<<<<<<< merged change: commit $commit_id2" \
636 283102fc 2020-07-23 stsp > $testroot/content.expected
637 11cc08c1 2020-07-23 stsp echo "beta" >> $testroot/content.expected
638 11cc08c1 2020-07-23 stsp echo "3-way merge base: commit $commit_id1" \
639 11cc08c1 2020-07-23 stsp >> $testroot/content.expected
640 11cc08c1 2020-07-23 stsp echo "alpha" >> $testroot/content.expected
641 11cc08c1 2020-07-23 stsp echo "=======" >> $testroot/content.expected
642 11cc08c1 2020-07-23 stsp echo "gamma/delta" >> $testroot/content.expected
643 11cc08c1 2020-07-23 stsp echo '>>>>>>>' >> $testroot/content.expected
644 11cc08c1 2020-07-23 stsp echo -n "" >> $testroot/content.expected
646 11cc08c1 2020-07-23 stsp cp $testroot/wt/alpha.link $testroot/content
647 fba9f79c 2020-07-23 stsp cmp -s $testroot/content.expected $testroot/content
649 fba9f79c 2020-07-23 stsp if [ "$ret" != "0" ]; then
650 fba9f79c 2020-07-23 stsp diff -u $testroot/content.expected $testroot/content
651 fba9f79c 2020-07-23 stsp test_done "$testroot" "$ret"
655 c90c8ce3 2020-07-23 stsp if [ -h $testroot/wt/boo.link ]; then
656 c90c8ce3 2020-07-23 stsp echo "boo.link is a symlink"
657 fba9f79c 2020-07-23 stsp test_done "$testroot" "1"
661 c90c8ce3 2020-07-23 stsp echo "this is unversioned file boo" > $testroot/content.expected
662 fba9f79c 2020-07-23 stsp cp $testroot/wt/boo.link $testroot/content
663 11cc08c1 2020-07-23 stsp cmp -s $testroot/content.expected $testroot/content
665 e26bafba 2020-07-23 stsp if [ "$ret" != "0" ]; then
666 11cc08c1 2020-07-23 stsp diff -u $testroot/content.expected $testroot/content
667 e26bafba 2020-07-23 stsp test_done "$testroot" "$ret"
671 11cc08c1 2020-07-23 stsp if [ -h $testroot/wt/epsilon.link ]; then
672 11cc08c1 2020-07-23 stsp echo "epsilon.link is a symlink"
673 e26bafba 2020-07-23 stsp test_done "$testroot" "1"
677 11cc08c1 2020-07-23 stsp echo "<<<<<<< merged change: commit $commit_id2" \
678 283102fc 2020-07-23 stsp > $testroot/content.expected
679 11cc08c1 2020-07-23 stsp echo "gamma" >> $testroot/content.expected
680 11cc08c1 2020-07-23 stsp echo "3-way merge base: commit $commit_id1" \
681 11cc08c1 2020-07-23 stsp >> $testroot/content.expected
682 11cc08c1 2020-07-23 stsp echo "epsilon" >> $testroot/content.expected
683 11cc08c1 2020-07-23 stsp echo "=======" >> $testroot/content.expected
684 11cc08c1 2020-07-23 stsp echo "beta" >> $testroot/content.expected
685 11cc08c1 2020-07-23 stsp echo '>>>>>>>' >> $testroot/content.expected
686 11cc08c1 2020-07-23 stsp echo -n "" >> $testroot/content.expected
688 11cc08c1 2020-07-23 stsp cp $testroot/wt/epsilon.link $testroot/content
689 11cc08c1 2020-07-23 stsp cmp -s $testroot/content.expected $testroot/content
691 af57b12a 2020-07-23 stsp if [ "$ret" != "0" ]; then
692 11cc08c1 2020-07-23 stsp diff -u $testroot/content.expected $testroot/content
693 af57b12a 2020-07-23 stsp test_done "$testroot" "$ret"
697 e26bafba 2020-07-23 stsp if [ -h $testroot/wt/passwd.link ]; then
698 e26bafba 2020-07-23 stsp echo -n "passwd.link symlink points outside of work tree: " >&2
699 e26bafba 2020-07-23 stsp readlink $testroot/wt/passwd.link >&2
700 e26bafba 2020-07-23 stsp test_done "$testroot" "1"
704 e26bafba 2020-07-23 stsp echo -n "/etc/passwd" > $testroot/content.expected
705 e26bafba 2020-07-23 stsp cp $testroot/wt/passwd.link $testroot/content
707 e26bafba 2020-07-23 stsp cmp -s $testroot/content.expected $testroot/content
709 e26bafba 2020-07-23 stsp if [ "$ret" != "0" ]; then
710 e26bafba 2020-07-23 stsp diff -u $testroot/content.expected $testroot/content
711 e26bafba 2020-07-23 stsp test_done "$testroot" "$ret"
715 11cc08c1 2020-07-23 stsp if [ -h $testroot/wt/epsilon/beta.link ]; then
716 11cc08c1 2020-07-23 stsp echo "epsilon/beta.link is a symlink"
717 11cc08c1 2020-07-23 stsp test_done "$testroot" "1"
721 11cc08c1 2020-07-23 stsp echo "<<<<<<< merged change: commit $commit_id2" \
722 283102fc 2020-07-23 stsp > $testroot/content.expected
723 11cc08c1 2020-07-23 stsp echo "../gamma/delta" >> $testroot/content.expected
724 11cc08c1 2020-07-23 stsp echo "3-way merge base: commit $commit_id1" \
725 11cc08c1 2020-07-23 stsp >> $testroot/content.expected
726 11cc08c1 2020-07-23 stsp echo "../beta" >> $testroot/content.expected
727 11cc08c1 2020-07-23 stsp echo "=======" >> $testroot/content.expected
728 11cc08c1 2020-07-23 stsp echo "../gamma" >> $testroot/content.expected
729 11cc08c1 2020-07-23 stsp echo '>>>>>>>' >> $testroot/content.expected
730 11cc08c1 2020-07-23 stsp echo -n "" >> $testroot/content.expected
732 11cc08c1 2020-07-23 stsp cp $testroot/wt/epsilon/beta.link $testroot/content
733 11cc08c1 2020-07-23 stsp cmp -s $testroot/content.expected $testroot/content
735 e26bafba 2020-07-23 stsp if [ "$ret" != "0" ]; then
736 11cc08c1 2020-07-23 stsp diff -u $testroot/content.expected $testroot/content
737 e26bafba 2020-07-23 stsp test_done "$testroot" "$ret"
741 af57b12a 2020-07-23 stsp if [ -h $testroot/wt/nonexistent.link ]; then
742 af57b12a 2020-07-23 stsp echo -n "nonexistent.link still exists on disk: " >&2
743 af57b12a 2020-07-23 stsp readlink $testroot/wt/nonexistent.link >&2
744 af57b12a 2020-07-23 stsp test_done "$testroot" "1"
748 e26bafba 2020-07-23 stsp if [ -h $testroot/wt/dotgotfoo.link ]; then
749 e26bafba 2020-07-23 stsp echo "dotgotfoo.link is a symlink"
750 e26bafba 2020-07-23 stsp test_done "$testroot" "1"
754 3b9f0f87 2020-07-23 stsp echo "<<<<<<< merged change: commit $commit_id2" \
755 3b9f0f87 2020-07-23 stsp > $testroot/content.expected
756 3b9f0f87 2020-07-23 stsp echo "this is regular file foo" >> $testroot/content.expected
757 3b9f0f87 2020-07-23 stsp echo "=======" >> $testroot/content.expected
758 3b9f0f87 2020-07-23 stsp echo -n ".got/bar" >> $testroot/content.expected
759 3b9f0f87 2020-07-23 stsp echo '>>>>>>>' >> $testroot/content.expected
760 e26bafba 2020-07-23 stsp cp $testroot/wt/dotgotfoo.link $testroot/content
761 e26bafba 2020-07-23 stsp cmp -s $testroot/content.expected $testroot/content
763 e26bafba 2020-07-23 stsp if [ "$ret" != "0" ]; then
764 e26bafba 2020-07-23 stsp diff -u $testroot/content.expected $testroot/content
765 e26bafba 2020-07-23 stsp test_done "$testroot" "$ret"
769 e26bafba 2020-07-23 stsp if [ -h $testroot/wt/dotgotbar.link ]; then
770 e26bafba 2020-07-23 stsp echo "dotgotbar.link is a symlink"
771 e26bafba 2020-07-23 stsp test_done "$testroot" "1"
774 d219f183 2020-07-23 stsp echo "<<<<<<< merged change: commit $commit_id2" \
775 d219f183 2020-07-23 stsp > $testroot/content.expected
776 d219f183 2020-07-23 stsp echo -n ".got/bar" >> $testroot/content.expected
777 d219f183 2020-07-23 stsp echo "=======" >> $testroot/content.expected
778 d219f183 2020-07-23 stsp echo "this is regular file bar" >> $testroot/content.expected
779 d219f183 2020-07-23 stsp echo '>>>>>>>' >> $testroot/content.expected
780 d219f183 2020-07-23 stsp echo -n "" >> $testroot/content.expected
781 e26bafba 2020-07-23 stsp cp $testroot/wt/dotgotbar.link $testroot/content
782 e26bafba 2020-07-23 stsp cmp -s $testroot/content.expected $testroot/content
784 e26bafba 2020-07-23 stsp if [ "$ret" != "0" ]; then
785 e26bafba 2020-07-23 stsp diff -u $testroot/content.expected $testroot/content
786 e26bafba 2020-07-23 stsp test_done "$testroot" "$ret"
790 11cc08c1 2020-07-23 stsp if [ -h $testroot/wt/new.link ]; then
791 11cc08c1 2020-07-23 stsp echo "new.link is a symlink"
792 e26bafba 2020-07-23 stsp test_done "$testroot" "1"
796 11cc08c1 2020-07-23 stsp echo "<<<<<<< merged change: commit $commit_id2" \
797 283102fc 2020-07-23 stsp > $testroot/content.expected
798 11cc08c1 2020-07-23 stsp echo "alpha" >> $testroot/content.expected
799 11cc08c1 2020-07-23 stsp echo "=======" >> $testroot/content.expected
800 11cc08c1 2020-07-23 stsp echo "beta" >> $testroot/content.expected
801 11cc08c1 2020-07-23 stsp echo '>>>>>>>' >> $testroot/content.expected
802 11cc08c1 2020-07-23 stsp echo -n "" >> $testroot/content.expected
804 11cc08c1 2020-07-23 stsp cp $testroot/wt/new.link $testroot/content
805 11cc08c1 2020-07-23 stsp cmp -s $testroot/content.expected $testroot/content
807 e26bafba 2020-07-23 stsp if [ "$ret" != "0" ]; then
808 11cc08c1 2020-07-23 stsp diff -u $testroot/content.expected $testroot/content
809 e26bafba 2020-07-23 stsp test_done "$testroot" "$ret"
813 e26bafba 2020-07-23 stsp echo "A dotgotfoo.link" > $testroot/stdout.expected
814 e26bafba 2020-07-23 stsp echo "M new.link" >> $testroot/stdout.expected
815 e26bafba 2020-07-23 stsp echo "D nonexistent.link" >> $testroot/stdout.expected
816 e26bafba 2020-07-23 stsp (cd $testroot/wt && got status > $testroot/stdout)
817 e26bafba 2020-07-23 stsp if [ "$ret" != "0" ]; then
818 e26bafba 2020-07-23 stsp diff -u $testroot/stdout.expected $testroot/stdout
819 e26bafba 2020-07-23 stsp test_done "$testroot" "$ret"
823 af57b12a 2020-07-23 stsp test_done "$testroot" "0"
826 f6cae3ed 2020-09-13 naddy test_cherrypick_with_path_prefix_and_empty_tree() {
827 69d57f3d 2020-07-31 stsp local testroot=`test_init cherrypick_with_path_prefix_and_empty_tree 1`
829 69d57f3d 2020-07-31 stsp (cd $testroot/repo && git commit --allow-empty \
830 69d57f3d 2020-07-31 stsp -m "initial empty commit" >/dev/null)
832 69d57f3d 2020-07-31 stsp (cd $testroot/repo && got br bar >/dev/null)
834 69d57f3d 2020-07-31 stsp mkdir -p $testroot/repo/epsilon
835 69d57f3d 2020-07-31 stsp echo "file foo" > $testroot/repo/epsilon/foo
836 69d57f3d 2020-07-31 stsp (cd $testroot/repo && git add .)
837 69d57f3d 2020-07-31 stsp git_commit $testroot/repo -m "add file foo"
838 69d57f3d 2020-07-31 stsp local commit_id=`git_show_head $testroot/repo`
840 69d57f3d 2020-07-31 stsp got checkout -b bar $testroot/repo $testroot/wt > /dev/null
842 69d57f3d 2020-07-31 stsp if [ "$ret" != "0" ]; then
843 69d57f3d 2020-07-31 stsp echo "got checkout failed unexpectedly" >&2
844 69d57f3d 2020-07-31 stsp test_done "$testroot" "$ret"
848 69d57f3d 2020-07-31 stsp mkdir -p $testroot/wt/epsilon
849 69d57f3d 2020-07-31 stsp echo "new file" > $testroot/wt/epsilon/new
850 69d57f3d 2020-07-31 stsp (cd $testroot/wt && got add epsilon/new >/dev/null)
851 69d57f3d 2020-07-31 stsp (cd $testroot/wt && got commit -m "add file on branch bar" > /dev/null)
853 69d57f3d 2020-07-31 stsp got checkout -b bar -p epsilon $testroot/repo $testroot/wt2 > /dev/null
855 69d57f3d 2020-07-31 stsp if [ "$ret" != "0" ]; then
856 69d57f3d 2020-07-31 stsp echo "got checkout failed unexpectedly" >&2
857 69d57f3d 2020-07-31 stsp test_done "$testroot" "$ret"
860 69d57f3d 2020-07-31 stsp (cd $testroot/wt2 && got cherrypick $commit_id > $testroot/stdout)
862 69d57f3d 2020-07-31 stsp echo "A foo" > $testroot/stdout.expected
863 69d57f3d 2020-07-31 stsp echo "Merged commit $commit_id" >> $testroot/stdout.expected
865 cce854ad 2021-04-13 stsp cmp -s $testroot/stdout.expected $testroot/stdout
867 cce854ad 2021-04-13 stsp if [ "$ret" != "0" ]; then
868 cce854ad 2021-04-13 stsp diff -u $testroot/stdout.expected $testroot/stdout
870 cce854ad 2021-04-13 stsp test_done "$testroot" "$ret"
873 cce854ad 2021-04-13 stsp test_cherrypick_conflict_no_eol() {
874 cce854ad 2021-04-13 stsp local testroot=`test_init cherrypick_conflict_no_eol 1`
875 cce854ad 2021-04-13 stsp local content_a="aaa\naaa\naaa\naaa\naaa\naaa\n"
876 cce854ad 2021-04-13 stsp local content_b="aaa\naaa\nbbb\naaa\naaa\naaa\naaa"
877 cce854ad 2021-04-13 stsp local content_c="aaa\naaa\nccc\naaa\naaa\naaa\naaa"
879 cce854ad 2021-04-13 stsp printf "$content_a" > $testroot/repo/a
880 cce854ad 2021-04-13 stsp (cd $testroot/repo && git add a)
881 cce854ad 2021-04-13 stsp git_commit $testroot/repo -m "initial commit"
883 cce854ad 2021-04-13 stsp (cd $testroot/repo && got branch newbranch)
885 cce854ad 2021-04-13 stsp printf "$content_b" > $testroot/repo/a
886 cce854ad 2021-04-13 stsp git_commit $testroot/repo -m "change bbb"
888 cce854ad 2021-04-13 stsp printf "$content_c" > $testroot/repo/a
889 cce854ad 2021-04-13 stsp git_commit $testroot/repo -m "change ccc"
890 cce854ad 2021-04-13 stsp local ccc_commit=`git_show_head $testroot/repo`
892 cce854ad 2021-04-13 stsp got checkout -b newbranch $testroot/repo $testroot/wt > /dev/null
894 cce854ad 2021-04-13 stsp if [ "$ret" != "0" ]; then
895 cce854ad 2021-04-13 stsp test_done "$testroot" "$ret"
899 cce854ad 2021-04-13 stsp (cd $testroot/wt && got cherrypick $ccc_commit > $testroot/stdout)
901 cce854ad 2021-04-13 stsp echo "C a" > $testroot/stdout.expected
902 cce854ad 2021-04-13 stsp echo "Merged commit $ccc_commit" >> $testroot/stdout.expected
903 cce854ad 2021-04-13 stsp echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
905 69d57f3d 2020-07-31 stsp cmp -s $testroot/stdout.expected $testroot/stdout
907 69d57f3d 2020-07-31 stsp if [ "$ret" != "0" ]; then
908 69d57f3d 2020-07-31 stsp diff -u $testroot/stdout.expected $testroot/stdout
910 cce854ad 2021-04-13 stsp test_done "$testroot" "$ret"
913 cce854ad 2021-04-13 stsp test_cherrypick_conflict_no_eol2() {
914 cce854ad 2021-04-13 stsp local testroot=`test_init cherrypick_conflict_no_eol2 1`
915 cce854ad 2021-04-13 stsp local content_a="aaa\naaa\naaa\naaa\naaa\naaa"
916 cce854ad 2021-04-13 stsp local content_b="aaa\naaa\nbbb\naaa\naaa\naaa"
917 cce854ad 2021-04-13 stsp local content_c="aaa\naaa\nbbb\naaa\naaa\naaa\n"
919 cce854ad 2021-04-13 stsp printf "$content_a" > $testroot/repo/a
920 cce854ad 2021-04-13 stsp (cd $testroot/repo && git add a)
921 cce854ad 2021-04-13 stsp git_commit $testroot/repo -m "initial commit"
923 cce854ad 2021-04-13 stsp (cd $testroot/repo && got branch newbranch)
925 cce854ad 2021-04-13 stsp printf "$content_b" > $testroot/repo/a
926 cce854ad 2021-04-13 stsp git_commit $testroot/repo -m "change bbb"
928 cce854ad 2021-04-13 stsp printf "$content_c" > $testroot/repo/a
929 cce854ad 2021-04-13 stsp git_commit $testroot/repo -m "change ccc"
930 cce854ad 2021-04-13 stsp local ccc_commit=`git_show_head $testroot/repo`
932 cce854ad 2021-04-13 stsp got checkout -b newbranch $testroot/repo $testroot/wt > /dev/null
934 cce854ad 2021-04-13 stsp if [ "$ret" != "0" ]; then
935 cce854ad 2021-04-13 stsp test_done "$testroot" "$ret"
939 cce854ad 2021-04-13 stsp (cd $testroot/wt && got cherrypick $ccc_commit \
940 cce854ad 2021-04-13 stsp > $testroot/stdout 2> $testroot/stderr)
942 cce854ad 2021-04-13 stsp echo "C a" > $testroot/stdout.expected
943 cce854ad 2021-04-13 stsp echo "Merged commit $ccc_commit" >> $testroot/stdout.expected
944 cce854ad 2021-04-13 stsp echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
946 cce854ad 2021-04-13 stsp cmp -s $testroot/stdout.expected $testroot/stdout
948 cce854ad 2021-04-13 stsp if [ "$ret" != "0" ]; then
949 54d5be07 2021-06-03 stsp diff -u $testroot/stdout.expected $testroot/stdout
951 3cd22b21 2021-05-31 stsp test_done "$testroot" "$ret"
954 3cd22b21 2021-05-31 stsp test_cherrypick_unrelated_changes() {
955 3cd22b21 2021-05-31 stsp local testroot=`test_init cherrypick_unrelated_changes`
957 3cd22b21 2021-05-31 stsp # Sorry about the large HERE document but I have not found
958 3cd22b21 2021-05-31 stsp # a smaller reproduction recipe yet...
959 3cd22b21 2021-05-31 stsp cat > $testroot/repo/reference.c <<EOF
960 3cd22b21 2021-05-31 stsp const struct got_error *
961 3cd22b21 2021-05-31 stsp got_ref_alloc(struct got_reference **ref, const char *name,
962 3cd22b21 2021-05-31 stsp struct got_object_id *id)
964 3cd22b21 2021-05-31 stsp if (!is_valid_ref_name(name))
965 3cd22b21 2021-05-31 stsp return got_error_path(name, GOT_ERR_BAD_REF_NAME);
967 3cd22b21 2021-05-31 stsp return alloc_ref(ref, name, id, 0);
970 3cd22b21 2021-05-31 stsp static const struct got_error *
971 3cd22b21 2021-05-31 stsp parse_packed_ref_line(struct got_reference **ref, const char *abs_refname,
972 3cd22b21 2021-05-31 stsp const char *line)
974 3cd22b21 2021-05-31 stsp struct got_object_id id;
975 3cd22b21 2021-05-31 stsp const char *name;
977 3cd22b21 2021-05-31 stsp *ref = NULL;
979 3cd22b21 2021-05-31 stsp if (line[0] == '#' || line[0] == '^')
980 3cd22b21 2021-05-31 stsp return NULL;
982 3cd22b21 2021-05-31 stsp if (!got_parse_sha1_digest(id.sha1, line))
983 3cd22b21 2021-05-31 stsp return got_error(GOT_ERR_BAD_REF_DATA);
985 3cd22b21 2021-05-31 stsp if (abs_refname) {
986 3cd22b21 2021-05-31 stsp if (strcmp(line + SHA1_DIGEST_STRING_LENGTH, abs_refname) != 0)
987 3cd22b21 2021-05-31 stsp return NULL;
988 3cd22b21 2021-05-31 stsp name = abs_refname;
990 3cd22b21 2021-05-31 stsp name = line + SHA1_DIGEST_STRING_LENGTH;
992 3cd22b21 2021-05-31 stsp return alloc_ref(ref, name, &id, GOT_REF_IS_PACKED);
995 3cd22b21 2021-05-31 stsp static const struct got_error *
996 3cd22b21 2021-05-31 stsp open_packed_ref(struct got_reference **ref, FILE *f, const char **subdirs,
997 3cd22b21 2021-05-31 stsp int nsubdirs, const char *refname)
999 3cd22b21 2021-05-31 stsp const struct got_error *err = NULL;
1000 3cd22b21 2021-05-31 stsp char *abs_refname;
1001 3cd22b21 2021-05-31 stsp char *line = NULL;
1002 3cd22b21 2021-05-31 stsp size_t linesize = 0;
1003 3cd22b21 2021-05-31 stsp ssize_t linelen;
1004 3cd22b21 2021-05-31 stsp int i, ref_is_absolute = (strncmp(refname, "refs/", 5) == 0);
1006 3cd22b21 2021-05-31 stsp *ref = NULL;
1008 3cd22b21 2021-05-31 stsp if (ref_is_absolute)
1009 3cd22b21 2021-05-31 stsp abs_refname = (char *)refname;
1011 3cd22b21 2021-05-31 stsp linelen = getline(&line, &linesize, f);
1012 3cd22b21 2021-05-31 stsp if (linelen == -1) {
1013 3cd22b21 2021-05-31 stsp if (feof(f))
1015 3cd22b21 2021-05-31 stsp err = got_ferror(f, GOT_ERR_BAD_REF_DATA);
1018 3cd22b21 2021-05-31 stsp if (linelen > 0 && line[linelen - 1] == '\n')
1019 3cd22b21 2021-05-31 stsp line[linelen - 1] = '\0';
1020 3cd22b21 2021-05-31 stsp for (i = 0; i < nsubdirs; i++) {
1021 3cd22b21 2021-05-31 stsp if (!ref_is_absolute &&
1022 3cd22b21 2021-05-31 stsp asprintf(&abs_refname, "refs/%s/%s", subdirs[i],
1023 3cd22b21 2021-05-31 stsp refname) == -1)
1024 3cd22b21 2021-05-31 stsp return got_error_from_errno("asprintf");
1025 3cd22b21 2021-05-31 stsp err = parse_packed_ref_line(ref, abs_refname, line);
1026 3cd22b21 2021-05-31 stsp if (!ref_is_absolute)
1027 3cd22b21 2021-05-31 stsp free(abs_refname);
1028 3cd22b21 2021-05-31 stsp if (err || *ref != NULL)
1033 3cd22b21 2021-05-31 stsp } while (*ref == NULL);
1034 3cd22b21 2021-05-31 stsp free(line);
1036 3cd22b21 2021-05-31 stsp return err;
1039 3cd22b21 2021-05-31 stsp static const struct got_error *
1040 3cd22b21 2021-05-31 stsp open_ref(struct got_reference **ref, const char *path_refs, const char *subdir,
1041 3cd22b21 2021-05-31 stsp const char *name, int lock)
1043 3cd22b21 2021-05-31 stsp const struct got_error *err = NULL;
1044 3cd22b21 2021-05-31 stsp char *path = NULL;
1045 3cd22b21 2021-05-31 stsp char *absname = NULL;
1046 3cd22b21 2021-05-31 stsp int ref_is_absolute = (strncmp(name, "refs/", 5) == 0);
1047 3cd22b21 2021-05-31 stsp int ref_is_well_known = (subdir[0] == '\0' && is_well_known_ref(name));
1049 3cd22b21 2021-05-31 stsp *ref = NULL;
1051 3cd22b21 2021-05-31 stsp if (ref_is_absolute || ref_is_well_known) {
1052 3cd22b21 2021-05-31 stsp if (asprintf(&path, "%s/%s", path_refs, name) == -1)
1053 3cd22b21 2021-05-31 stsp return got_error_from_errno("asprintf");
1054 3cd22b21 2021-05-31 stsp absname = (char *)name;
1056 3cd22b21 2021-05-31 stsp if (asprintf(&path, "%s/%s%s%s", path_refs, subdir,
1057 3cd22b21 2021-05-31 stsp subdir[0] ? "/" : "", name) == -1)
1058 3cd22b21 2021-05-31 stsp return got_error_from_errno("asprintf");
1060 3cd22b21 2021-05-31 stsp if (asprintf(&absname, "refs/%s%s%s",
1061 3cd22b21 2021-05-31 stsp subdir, subdir[0] ? "/" : "", name) == -1) {
1062 3cd22b21 2021-05-31 stsp err = got_error_from_errno("asprintf");
1063 3cd22b21 2021-05-31 stsp goto done;
1067 3cd22b21 2021-05-31 stsp err = parse_ref_file(ref, name, absname, path, lock);
1069 3cd22b21 2021-05-31 stsp if (!ref_is_absolute && !ref_is_well_known)
1070 3cd22b21 2021-05-31 stsp free(absname);
1071 3cd22b21 2021-05-31 stsp free(path);
1072 3cd22b21 2021-05-31 stsp return err;
1075 3cd22b21 2021-05-31 stsp const struct got_error *
1076 3cd22b21 2021-05-31 stsp got_ref_open(struct got_reference **ref, struct got_repository *repo,
1077 3cd22b21 2021-05-31 stsp const char *refname, int lock)
1079 3cd22b21 2021-05-31 stsp const struct got_error *err = NULL;
1080 3cd22b21 2021-05-31 stsp char *path_refs = NULL;
1081 3cd22b21 2021-05-31 stsp const char *subdirs[] = {
1082 3cd22b21 2021-05-31 stsp GOT_REF_HEADS, GOT_REF_TAGS, GOT_REF_REMOTES
1085 3cd22b21 2021-05-31 stsp int well_known = is_well_known_ref(refname);
1086 3cd22b21 2021-05-31 stsp struct got_lockfile *lf = NULL;
1088 3cd22b21 2021-05-31 stsp *ref = NULL;
1090 3cd22b21 2021-05-31 stsp path_refs = get_refs_dir_path(repo, refname);
1091 3cd22b21 2021-05-31 stsp if (path_refs == NULL) {
1092 3cd22b21 2021-05-31 stsp err = got_error_from_errno2("get_refs_dir_path", refname);
1093 3cd22b21 2021-05-31 stsp goto done;
1096 3cd22b21 2021-05-31 stsp if (well_known) {
1097 3cd22b21 2021-05-31 stsp err = open_ref(ref, path_refs, "", refname, lock);
1099 3cd22b21 2021-05-31 stsp char *packed_refs_path;
1102 3cd22b21 2021-05-31 stsp /* Search on-disk refs before packed refs! */
1103 3cd22b21 2021-05-31 stsp for (i = 0; i < nitems(subdirs); i++) {
1104 3cd22b21 2021-05-31 stsp err = open_ref(ref, path_refs, subdirs[i], refname,
1106 3cd22b21 2021-05-31 stsp if ((err && err->code != GOT_ERR_NOT_REF) || *ref)
1107 3cd22b21 2021-05-31 stsp goto done;
1110 3cd22b21 2021-05-31 stsp packed_refs_path = got_repo_get_path_packed_refs(repo);
1111 3cd22b21 2021-05-31 stsp if (packed_refs_path == NULL) {
1112 3cd22b21 2021-05-31 stsp err = got_error_from_errno(
1113 3cd22b21 2021-05-31 stsp "got_repo_get_path_packed_refs");
1114 3cd22b21 2021-05-31 stsp goto done;
1117 3cd22b21 2021-05-31 stsp if (lock) {
1118 3cd22b21 2021-05-31 stsp err = got_lockfile_lock(&lf, packed_refs_path);
1120 3cd22b21 2021-05-31 stsp goto done;
1122 3cd22b21 2021-05-31 stsp f = fopen(packed_refs_path, "rb");
1123 3cd22b21 2021-05-31 stsp free(packed_refs_path);
1124 3cd22b21 2021-05-31 stsp if (f != NULL) {
1125 3cd22b21 2021-05-31 stsp err = open_packed_ref(ref, f, subdirs, nitems(subdirs),
1127 3cd22b21 2021-05-31 stsp if (!err) {
1128 3cd22b21 2021-05-31 stsp if (fclose(f) == EOF) {
1129 3cd22b21 2021-05-31 stsp err = got_error_from_errno("fclose");
1130 3cd22b21 2021-05-31 stsp got_ref_close(*ref);
1131 3cd22b21 2021-05-31 stsp *ref = NULL;
1132 3cd22b21 2021-05-31 stsp } else if (*ref)
1133 3cd22b21 2021-05-31 stsp (*ref)->lf = lf;
1138 3cd22b21 2021-05-31 stsp if (!err && *ref == NULL)
1139 3cd22b21 2021-05-31 stsp err = got_error_not_ref(refname);
1140 3cd22b21 2021-05-31 stsp if (err && lf)
1141 3cd22b21 2021-05-31 stsp got_lockfile_unlock(lf);
1142 3cd22b21 2021-05-31 stsp free(path_refs);
1143 3cd22b21 2021-05-31 stsp return err;
1146 3cd22b21 2021-05-31 stsp struct got_reference *
1147 3cd22b21 2021-05-31 stsp got_ref_dup(struct got_reference *ref)
1149 3cd22b21 2021-05-31 stsp struct got_reference *ret;
1151 3cd22b21 2021-05-31 stsp ret = calloc(1, sizeof(*ret));
1152 3cd22b21 2021-05-31 stsp if (ret == NULL)
1153 3cd22b21 2021-05-31 stsp return NULL;
1155 3cd22b21 2021-05-31 stsp ret->flags = ref->flags;
1156 3cd22b21 2021-05-31 stsp if (ref->flags & GOT_REF_IS_SYMBOLIC) {
1157 3cd22b21 2021-05-31 stsp ret->ref.symref.name = strdup(ref->ref.symref.name);
1158 3cd22b21 2021-05-31 stsp if (ret->ref.symref.name == NULL) {
1159 3cd22b21 2021-05-31 stsp free(ret);
1160 3cd22b21 2021-05-31 stsp return NULL;
1162 3cd22b21 2021-05-31 stsp ret->ref.symref.ref = strdup(ref->ref.symref.ref);
1163 3cd22b21 2021-05-31 stsp if (ret->ref.symref.ref == NULL) {
1164 3cd22b21 2021-05-31 stsp free(ret->ref.symref.name);
1165 3cd22b21 2021-05-31 stsp free(ret);
1166 3cd22b21 2021-05-31 stsp return NULL;
1169 3cd22b21 2021-05-31 stsp ret->ref.ref.name = strdup(ref->ref.ref.name);
1170 3cd22b21 2021-05-31 stsp if (ret->ref.ref.name == NULL) {
1171 3cd22b21 2021-05-31 stsp free(ret);
1172 3cd22b21 2021-05-31 stsp return NULL;
1174 3cd22b21 2021-05-31 stsp memcpy(ret->ref.ref.sha1, ref->ref.ref.sha1,
1175 3cd22b21 2021-05-31 stsp sizeof(ret->ref.ref.sha1));
1178 3cd22b21 2021-05-31 stsp return ret;
1181 3cd22b21 2021-05-31 stsp const struct got_error *
1182 3cd22b21 2021-05-31 stsp got_reflist_entry_dup(struct got_reflist_entry **newp,
1183 3cd22b21 2021-05-31 stsp struct got_reflist_entry *re)
1185 3cd22b21 2021-05-31 stsp const struct got_error *err = NULL;
1186 3cd22b21 2021-05-31 stsp struct got_reflist_entry *new;
1188 3cd22b21 2021-05-31 stsp *newp = NULL;
1190 3cd22b21 2021-05-31 stsp new = malloc(sizeof(*new));
1191 3cd22b21 2021-05-31 stsp if (new == NULL)
1192 3cd22b21 2021-05-31 stsp return got_error_from_errno("malloc");
1194 3cd22b21 2021-05-31 stsp new->ref = got_ref_dup(re->ref);
1195 3cd22b21 2021-05-31 stsp if (new->ref == NULL) {
1196 3cd22b21 2021-05-31 stsp err = got_error_from_errno("got_ref_dup");
1197 3cd22b21 2021-05-31 stsp free(new);
1198 3cd22b21 2021-05-31 stsp return err;
1201 3cd22b21 2021-05-31 stsp *newp = new;
1202 3cd22b21 2021-05-31 stsp return NULL;
1206 3cd22b21 2021-05-31 stsp got_ref_list_free(struct got_reflist_head *refs)
1208 3cd22b21 2021-05-31 stsp struct got_reflist_entry *re;
1210 3cd22b21 2021-05-31 stsp while ((re = TAILQ_FIRST(refs))) {
1211 3cd22b21 2021-05-31 stsp TAILQ_REMOVE(refs, re, entry);
1217 3cd22b21 2021-05-31 stsp (cd $testroot/repo && git add reference.c)
1218 3cd22b21 2021-05-31 stsp git_commit $testroot/repo -m "added reference.c file"
1219 3cd22b21 2021-05-31 stsp local base_commit=`git_show_head $testroot/repo`
1221 3cd22b21 2021-05-31 stsp got checkout $testroot/repo $testroot/wt > /dev/null
1223 3cd22b21 2021-05-31 stsp if [ "$ret" != "0" ]; then
1224 3cd22b21 2021-05-31 stsp test_done "$testroot" "$ret"
1228 3cd22b21 2021-05-31 stsp (cd $testroot/repo && git checkout -q -b newbranch)
1229 3cd22b21 2021-05-31 stsp ed -s $testroot/repo/reference.c <<EOF
1231 3cd22b21 2021-05-31 stsp if (!is_valid_ref_name(name))
1232 3cd22b21 2021-05-31 stsp return got_error_path(name, GOT_ERR_BAD_REF_NAME);
1238 3cd22b21 2021-05-31 stsp git_commit $testroot/repo -m "added lines on newbranch"
1239 3cd22b21 2021-05-31 stsp local branch_rev1=`git_show_head $testroot/repo`
1241 3cd22b21 2021-05-31 stsp ed -s $testroot/repo/reference.c <<EOF
1243 3cd22b21 2021-05-31 stsp got_ref_close(re->ref);
1248 3cd22b21 2021-05-31 stsp git_commit $testroot/repo -m "more lines on newbranch"
1250 3cd22b21 2021-05-31 stsp local branch_rev2=`git_show_head $testroot/repo`
1252 3cd22b21 2021-05-31 stsp (cd $testroot/wt && got cherrypick $branch_rev2 > $testroot/stdout)
1254 3cd22b21 2021-05-31 stsp echo "G reference.c" > $testroot/stdout.expected
1255 3cd22b21 2021-05-31 stsp echo "Merged commit $branch_rev2" >> $testroot/stdout.expected
1257 3cd22b21 2021-05-31 stsp cmp -s $testroot/stdout.expected $testroot/stdout
1259 3cd22b21 2021-05-31 stsp if [ "$ret" != "0" ]; then
1260 3cd22b21 2021-05-31 stsp diff -u $testroot/stdout.expected $testroot/stdout
1261 3cd22b21 2021-05-31 stsp test_done "$testroot" "$ret"
1265 3cd22b21 2021-05-31 stsp cat > $testroot/diff.expected <<EOF
1266 3cd22b21 2021-05-31 stsp --- reference.c
1267 3cd22b21 2021-05-31 stsp +++ reference.c
1268 3cd22b21 2021-05-31 stsp @@ -250,6 +250,7 @@ got_ref_list_free(struct got_reflist_head *refs)
1270 3cd22b21 2021-05-31 stsp while ((re = TAILQ_FIRST(refs))) {
1271 3cd22b21 2021-05-31 stsp TAILQ_REMOVE(refs, re, entry);
1272 3cd22b21 2021-05-31 stsp + got_ref_close(re->ref);
1277 3cd22b21 2021-05-31 stsp (cd $testroot/wt && got diff |
1278 3cd22b21 2021-05-31 stsp egrep -v '^(diff|blob|file)' > $testroot/diff)
1279 3cd22b21 2021-05-31 stsp cmp -s $testroot/diff.expected $testroot/diff
1281 3cd22b21 2021-05-31 stsp if [ "$ret" != "0" ]; then
1282 54d5be07 2021-06-03 stsp diff -u $testroot/diff.expected $testroot/diff
1285 0baddd91 2021-09-03 stsp test_done "$testroot" "$ret"
1288 0baddd91 2021-09-03 stsp test_cherrypick_same_branch() {
1289 0baddd91 2021-09-03 stsp local testroot=`test_init cherrypick_same_branch`
1291 0baddd91 2021-09-03 stsp got checkout $testroot/repo $testroot/wt > /dev/null
1293 0baddd91 2021-09-03 stsp if [ "$ret" != "0" ]; then
1294 0baddd91 2021-09-03 stsp test_done "$testroot" "$ret"
1298 0baddd91 2021-09-03 stsp (cd $testroot/repo && git checkout -q -b newbranch)
1299 0baddd91 2021-09-03 stsp echo "modified delta on branch" > $testroot/repo/gamma/delta
1300 0baddd91 2021-09-03 stsp git_commit $testroot/repo -m "committing to delta on newbranch"
1302 0baddd91 2021-09-03 stsp echo "modified alpha on branch" > $testroot/repo/alpha
1303 0baddd91 2021-09-03 stsp (cd $testroot/repo && git rm -q beta)
1304 0baddd91 2021-09-03 stsp echo "new file on branch" > $testroot/repo/epsilon/new
1305 0baddd91 2021-09-03 stsp (cd $testroot/repo && git add epsilon/new)
1306 0baddd91 2021-09-03 stsp git_commit $testroot/repo -m "committing more changes on newbranch"
1308 0baddd91 2021-09-03 stsp local branch_rev=`git_show_head $testroot/repo`
1310 0baddd91 2021-09-03 stsp # picking a commit from the branch's own history does not make
1311 0baddd91 2021-09-03 stsp # sense but we should have test coverage for this case regardless
1312 0baddd91 2021-09-03 stsp (cd $testroot/wt && got up -b newbranch > /dev/null)
1313 0baddd91 2021-09-03 stsp (cd $testroot/wt && got cherrypick $branch_rev > $testroot/stdout)
1315 0baddd91 2021-09-03 stsp echo "G alpha" > $testroot/stdout.expected
1316 0baddd91 2021-09-03 stsp echo "! beta" >> $testroot/stdout.expected
1317 0baddd91 2021-09-03 stsp echo "G epsilon/new" >> $testroot/stdout.expected
1318 0baddd91 2021-09-03 stsp echo "Merged commit $branch_rev" >> $testroot/stdout.expected
1320 0baddd91 2021-09-03 stsp cmp -s $testroot/stdout.expected $testroot/stdout
1322 0baddd91 2021-09-03 stsp if [ "$ret" != "0" ]; then
1323 0baddd91 2021-09-03 stsp diff -u $testroot/stdout.expected $testroot/stdout
1325 69d57f3d 2020-07-31 stsp test_done "$testroot" "$ret"
1329 7fb414ae 2020-08-08 stsp test_parseargs "$@"
1330 234035bc 2019-06-01 stsp run_test test_cherrypick_basic
1331 03415a1a 2019-06-02 stsp run_test test_cherrypick_root_commit
1332 ceb466a7 2020-04-18 stsp run_test test_cherrypick_into_work_tree_with_conflicts
1333 ed99f061 2021-09-03 stsp run_test test_cherrypick_into_work_tree_with_mixed_commits
1334 e7303626 2020-05-14 stsp run_test test_cherrypick_modified_submodule
1335 e7303626 2020-05-14 stsp run_test test_cherrypick_added_submodule
1336 e7303626 2020-05-14 stsp run_test test_cherrypick_conflict_wt_file_vs_repo_submodule
1337 af57b12a 2020-07-23 stsp run_test test_cherrypick_modified_symlinks
1338 e26bafba 2020-07-23 stsp run_test test_cherrypick_symlink_conflicts
1339 69d57f3d 2020-07-31 stsp run_test test_cherrypick_with_path_prefix_and_empty_tree
1340 cce854ad 2021-04-13 stsp run_test test_cherrypick_conflict_no_eol
1341 cce854ad 2021-04-13 stsp run_test test_cherrypick_conflict_no_eol2
1342 3cd22b21 2021-05-31 stsp run_test test_cherrypick_unrelated_changes
1343 0baddd91 2021-09-03 stsp run_test test_cherrypick_same_branch