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 5267b9e4 2021-09-26 stsp got tree -r $testroot/repo -R -c $commit_id1 \
452 5267b9e4 2021-09-26 stsp > $testroot/stdout
453 5267b9e4 2021-09-26 stsp cat > $testroot/stdout.expected <<EOF
455 5267b9e4 2021-09-26 stsp alpha.link@ -> alpha
458 5267b9e4 2021-09-26 stsp epsilon/beta.link@ -> ../beta
459 5267b9e4 2021-09-26 stsp epsilon/zeta
460 5267b9e4 2021-09-26 stsp epsilon.link@ -> epsilon
462 5267b9e4 2021-09-26 stsp gamma/delta
463 5267b9e4 2021-09-26 stsp nonexistent.link@ -> nonexistent
464 5267b9e4 2021-09-26 stsp passwd.link@ -> /etc/passwd
466 5267b9e4 2021-09-26 stsp cmp -s $testroot/stdout.expected $testroot/stdout
468 5267b9e4 2021-09-26 stsp if [ "$ret" != "0" ]; then
469 5267b9e4 2021-09-26 stsp diff -u $testroot/stdout.expected $testroot/stdout
470 5267b9e4 2021-09-26 stsp test_done "$testroot" "$ret"
474 af57b12a 2020-07-23 stsp got branch -r $testroot/repo foo
476 af57b12a 2020-07-23 stsp got checkout -b foo $testroot/repo $testroot/wt > /dev/null
478 af57b12a 2020-07-23 stsp (cd $testroot/repo && ln -sf beta alpha.link)
479 af57b12a 2020-07-23 stsp (cd $testroot/repo && ln -sfh gamma epsilon.link)
480 af57b12a 2020-07-23 stsp (cd $testroot/repo && ln -sf ../gamma/delta epsilon/beta.link)
481 5267b9e4 2021-09-26 stsp (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`
488 af57b12a 2020-07-23 stsp (cd $testroot/wt && got cherrypick $commit_id2 > $testroot/stdout)
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
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"
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"
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
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"
521 5267b9e4 2021-09-26 stsp if ! [ -h $testroot/wt/dotgotfoo.link ]; then
522 5267b9e4 2021-09-26 stsp echo "dotgotfoo.link is not a symlink"
523 5267b9e4 2021-09-26 stsp test_done "$testroot" "1"
527 5267b9e4 2021-09-26 stsp readlink $testroot/wt/dotgotfoo.link > $testroot/stdout
528 5267b9e4 2021-09-26 stsp echo ".got/foo" > $testroot/stdout.expected
529 5267b9e4 2021-09-26 stsp cmp -s $testroot/stdout.expected $testroot/stdout
531 5267b9e4 2021-09-26 stsp if [ "$ret" != "0" ]; then
532 5267b9e4 2021-09-26 stsp diff -u $testroot/stdout.expected $testroot/stdout
533 5267b9e4 2021-09-26 stsp test_done "$testroot" "$ret"
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"
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
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"
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"
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
563 af57b12a 2020-07-23 stsp cmp -s $testroot/content.expected $testroot/content
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"
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
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"
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"
588 5267b9e4 2021-09-26 stsp (cd $testroot/wt && got commit -m 'commit cherrypick result' \
589 5267b9e4 2021-09-26 stsp > /dev/null 2>$testroot/stderr)
591 5267b9e4 2021-09-26 stsp if [ "$ret" == "0" ]; then
592 5267b9e4 2021-09-26 stsp echo "got commit succeeded unexpectedly" >&2
593 5267b9e4 2021-09-26 stsp test_done "$testroot" "$ret"
596 5267b9e4 2021-09-26 stsp echo -n "got: $testroot/wt/dotgotfoo.link: symbolic link points " \
597 5267b9e4 2021-09-26 stsp > $testroot/stderr.expected
598 5267b9e4 2021-09-26 stsp echo "outside of paths under version control" \
599 5267b9e4 2021-09-26 stsp >> $testroot/stderr.expected
600 5267b9e4 2021-09-26 stsp cmp -s $testroot/stderr.expected $testroot/stderr
602 5267b9e4 2021-09-26 stsp if [ "$ret" != "0" ]; then
603 5267b9e4 2021-09-26 stsp diff -u $testroot/stderr.expected $testroot/stderr
604 5267b9e4 2021-09-26 stsp test_done "$testroot" "$ret"
608 5267b9e4 2021-09-26 stsp (cd $testroot/wt && got commit -S -m 'commit cherrypick result' \
609 5267b9e4 2021-09-26 stsp > /dev/null)
611 5267b9e4 2021-09-26 stsp if [ "$ret" != "0" ]; then
612 5267b9e4 2021-09-26 stsp echo "got commit failed unexpectedly" >&2
613 5267b9e4 2021-09-26 stsp test_done "$testroot" "$ret"
616 5267b9e4 2021-09-26 stsp local commit_id2=`git_show_head $testroot/repo`
618 5267b9e4 2021-09-26 stsp got tree -r $testroot/repo -R -c $commit_id2 \
619 5267b9e4 2021-09-26 stsp > $testroot/stdout
620 5267b9e4 2021-09-26 stsp cat > $testroot/stdout.expected <<EOF
622 5267b9e4 2021-09-26 stsp alpha.link@ -> beta
624 5267b9e4 2021-09-26 stsp dotgotfoo.link@ -> .got/foo
626 5267b9e4 2021-09-26 stsp epsilon/beta.link@ -> ../gamma/delta
627 5267b9e4 2021-09-26 stsp epsilon/zeta
628 5267b9e4 2021-09-26 stsp epsilon.link@ -> gamma
630 5267b9e4 2021-09-26 stsp gamma/delta
631 5267b9e4 2021-09-26 stsp passwd.link@ -> /etc/passwd
632 5267b9e4 2021-09-26 stsp zeta.link@ -> epsilon/zeta
634 5267b9e4 2021-09-26 stsp cmp -s $testroot/stdout.expected $testroot/stdout
636 5267b9e4 2021-09-26 stsp if [ "$ret" != "0" ]; then
637 5267b9e4 2021-09-26 stsp diff -u $testroot/stdout.expected $testroot/stdout
639 5267b9e4 2021-09-26 stsp test_done "$testroot" "$ret"
642 f6cae3ed 2020-09-13 naddy test_cherrypick_symlink_conflicts() {
643 e26bafba 2020-07-23 stsp local testroot=`test_init cherrypick_symlink_conflicts`
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`
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 e26bafba 2020-07-23 stsp (cd $testroot/repo && ln -sfh 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`
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
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 e26bafba 2020-07-23 stsp (cd $testroot/wt && ln -sfh beta epsilon.link)
675 e26bafba 2020-07-23 stsp # modeified symlink to file A vs modified symlink to dir B
676 e26bafba 2020-07-23 stsp (cd $testroot/wt && ln -sfh ../gamma epsilon/beta.link)
677 e26bafba 2020-07-23 stsp # added regular file A vs added bad symlink to file A
678 5267b9e4 2021-09-26 stsp (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)
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)
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 e26bafba 2020-07-23 stsp cmp -s $testroot/stdout.expected $testroot/stdout
713 e26bafba 2020-07-23 stsp if [ "$ret" != "0" ]; then
714 e26bafba 2020-07-23 stsp diff -u $testroot/stdout.expected $testroot/stdout
715 e26bafba 2020-07-23 stsp test_done "$testroot" "$ret"
719 11cc08c1 2020-07-23 stsp if [ -h $testroot/wt/alpha.link ]; then
720 11cc08c1 2020-07-23 stsp echo "alpha.link is a symlink"
721 e26bafba 2020-07-23 stsp test_done "$testroot" "1"
725 11cc08c1 2020-07-23 stsp echo "<<<<<<< merged change: commit $commit_id2" \
726 283102fc 2020-07-23 stsp > $testroot/content.expected
727 11cc08c1 2020-07-23 stsp echo "beta" >> $testroot/content.expected
728 11cc08c1 2020-07-23 stsp echo "3-way merge base: commit $commit_id1" \
729 11cc08c1 2020-07-23 stsp >> $testroot/content.expected
730 11cc08c1 2020-07-23 stsp echo "alpha" >> $testroot/content.expected
731 11cc08c1 2020-07-23 stsp echo "=======" >> $testroot/content.expected
732 11cc08c1 2020-07-23 stsp echo "gamma/delta" >> $testroot/content.expected
733 11cc08c1 2020-07-23 stsp echo '>>>>>>>' >> $testroot/content.expected
734 11cc08c1 2020-07-23 stsp echo -n "" >> $testroot/content.expected
736 11cc08c1 2020-07-23 stsp cp $testroot/wt/alpha.link $testroot/content
737 fba9f79c 2020-07-23 stsp cmp -s $testroot/content.expected $testroot/content
739 fba9f79c 2020-07-23 stsp if [ "$ret" != "0" ]; then
740 fba9f79c 2020-07-23 stsp diff -u $testroot/content.expected $testroot/content
741 fba9f79c 2020-07-23 stsp test_done "$testroot" "$ret"
745 c90c8ce3 2020-07-23 stsp if [ -h $testroot/wt/boo.link ]; then
746 c90c8ce3 2020-07-23 stsp echo "boo.link is a symlink"
747 fba9f79c 2020-07-23 stsp test_done "$testroot" "1"
751 c90c8ce3 2020-07-23 stsp echo "this is unversioned file boo" > $testroot/content.expected
752 fba9f79c 2020-07-23 stsp cp $testroot/wt/boo.link $testroot/content
753 11cc08c1 2020-07-23 stsp cmp -s $testroot/content.expected $testroot/content
755 e26bafba 2020-07-23 stsp if [ "$ret" != "0" ]; then
756 11cc08c1 2020-07-23 stsp diff -u $testroot/content.expected $testroot/content
757 e26bafba 2020-07-23 stsp test_done "$testroot" "$ret"
761 11cc08c1 2020-07-23 stsp if [ -h $testroot/wt/epsilon.link ]; then
762 11cc08c1 2020-07-23 stsp echo "epsilon.link is a symlink"
763 e26bafba 2020-07-23 stsp test_done "$testroot" "1"
767 11cc08c1 2020-07-23 stsp echo "<<<<<<< merged change: commit $commit_id2" \
768 283102fc 2020-07-23 stsp > $testroot/content.expected
769 11cc08c1 2020-07-23 stsp echo "gamma" >> $testroot/content.expected
770 11cc08c1 2020-07-23 stsp echo "3-way merge base: commit $commit_id1" \
771 11cc08c1 2020-07-23 stsp >> $testroot/content.expected
772 11cc08c1 2020-07-23 stsp echo "epsilon" >> $testroot/content.expected
773 11cc08c1 2020-07-23 stsp echo "=======" >> $testroot/content.expected
774 11cc08c1 2020-07-23 stsp echo "beta" >> $testroot/content.expected
775 11cc08c1 2020-07-23 stsp echo '>>>>>>>' >> $testroot/content.expected
776 11cc08c1 2020-07-23 stsp echo -n "" >> $testroot/content.expected
778 11cc08c1 2020-07-23 stsp cp $testroot/wt/epsilon.link $testroot/content
779 11cc08c1 2020-07-23 stsp cmp -s $testroot/content.expected $testroot/content
781 af57b12a 2020-07-23 stsp if [ "$ret" != "0" ]; then
782 11cc08c1 2020-07-23 stsp diff -u $testroot/content.expected $testroot/content
783 af57b12a 2020-07-23 stsp test_done "$testroot" "$ret"
787 e26bafba 2020-07-23 stsp if [ -h $testroot/wt/passwd.link ]; then
788 e26bafba 2020-07-23 stsp echo -n "passwd.link symlink points outside of work tree: " >&2
789 e26bafba 2020-07-23 stsp readlink $testroot/wt/passwd.link >&2
790 e26bafba 2020-07-23 stsp test_done "$testroot" "1"
794 e26bafba 2020-07-23 stsp echo -n "/etc/passwd" > $testroot/content.expected
795 e26bafba 2020-07-23 stsp cp $testroot/wt/passwd.link $testroot/content
797 e26bafba 2020-07-23 stsp cmp -s $testroot/content.expected $testroot/content
799 e26bafba 2020-07-23 stsp if [ "$ret" != "0" ]; then
800 e26bafba 2020-07-23 stsp diff -u $testroot/content.expected $testroot/content
801 e26bafba 2020-07-23 stsp test_done "$testroot" "$ret"
805 11cc08c1 2020-07-23 stsp if [ -h $testroot/wt/epsilon/beta.link ]; then
806 11cc08c1 2020-07-23 stsp echo "epsilon/beta.link is a symlink"
807 11cc08c1 2020-07-23 stsp test_done "$testroot" "1"
811 11cc08c1 2020-07-23 stsp echo "<<<<<<< merged change: commit $commit_id2" \
812 283102fc 2020-07-23 stsp > $testroot/content.expected
813 11cc08c1 2020-07-23 stsp echo "../gamma/delta" >> $testroot/content.expected
814 11cc08c1 2020-07-23 stsp echo "3-way merge base: commit $commit_id1" \
815 11cc08c1 2020-07-23 stsp >> $testroot/content.expected
816 11cc08c1 2020-07-23 stsp echo "../beta" >> $testroot/content.expected
817 11cc08c1 2020-07-23 stsp echo "=======" >> $testroot/content.expected
818 11cc08c1 2020-07-23 stsp echo "../gamma" >> $testroot/content.expected
819 11cc08c1 2020-07-23 stsp echo '>>>>>>>' >> $testroot/content.expected
820 11cc08c1 2020-07-23 stsp echo -n "" >> $testroot/content.expected
822 11cc08c1 2020-07-23 stsp cp $testroot/wt/epsilon/beta.link $testroot/content
823 11cc08c1 2020-07-23 stsp cmp -s $testroot/content.expected $testroot/content
825 e26bafba 2020-07-23 stsp if [ "$ret" != "0" ]; then
826 11cc08c1 2020-07-23 stsp diff -u $testroot/content.expected $testroot/content
827 e26bafba 2020-07-23 stsp test_done "$testroot" "$ret"
831 af57b12a 2020-07-23 stsp if [ -h $testroot/wt/nonexistent.link ]; then
832 af57b12a 2020-07-23 stsp echo -n "nonexistent.link still exists on disk: " >&2
833 af57b12a 2020-07-23 stsp readlink $testroot/wt/nonexistent.link >&2
834 af57b12a 2020-07-23 stsp test_done "$testroot" "1"
838 e26bafba 2020-07-23 stsp if [ -h $testroot/wt/dotgotfoo.link ]; then
839 e26bafba 2020-07-23 stsp echo "dotgotfoo.link is a symlink"
840 e26bafba 2020-07-23 stsp test_done "$testroot" "1"
844 3b9f0f87 2020-07-23 stsp echo "<<<<<<< merged change: commit $commit_id2" \
845 3b9f0f87 2020-07-23 stsp > $testroot/content.expected
846 3b9f0f87 2020-07-23 stsp echo "this is regular file foo" >> $testroot/content.expected
847 3b9f0f87 2020-07-23 stsp echo "=======" >> $testroot/content.expected
848 5267b9e4 2021-09-26 stsp echo -n ".got/foo" >> $testroot/content.expected
849 3b9f0f87 2020-07-23 stsp echo '>>>>>>>' >> $testroot/content.expected
850 e26bafba 2020-07-23 stsp cp $testroot/wt/dotgotfoo.link $testroot/content
851 e26bafba 2020-07-23 stsp cmp -s $testroot/content.expected $testroot/content
853 e26bafba 2020-07-23 stsp if [ "$ret" != "0" ]; then
854 e26bafba 2020-07-23 stsp diff -u $testroot/content.expected $testroot/content
855 e26bafba 2020-07-23 stsp test_done "$testroot" "$ret"
859 e26bafba 2020-07-23 stsp if [ -h $testroot/wt/dotgotbar.link ]; then
860 e26bafba 2020-07-23 stsp echo "dotgotbar.link is a symlink"
861 e26bafba 2020-07-23 stsp test_done "$testroot" "1"
864 d219f183 2020-07-23 stsp echo "<<<<<<< merged change: commit $commit_id2" \
865 d219f183 2020-07-23 stsp > $testroot/content.expected
866 d219f183 2020-07-23 stsp echo -n ".got/bar" >> $testroot/content.expected
867 d219f183 2020-07-23 stsp echo "=======" >> $testroot/content.expected
868 d219f183 2020-07-23 stsp echo "this is regular file bar" >> $testroot/content.expected
869 d219f183 2020-07-23 stsp echo '>>>>>>>' >> $testroot/content.expected
870 d219f183 2020-07-23 stsp echo -n "" >> $testroot/content.expected
871 e26bafba 2020-07-23 stsp cp $testroot/wt/dotgotbar.link $testroot/content
872 e26bafba 2020-07-23 stsp cmp -s $testroot/content.expected $testroot/content
874 e26bafba 2020-07-23 stsp if [ "$ret" != "0" ]; then
875 e26bafba 2020-07-23 stsp diff -u $testroot/content.expected $testroot/content
876 e26bafba 2020-07-23 stsp test_done "$testroot" "$ret"
880 11cc08c1 2020-07-23 stsp if [ -h $testroot/wt/new.link ]; then
881 11cc08c1 2020-07-23 stsp echo "new.link is a symlink"
882 e26bafba 2020-07-23 stsp test_done "$testroot" "1"
886 11cc08c1 2020-07-23 stsp echo "<<<<<<< merged change: commit $commit_id2" \
887 283102fc 2020-07-23 stsp > $testroot/content.expected
888 11cc08c1 2020-07-23 stsp echo "alpha" >> $testroot/content.expected
889 11cc08c1 2020-07-23 stsp echo "=======" >> $testroot/content.expected
890 11cc08c1 2020-07-23 stsp echo "beta" >> $testroot/content.expected
891 11cc08c1 2020-07-23 stsp echo '>>>>>>>' >> $testroot/content.expected
892 11cc08c1 2020-07-23 stsp echo -n "" >> $testroot/content.expected
894 11cc08c1 2020-07-23 stsp cp $testroot/wt/new.link $testroot/content
895 11cc08c1 2020-07-23 stsp cmp -s $testroot/content.expected $testroot/content
897 e26bafba 2020-07-23 stsp if [ "$ret" != "0" ]; then
898 11cc08c1 2020-07-23 stsp diff -u $testroot/content.expected $testroot/content
899 e26bafba 2020-07-23 stsp test_done "$testroot" "$ret"
903 e26bafba 2020-07-23 stsp echo "A dotgotfoo.link" > $testroot/stdout.expected
904 e26bafba 2020-07-23 stsp echo "M new.link" >> $testroot/stdout.expected
905 e26bafba 2020-07-23 stsp echo "D nonexistent.link" >> $testroot/stdout.expected
906 e26bafba 2020-07-23 stsp (cd $testroot/wt && got status > $testroot/stdout)
907 e26bafba 2020-07-23 stsp if [ "$ret" != "0" ]; then
908 e26bafba 2020-07-23 stsp diff -u $testroot/stdout.expected $testroot/stdout
909 e26bafba 2020-07-23 stsp test_done "$testroot" "$ret"
913 af57b12a 2020-07-23 stsp test_done "$testroot" "0"
916 f6cae3ed 2020-09-13 naddy test_cherrypick_with_path_prefix_and_empty_tree() {
917 69d57f3d 2020-07-31 stsp local testroot=`test_init cherrypick_with_path_prefix_and_empty_tree 1`
919 69d57f3d 2020-07-31 stsp (cd $testroot/repo && git commit --allow-empty \
920 69d57f3d 2020-07-31 stsp -m "initial empty commit" >/dev/null)
922 69d57f3d 2020-07-31 stsp (cd $testroot/repo && got br bar >/dev/null)
924 69d57f3d 2020-07-31 stsp mkdir -p $testroot/repo/epsilon
925 69d57f3d 2020-07-31 stsp echo "file foo" > $testroot/repo/epsilon/foo
926 69d57f3d 2020-07-31 stsp (cd $testroot/repo && git add .)
927 69d57f3d 2020-07-31 stsp git_commit $testroot/repo -m "add file foo"
928 69d57f3d 2020-07-31 stsp local commit_id=`git_show_head $testroot/repo`
930 69d57f3d 2020-07-31 stsp got checkout -b bar $testroot/repo $testroot/wt > /dev/null
932 69d57f3d 2020-07-31 stsp if [ "$ret" != "0" ]; then
933 69d57f3d 2020-07-31 stsp echo "got checkout failed unexpectedly" >&2
934 69d57f3d 2020-07-31 stsp test_done "$testroot" "$ret"
938 69d57f3d 2020-07-31 stsp mkdir -p $testroot/wt/epsilon
939 69d57f3d 2020-07-31 stsp echo "new file" > $testroot/wt/epsilon/new
940 69d57f3d 2020-07-31 stsp (cd $testroot/wt && got add epsilon/new >/dev/null)
941 69d57f3d 2020-07-31 stsp (cd $testroot/wt && got commit -m "add file on branch bar" > /dev/null)
943 69d57f3d 2020-07-31 stsp got checkout -b bar -p epsilon $testroot/repo $testroot/wt2 > /dev/null
945 69d57f3d 2020-07-31 stsp if [ "$ret" != "0" ]; then
946 69d57f3d 2020-07-31 stsp echo "got checkout failed unexpectedly" >&2
947 69d57f3d 2020-07-31 stsp test_done "$testroot" "$ret"
950 69d57f3d 2020-07-31 stsp (cd $testroot/wt2 && got cherrypick $commit_id > $testroot/stdout)
952 69d57f3d 2020-07-31 stsp echo "A foo" > $testroot/stdout.expected
953 69d57f3d 2020-07-31 stsp echo "Merged commit $commit_id" >> $testroot/stdout.expected
955 cce854ad 2021-04-13 stsp cmp -s $testroot/stdout.expected $testroot/stdout
957 cce854ad 2021-04-13 stsp if [ "$ret" != "0" ]; then
958 cce854ad 2021-04-13 stsp diff -u $testroot/stdout.expected $testroot/stdout
960 cce854ad 2021-04-13 stsp test_done "$testroot" "$ret"
963 cce854ad 2021-04-13 stsp test_cherrypick_conflict_no_eol() {
964 cce854ad 2021-04-13 stsp local testroot=`test_init cherrypick_conflict_no_eol 1`
965 cce854ad 2021-04-13 stsp local content_a="aaa\naaa\naaa\naaa\naaa\naaa\n"
966 cce854ad 2021-04-13 stsp local content_b="aaa\naaa\nbbb\naaa\naaa\naaa\naaa"
967 cce854ad 2021-04-13 stsp local content_c="aaa\naaa\nccc\naaa\naaa\naaa\naaa"
969 cce854ad 2021-04-13 stsp printf "$content_a" > $testroot/repo/a
970 cce854ad 2021-04-13 stsp (cd $testroot/repo && git add a)
971 cce854ad 2021-04-13 stsp git_commit $testroot/repo -m "initial commit"
973 cce854ad 2021-04-13 stsp (cd $testroot/repo && got branch newbranch)
975 cce854ad 2021-04-13 stsp printf "$content_b" > $testroot/repo/a
976 cce854ad 2021-04-13 stsp git_commit $testroot/repo -m "change bbb"
978 cce854ad 2021-04-13 stsp printf "$content_c" > $testroot/repo/a
979 cce854ad 2021-04-13 stsp git_commit $testroot/repo -m "change ccc"
980 cce854ad 2021-04-13 stsp local ccc_commit=`git_show_head $testroot/repo`
982 cce854ad 2021-04-13 stsp got checkout -b newbranch $testroot/repo $testroot/wt > /dev/null
984 cce854ad 2021-04-13 stsp if [ "$ret" != "0" ]; then
985 cce854ad 2021-04-13 stsp test_done "$testroot" "$ret"
989 cce854ad 2021-04-13 stsp (cd $testroot/wt && got cherrypick $ccc_commit > $testroot/stdout)
991 cce854ad 2021-04-13 stsp echo "C a" > $testroot/stdout.expected
992 cce854ad 2021-04-13 stsp echo "Merged commit $ccc_commit" >> $testroot/stdout.expected
993 cce854ad 2021-04-13 stsp echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
995 69d57f3d 2020-07-31 stsp cmp -s $testroot/stdout.expected $testroot/stdout
997 69d57f3d 2020-07-31 stsp if [ "$ret" != "0" ]; then
998 69d57f3d 2020-07-31 stsp diff -u $testroot/stdout.expected $testroot/stdout
1000 cce854ad 2021-04-13 stsp test_done "$testroot" "$ret"
1003 cce854ad 2021-04-13 stsp test_cherrypick_conflict_no_eol2() {
1004 cce854ad 2021-04-13 stsp local testroot=`test_init cherrypick_conflict_no_eol2 1`
1005 cce854ad 2021-04-13 stsp local content_a="aaa\naaa\naaa\naaa\naaa\naaa"
1006 cce854ad 2021-04-13 stsp local content_b="aaa\naaa\nbbb\naaa\naaa\naaa"
1007 cce854ad 2021-04-13 stsp local content_c="aaa\naaa\nbbb\naaa\naaa\naaa\n"
1009 cce854ad 2021-04-13 stsp printf "$content_a" > $testroot/repo/a
1010 cce854ad 2021-04-13 stsp (cd $testroot/repo && git add a)
1011 cce854ad 2021-04-13 stsp git_commit $testroot/repo -m "initial commit"
1013 cce854ad 2021-04-13 stsp (cd $testroot/repo && got branch newbranch)
1015 cce854ad 2021-04-13 stsp printf "$content_b" > $testroot/repo/a
1016 cce854ad 2021-04-13 stsp git_commit $testroot/repo -m "change bbb"
1018 cce854ad 2021-04-13 stsp printf "$content_c" > $testroot/repo/a
1019 cce854ad 2021-04-13 stsp git_commit $testroot/repo -m "change ccc"
1020 cce854ad 2021-04-13 stsp local ccc_commit=`git_show_head $testroot/repo`
1022 cce854ad 2021-04-13 stsp got checkout -b newbranch $testroot/repo $testroot/wt > /dev/null
1024 cce854ad 2021-04-13 stsp if [ "$ret" != "0" ]; then
1025 cce854ad 2021-04-13 stsp test_done "$testroot" "$ret"
1029 cce854ad 2021-04-13 stsp (cd $testroot/wt && got cherrypick $ccc_commit \
1030 cce854ad 2021-04-13 stsp > $testroot/stdout 2> $testroot/stderr)
1032 cce854ad 2021-04-13 stsp echo "C a" > $testroot/stdout.expected
1033 cce854ad 2021-04-13 stsp echo "Merged commit $ccc_commit" >> $testroot/stdout.expected
1034 cce854ad 2021-04-13 stsp echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
1036 cce854ad 2021-04-13 stsp cmp -s $testroot/stdout.expected $testroot/stdout
1038 cce854ad 2021-04-13 stsp if [ "$ret" != "0" ]; then
1039 54d5be07 2021-06-03 stsp diff -u $testroot/stdout.expected $testroot/stdout
1041 3cd22b21 2021-05-31 stsp test_done "$testroot" "$ret"
1044 3cd22b21 2021-05-31 stsp test_cherrypick_unrelated_changes() {
1045 3cd22b21 2021-05-31 stsp local testroot=`test_init cherrypick_unrelated_changes`
1047 3cd22b21 2021-05-31 stsp # Sorry about the large HERE document but I have not found
1048 3cd22b21 2021-05-31 stsp # a smaller reproduction recipe yet...
1049 3cd22b21 2021-05-31 stsp cat > $testroot/repo/reference.c <<EOF
1050 3cd22b21 2021-05-31 stsp const struct got_error *
1051 3cd22b21 2021-05-31 stsp got_ref_alloc(struct got_reference **ref, const char *name,
1052 3cd22b21 2021-05-31 stsp struct got_object_id *id)
1054 3cd22b21 2021-05-31 stsp if (!is_valid_ref_name(name))
1055 3cd22b21 2021-05-31 stsp return got_error_path(name, GOT_ERR_BAD_REF_NAME);
1057 3cd22b21 2021-05-31 stsp return alloc_ref(ref, name, id, 0);
1060 3cd22b21 2021-05-31 stsp static const struct got_error *
1061 3cd22b21 2021-05-31 stsp parse_packed_ref_line(struct got_reference **ref, const char *abs_refname,
1062 3cd22b21 2021-05-31 stsp const char *line)
1064 3cd22b21 2021-05-31 stsp struct got_object_id id;
1065 3cd22b21 2021-05-31 stsp const char *name;
1067 3cd22b21 2021-05-31 stsp *ref = NULL;
1069 3cd22b21 2021-05-31 stsp if (line[0] == '#' || line[0] == '^')
1070 3cd22b21 2021-05-31 stsp return NULL;
1072 3cd22b21 2021-05-31 stsp if (!got_parse_sha1_digest(id.sha1, line))
1073 3cd22b21 2021-05-31 stsp return got_error(GOT_ERR_BAD_REF_DATA);
1075 3cd22b21 2021-05-31 stsp if (abs_refname) {
1076 3cd22b21 2021-05-31 stsp if (strcmp(line + SHA1_DIGEST_STRING_LENGTH, abs_refname) != 0)
1077 3cd22b21 2021-05-31 stsp return NULL;
1078 3cd22b21 2021-05-31 stsp name = abs_refname;
1080 3cd22b21 2021-05-31 stsp name = line + SHA1_DIGEST_STRING_LENGTH;
1082 3cd22b21 2021-05-31 stsp return alloc_ref(ref, name, &id, GOT_REF_IS_PACKED);
1085 3cd22b21 2021-05-31 stsp static const struct got_error *
1086 3cd22b21 2021-05-31 stsp open_packed_ref(struct got_reference **ref, FILE *f, const char **subdirs,
1087 3cd22b21 2021-05-31 stsp int nsubdirs, const char *refname)
1089 3cd22b21 2021-05-31 stsp const struct got_error *err = NULL;
1090 3cd22b21 2021-05-31 stsp char *abs_refname;
1091 3cd22b21 2021-05-31 stsp char *line = NULL;
1092 3cd22b21 2021-05-31 stsp size_t linesize = 0;
1093 3cd22b21 2021-05-31 stsp ssize_t linelen;
1094 3cd22b21 2021-05-31 stsp int i, ref_is_absolute = (strncmp(refname, "refs/", 5) == 0);
1096 3cd22b21 2021-05-31 stsp *ref = NULL;
1098 3cd22b21 2021-05-31 stsp if (ref_is_absolute)
1099 3cd22b21 2021-05-31 stsp abs_refname = (char *)refname;
1101 3cd22b21 2021-05-31 stsp linelen = getline(&line, &linesize, f);
1102 3cd22b21 2021-05-31 stsp if (linelen == -1) {
1103 3cd22b21 2021-05-31 stsp if (feof(f))
1105 3cd22b21 2021-05-31 stsp err = got_ferror(f, GOT_ERR_BAD_REF_DATA);
1108 3cd22b21 2021-05-31 stsp if (linelen > 0 && line[linelen - 1] == '\n')
1109 3cd22b21 2021-05-31 stsp line[linelen - 1] = '\0';
1110 3cd22b21 2021-05-31 stsp for (i = 0; i < nsubdirs; i++) {
1111 3cd22b21 2021-05-31 stsp if (!ref_is_absolute &&
1112 3cd22b21 2021-05-31 stsp asprintf(&abs_refname, "refs/%s/%s", subdirs[i],
1113 3cd22b21 2021-05-31 stsp refname) == -1)
1114 3cd22b21 2021-05-31 stsp return got_error_from_errno("asprintf");
1115 3cd22b21 2021-05-31 stsp err = parse_packed_ref_line(ref, abs_refname, line);
1116 3cd22b21 2021-05-31 stsp if (!ref_is_absolute)
1117 3cd22b21 2021-05-31 stsp free(abs_refname);
1118 3cd22b21 2021-05-31 stsp if (err || *ref != NULL)
1123 3cd22b21 2021-05-31 stsp } while (*ref == NULL);
1124 3cd22b21 2021-05-31 stsp free(line);
1126 3cd22b21 2021-05-31 stsp return err;
1129 3cd22b21 2021-05-31 stsp static const struct got_error *
1130 3cd22b21 2021-05-31 stsp open_ref(struct got_reference **ref, const char *path_refs, const char *subdir,
1131 3cd22b21 2021-05-31 stsp const char *name, int lock)
1133 3cd22b21 2021-05-31 stsp const struct got_error *err = NULL;
1134 3cd22b21 2021-05-31 stsp char *path = NULL;
1135 3cd22b21 2021-05-31 stsp char *absname = NULL;
1136 3cd22b21 2021-05-31 stsp int ref_is_absolute = (strncmp(name, "refs/", 5) == 0);
1137 3cd22b21 2021-05-31 stsp int ref_is_well_known = (subdir[0] == '\0' && is_well_known_ref(name));
1139 3cd22b21 2021-05-31 stsp *ref = NULL;
1141 3cd22b21 2021-05-31 stsp if (ref_is_absolute || ref_is_well_known) {
1142 3cd22b21 2021-05-31 stsp if (asprintf(&path, "%s/%s", path_refs, name) == -1)
1143 3cd22b21 2021-05-31 stsp return got_error_from_errno("asprintf");
1144 3cd22b21 2021-05-31 stsp absname = (char *)name;
1146 3cd22b21 2021-05-31 stsp if (asprintf(&path, "%s/%s%s%s", path_refs, subdir,
1147 3cd22b21 2021-05-31 stsp subdir[0] ? "/" : "", name) == -1)
1148 3cd22b21 2021-05-31 stsp return got_error_from_errno("asprintf");
1150 3cd22b21 2021-05-31 stsp if (asprintf(&absname, "refs/%s%s%s",
1151 3cd22b21 2021-05-31 stsp subdir, subdir[0] ? "/" : "", name) == -1) {
1152 3cd22b21 2021-05-31 stsp err = got_error_from_errno("asprintf");
1153 3cd22b21 2021-05-31 stsp goto done;
1157 3cd22b21 2021-05-31 stsp err = parse_ref_file(ref, name, absname, path, lock);
1159 3cd22b21 2021-05-31 stsp if (!ref_is_absolute && !ref_is_well_known)
1160 3cd22b21 2021-05-31 stsp free(absname);
1161 3cd22b21 2021-05-31 stsp free(path);
1162 3cd22b21 2021-05-31 stsp return err;
1165 3cd22b21 2021-05-31 stsp const struct got_error *
1166 3cd22b21 2021-05-31 stsp got_ref_open(struct got_reference **ref, struct got_repository *repo,
1167 3cd22b21 2021-05-31 stsp const char *refname, int lock)
1169 3cd22b21 2021-05-31 stsp const struct got_error *err = NULL;
1170 3cd22b21 2021-05-31 stsp char *path_refs = NULL;
1171 3cd22b21 2021-05-31 stsp const char *subdirs[] = {
1172 3cd22b21 2021-05-31 stsp GOT_REF_HEADS, GOT_REF_TAGS, GOT_REF_REMOTES
1175 3cd22b21 2021-05-31 stsp int well_known = is_well_known_ref(refname);
1176 3cd22b21 2021-05-31 stsp struct got_lockfile *lf = NULL;
1178 3cd22b21 2021-05-31 stsp *ref = NULL;
1180 3cd22b21 2021-05-31 stsp path_refs = get_refs_dir_path(repo, refname);
1181 3cd22b21 2021-05-31 stsp if (path_refs == NULL) {
1182 3cd22b21 2021-05-31 stsp err = got_error_from_errno2("get_refs_dir_path", refname);
1183 3cd22b21 2021-05-31 stsp goto done;
1186 3cd22b21 2021-05-31 stsp if (well_known) {
1187 3cd22b21 2021-05-31 stsp err = open_ref(ref, path_refs, "", refname, lock);
1189 3cd22b21 2021-05-31 stsp char *packed_refs_path;
1192 3cd22b21 2021-05-31 stsp /* Search on-disk refs before packed refs! */
1193 3cd22b21 2021-05-31 stsp for (i = 0; i < nitems(subdirs); i++) {
1194 3cd22b21 2021-05-31 stsp err = open_ref(ref, path_refs, subdirs[i], refname,
1196 3cd22b21 2021-05-31 stsp if ((err && err->code != GOT_ERR_NOT_REF) || *ref)
1197 3cd22b21 2021-05-31 stsp goto done;
1200 3cd22b21 2021-05-31 stsp packed_refs_path = got_repo_get_path_packed_refs(repo);
1201 3cd22b21 2021-05-31 stsp if (packed_refs_path == NULL) {
1202 3cd22b21 2021-05-31 stsp err = got_error_from_errno(
1203 3cd22b21 2021-05-31 stsp "got_repo_get_path_packed_refs");
1204 3cd22b21 2021-05-31 stsp goto done;
1207 3cd22b21 2021-05-31 stsp if (lock) {
1208 3cd22b21 2021-05-31 stsp err = got_lockfile_lock(&lf, packed_refs_path);
1210 3cd22b21 2021-05-31 stsp goto done;
1212 3cd22b21 2021-05-31 stsp f = fopen(packed_refs_path, "rb");
1213 3cd22b21 2021-05-31 stsp free(packed_refs_path);
1214 3cd22b21 2021-05-31 stsp if (f != NULL) {
1215 3cd22b21 2021-05-31 stsp err = open_packed_ref(ref, f, subdirs, nitems(subdirs),
1217 3cd22b21 2021-05-31 stsp if (!err) {
1218 3cd22b21 2021-05-31 stsp if (fclose(f) == EOF) {
1219 3cd22b21 2021-05-31 stsp err = got_error_from_errno("fclose");
1220 3cd22b21 2021-05-31 stsp got_ref_close(*ref);
1221 3cd22b21 2021-05-31 stsp *ref = NULL;
1222 3cd22b21 2021-05-31 stsp } else if (*ref)
1223 3cd22b21 2021-05-31 stsp (*ref)->lf = lf;
1228 3cd22b21 2021-05-31 stsp if (!err && *ref == NULL)
1229 3cd22b21 2021-05-31 stsp err = got_error_not_ref(refname);
1230 3cd22b21 2021-05-31 stsp if (err && lf)
1231 3cd22b21 2021-05-31 stsp got_lockfile_unlock(lf);
1232 3cd22b21 2021-05-31 stsp free(path_refs);
1233 3cd22b21 2021-05-31 stsp return err;
1236 3cd22b21 2021-05-31 stsp struct got_reference *
1237 3cd22b21 2021-05-31 stsp got_ref_dup(struct got_reference *ref)
1239 3cd22b21 2021-05-31 stsp struct got_reference *ret;
1241 3cd22b21 2021-05-31 stsp ret = calloc(1, sizeof(*ret));
1242 3cd22b21 2021-05-31 stsp if (ret == NULL)
1243 3cd22b21 2021-05-31 stsp return NULL;
1245 3cd22b21 2021-05-31 stsp ret->flags = ref->flags;
1246 3cd22b21 2021-05-31 stsp if (ref->flags & GOT_REF_IS_SYMBOLIC) {
1247 3cd22b21 2021-05-31 stsp ret->ref.symref.name = strdup(ref->ref.symref.name);
1248 3cd22b21 2021-05-31 stsp if (ret->ref.symref.name == NULL) {
1249 3cd22b21 2021-05-31 stsp free(ret);
1250 3cd22b21 2021-05-31 stsp return NULL;
1252 3cd22b21 2021-05-31 stsp ret->ref.symref.ref = strdup(ref->ref.symref.ref);
1253 3cd22b21 2021-05-31 stsp if (ret->ref.symref.ref == NULL) {
1254 3cd22b21 2021-05-31 stsp free(ret->ref.symref.name);
1255 3cd22b21 2021-05-31 stsp free(ret);
1256 3cd22b21 2021-05-31 stsp return NULL;
1259 3cd22b21 2021-05-31 stsp ret->ref.ref.name = strdup(ref->ref.ref.name);
1260 3cd22b21 2021-05-31 stsp if (ret->ref.ref.name == NULL) {
1261 3cd22b21 2021-05-31 stsp free(ret);
1262 3cd22b21 2021-05-31 stsp return NULL;
1264 3cd22b21 2021-05-31 stsp memcpy(ret->ref.ref.sha1, ref->ref.ref.sha1,
1265 3cd22b21 2021-05-31 stsp sizeof(ret->ref.ref.sha1));
1268 3cd22b21 2021-05-31 stsp return ret;
1271 3cd22b21 2021-05-31 stsp const struct got_error *
1272 3cd22b21 2021-05-31 stsp got_reflist_entry_dup(struct got_reflist_entry **newp,
1273 3cd22b21 2021-05-31 stsp struct got_reflist_entry *re)
1275 3cd22b21 2021-05-31 stsp const struct got_error *err = NULL;
1276 3cd22b21 2021-05-31 stsp struct got_reflist_entry *new;
1278 3cd22b21 2021-05-31 stsp *newp = NULL;
1280 3cd22b21 2021-05-31 stsp new = malloc(sizeof(*new));
1281 3cd22b21 2021-05-31 stsp if (new == NULL)
1282 3cd22b21 2021-05-31 stsp return got_error_from_errno("malloc");
1284 3cd22b21 2021-05-31 stsp new->ref = got_ref_dup(re->ref);
1285 3cd22b21 2021-05-31 stsp if (new->ref == NULL) {
1286 3cd22b21 2021-05-31 stsp err = got_error_from_errno("got_ref_dup");
1287 3cd22b21 2021-05-31 stsp free(new);
1288 3cd22b21 2021-05-31 stsp return err;
1291 3cd22b21 2021-05-31 stsp *newp = new;
1292 3cd22b21 2021-05-31 stsp return NULL;
1296 3cd22b21 2021-05-31 stsp got_ref_list_free(struct got_reflist_head *refs)
1298 3cd22b21 2021-05-31 stsp struct got_reflist_entry *re;
1300 3cd22b21 2021-05-31 stsp while ((re = TAILQ_FIRST(refs))) {
1301 3cd22b21 2021-05-31 stsp TAILQ_REMOVE(refs, re, entry);
1307 3cd22b21 2021-05-31 stsp (cd $testroot/repo && git add reference.c)
1308 3cd22b21 2021-05-31 stsp git_commit $testroot/repo -m "added reference.c file"
1309 3cd22b21 2021-05-31 stsp local base_commit=`git_show_head $testroot/repo`
1311 3cd22b21 2021-05-31 stsp got checkout $testroot/repo $testroot/wt > /dev/null
1313 3cd22b21 2021-05-31 stsp if [ "$ret" != "0" ]; then
1314 3cd22b21 2021-05-31 stsp test_done "$testroot" "$ret"
1318 3cd22b21 2021-05-31 stsp (cd $testroot/repo && git checkout -q -b newbranch)
1319 3cd22b21 2021-05-31 stsp ed -s $testroot/repo/reference.c <<EOF
1321 3cd22b21 2021-05-31 stsp if (!is_valid_ref_name(name))
1322 3cd22b21 2021-05-31 stsp return got_error_path(name, GOT_ERR_BAD_REF_NAME);
1328 3cd22b21 2021-05-31 stsp git_commit $testroot/repo -m "added lines on newbranch"
1329 3cd22b21 2021-05-31 stsp local branch_rev1=`git_show_head $testroot/repo`
1331 3cd22b21 2021-05-31 stsp ed -s $testroot/repo/reference.c <<EOF
1333 3cd22b21 2021-05-31 stsp got_ref_close(re->ref);
1338 3cd22b21 2021-05-31 stsp git_commit $testroot/repo -m "more lines on newbranch"
1340 3cd22b21 2021-05-31 stsp local branch_rev2=`git_show_head $testroot/repo`
1342 3cd22b21 2021-05-31 stsp (cd $testroot/wt && got cherrypick $branch_rev2 > $testroot/stdout)
1344 3cd22b21 2021-05-31 stsp echo "G reference.c" > $testroot/stdout.expected
1345 3cd22b21 2021-05-31 stsp echo "Merged commit $branch_rev2" >> $testroot/stdout.expected
1347 3cd22b21 2021-05-31 stsp cmp -s $testroot/stdout.expected $testroot/stdout
1349 3cd22b21 2021-05-31 stsp if [ "$ret" != "0" ]; then
1350 3cd22b21 2021-05-31 stsp diff -u $testroot/stdout.expected $testroot/stdout
1351 3cd22b21 2021-05-31 stsp test_done "$testroot" "$ret"
1355 3cd22b21 2021-05-31 stsp cat > $testroot/diff.expected <<EOF
1356 3cd22b21 2021-05-31 stsp --- reference.c
1357 3cd22b21 2021-05-31 stsp +++ reference.c
1358 3cd22b21 2021-05-31 stsp @@ -250,6 +250,7 @@ got_ref_list_free(struct got_reflist_head *refs)
1360 3cd22b21 2021-05-31 stsp while ((re = TAILQ_FIRST(refs))) {
1361 3cd22b21 2021-05-31 stsp TAILQ_REMOVE(refs, re, entry);
1362 3cd22b21 2021-05-31 stsp + got_ref_close(re->ref);
1367 3cd22b21 2021-05-31 stsp (cd $testroot/wt && got diff |
1368 3cd22b21 2021-05-31 stsp egrep -v '^(diff|blob|file)' > $testroot/diff)
1369 3cd22b21 2021-05-31 stsp cmp -s $testroot/diff.expected $testroot/diff
1371 3cd22b21 2021-05-31 stsp if [ "$ret" != "0" ]; then
1372 54d5be07 2021-06-03 stsp diff -u $testroot/diff.expected $testroot/diff
1375 0baddd91 2021-09-03 stsp test_done "$testroot" "$ret"
1378 0baddd91 2021-09-03 stsp test_cherrypick_same_branch() {
1379 0baddd91 2021-09-03 stsp local testroot=`test_init cherrypick_same_branch`
1381 0baddd91 2021-09-03 stsp got checkout $testroot/repo $testroot/wt > /dev/null
1383 0baddd91 2021-09-03 stsp if [ "$ret" != "0" ]; then
1384 0baddd91 2021-09-03 stsp test_done "$testroot" "$ret"
1388 0baddd91 2021-09-03 stsp (cd $testroot/repo && git checkout -q -b newbranch)
1389 0baddd91 2021-09-03 stsp echo "modified delta on branch" > $testroot/repo/gamma/delta
1390 0baddd91 2021-09-03 stsp git_commit $testroot/repo -m "committing to delta on newbranch"
1392 0baddd91 2021-09-03 stsp echo "modified alpha on branch" > $testroot/repo/alpha
1393 0baddd91 2021-09-03 stsp (cd $testroot/repo && git rm -q beta)
1394 0baddd91 2021-09-03 stsp echo "new file on branch" > $testroot/repo/epsilon/new
1395 0baddd91 2021-09-03 stsp (cd $testroot/repo && git add epsilon/new)
1396 0baddd91 2021-09-03 stsp git_commit $testroot/repo -m "committing more changes on newbranch"
1398 0baddd91 2021-09-03 stsp local branch_rev=`git_show_head $testroot/repo`
1400 0baddd91 2021-09-03 stsp # picking a commit from the branch's own history does not make
1401 0baddd91 2021-09-03 stsp # sense but we should have test coverage for this case regardless
1402 0baddd91 2021-09-03 stsp (cd $testroot/wt && got up -b newbranch > /dev/null)
1403 0baddd91 2021-09-03 stsp (cd $testroot/wt && got cherrypick $branch_rev > $testroot/stdout)
1405 0baddd91 2021-09-03 stsp echo "G alpha" > $testroot/stdout.expected
1406 0baddd91 2021-09-03 stsp echo "! beta" >> $testroot/stdout.expected
1407 0baddd91 2021-09-03 stsp echo "G epsilon/new" >> $testroot/stdout.expected
1408 0baddd91 2021-09-03 stsp echo "Merged commit $branch_rev" >> $testroot/stdout.expected
1410 0baddd91 2021-09-03 stsp cmp -s $testroot/stdout.expected $testroot/stdout
1412 0baddd91 2021-09-03 stsp if [ "$ret" != "0" ]; then
1413 0baddd91 2021-09-03 stsp diff -u $testroot/stdout.expected $testroot/stdout
1415 69d57f3d 2020-07-31 stsp test_done "$testroot" "$ret"
1419 7fb414ae 2020-08-08 stsp test_parseargs "$@"
1420 234035bc 2019-06-01 stsp run_test test_cherrypick_basic
1421 03415a1a 2019-06-02 stsp run_test test_cherrypick_root_commit
1422 ceb466a7 2020-04-18 stsp run_test test_cherrypick_into_work_tree_with_conflicts
1423 ed99f061 2021-09-03 stsp run_test test_cherrypick_into_work_tree_with_mixed_commits
1424 e7303626 2020-05-14 stsp run_test test_cherrypick_modified_submodule
1425 e7303626 2020-05-14 stsp run_test test_cherrypick_added_submodule
1426 e7303626 2020-05-14 stsp run_test test_cherrypick_conflict_wt_file_vs_repo_submodule
1427 af57b12a 2020-07-23 stsp run_test test_cherrypick_modified_symlinks
1428 e26bafba 2020-07-23 stsp run_test test_cherrypick_symlink_conflicts
1429 69d57f3d 2020-07-31 stsp run_test test_cherrypick_with_path_prefix_and_empty_tree
1430 cce854ad 2021-04-13 stsp run_test test_cherrypick_conflict_no_eol
1431 cce854ad 2021-04-13 stsp run_test test_cherrypick_conflict_no_eol2
1432 3cd22b21 2021-05-31 stsp run_test test_cherrypick_unrelated_changes
1433 0baddd91 2021-09-03 stsp run_test test_cherrypick_same_branch