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