Blame


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