Blame


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