]>
Commit | Line | Data |
---|---|---|
d3a04e06 DG |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2012 Avery Pennaraum | |
5b6ab38b | 4 | # Copyright (c) 2015 Alexey Shumkin |
d3a04e06 DG |
5 | # |
6 | test_description='Basic porcelain support for subtrees | |
7 | ||
94389e7c LS |
8 | This test verifies the basic operation of the add, merge, split, pull, |
9 | and push subcommands of git subtree. | |
d3a04e06 DG |
10 | ' |
11 | ||
bed137d2 | 12 | TEST_DIRECTORY=$(pwd)/../../../t |
f7004069 | 13 | . "$TEST_DIRECTORY"/test-lib.sh |
603ee0f0 | 14 | |
40b1e1ec LS |
15 | # Use our own wrapper around test-lib.sh's test_create_repo, in order |
16 | # to set log.date=relative. `git subtree` parses the output of `git | |
17 | # log`, and so it must be careful to not be affected by settings that | |
18 | # change the `git log` output. We test this by setting | |
19 | # log.date=relative for every repo in the tests. | |
f7004069 | 20 | subtree_test_create_repo () { |
fbd3199a | 21 | test_create_repo "$1" && |
40b1e1ec | 22 | git -C "$1" config log.date relative |
43711746 TZ |
23 | } |
24 | ||
f7004069 | 25 | test_create_commit () ( |
fbd3199a DA |
26 | repo=$1 && |
27 | commit=$2 && | |
28 | cd "$repo" && | |
29 | mkdir -p "$(dirname "$commit")" \ | |
43711746 | 30 | || error "Could not create directory for commit" |
fbd3199a | 31 | echo "$commit" >"$commit" && |
43711746 TZ |
32 | git add "$commit" || error "Could not add commit" |
33 | git commit -m "$commit" || error "Could not commit" | |
34 | ) | |
35 | ||
9a3e3ca2 LS |
36 | test_wrong_flag() { |
37 | test_must_fail "$@" >out 2>err && | |
38 | test_must_be_empty out && | |
39 | grep "flag does not make sense with" err | |
40 | } | |
41 | ||
db6952b2 | 42 | last_commit_subject () { |
6fe98630 | 43 | git log --pretty=format:%s -1 |
13ea2b5e JS |
44 | } |
45 | ||
0d330673 PB |
46 | # Upon 'git subtree add|merge --squash' of an annotated tag, |
47 | # pre-2.32.0 versions of 'git subtree' would write the hash of the tag | |
48 | # (sub1 below), instead of the commit (sub1^{commit}) in the | |
49 | # "git-subtree-split" trailer. | |
50 | # We immitate this behaviour below using a replace ref. | |
51 | # This function creates 3 repositories: | |
52 | # - $1 | |
53 | # - $1-sub (added as subtree "sub" in $1) | |
54 | # - $1-clone (clone of $1) | |
55 | test_create_pre2_32_repo () { | |
56 | subtree_test_create_repo "$1" && | |
57 | subtree_test_create_repo "$1-sub" && | |
58 | test_commit -C "$1" main1 && | |
59 | test_commit -C "$1-sub" --annotate sub1 && | |
60 | git -C "$1" subtree add --prefix="sub" --squash "../$1-sub" sub1 && | |
61 | tag=$(git -C "$1" rev-parse FETCH_HEAD) && | |
62 | commit=$(git -C "$1" rev-parse FETCH_HEAD^{commit}) && | |
63 | git -C "$1" log -1 --format=%B HEAD^2 >msg && | |
64 | test_commit -C "$1-sub" --annotate sub2 && | |
65 | git clone --no-local "$1" "$1-clone" && | |
66 | new_commit=$(cat msg | sed -e "s/$commit/$tag/" | git -C "$1-clone" commit-tree HEAD^2^{tree}) && | |
67 | git -C "$1-clone" replace HEAD^2 $new_commit | |
68 | } | |
69 | ||
b2699769 LS |
70 | test_expect_success 'shows short help text for -h' ' |
71 | test_expect_code 129 git subtree -h >out 2>err && | |
72 | test_must_be_empty err && | |
73 | grep -e "^ *or: git subtree pull" out && | |
e8e5d294 | 74 | grep -F -e "--[no-]annotate" out |
b2699769 LS |
75 | ' |
76 | ||
43711746 TZ |
77 | # |
78 | # Tests for 'git subtree add' | |
79 | # | |
d3a04e06 | 80 | |
a6867011 | 81 | test_expect_success 'no merge from non-existent subtree' ' |
f2bb7fef LS |
82 | subtree_test_create_repo "$test_count" && |
83 | subtree_test_create_repo "$test_count/sub proj" && | |
84 | test_create_commit "$test_count" main1 && | |
85 | test_create_commit "$test_count/sub proj" sub1 && | |
43711746 | 86 | ( |
f2bb7fef | 87 | cd "$test_count" && |
914d5125 | 88 | git fetch ./"sub proj" HEAD && |
43711746 TZ |
89 | test_must_fail git subtree merge --prefix="sub dir" FETCH_HEAD |
90 | ) | |
a6867011 TZ |
91 | ' |
92 | ||
43711746 | 93 | test_expect_success 'no pull from non-existent subtree' ' |
f2bb7fef LS |
94 | subtree_test_create_repo "$test_count" && |
95 | subtree_test_create_repo "$test_count/sub proj" && | |
96 | test_create_commit "$test_count" main1 && | |
97 | test_create_commit "$test_count/sub proj" sub1 && | |
43711746 | 98 | ( |
f2bb7fef | 99 | cd "$test_count" && |
914d5125 LS |
100 | git fetch ./"sub proj" HEAD && |
101 | test_must_fail git subtree pull --prefix="sub dir" ./"sub proj" HEAD | |
f7004069 LS |
102 | ) |
103 | ' | |
c9924996 | 104 | |
9a3e3ca2 LS |
105 | test_expect_success 'add rejects flags for split' ' |
106 | subtree_test_create_repo "$test_count" && | |
107 | subtree_test_create_repo "$test_count/sub proj" && | |
108 | test_create_commit "$test_count" main1 && | |
109 | test_create_commit "$test_count/sub proj" sub1 && | |
110 | ( | |
111 | cd "$test_count" && | |
112 | git fetch ./"sub proj" HEAD && | |
113 | test_wrong_flag git subtree add --prefix="sub dir" --annotate=foo FETCH_HEAD && | |
114 | test_wrong_flag git subtree add --prefix="sub dir" --branch=foo FETCH_HEAD && | |
115 | test_wrong_flag git subtree add --prefix="sub dir" --ignore-joins FETCH_HEAD && | |
116 | test_wrong_flag git subtree add --prefix="sub dir" --onto=foo FETCH_HEAD && | |
117 | test_wrong_flag git subtree add --prefix="sub dir" --rejoin FETCH_HEAD | |
118 | ) | |
119 | ' | |
120 | ||
43711746 | 121 | test_expect_success 'add subproj as subtree into sub dir/ with --prefix' ' |
f2bb7fef LS |
122 | subtree_test_create_repo "$test_count" && |
123 | subtree_test_create_repo "$test_count/sub proj" && | |
124 | test_create_commit "$test_count" main1 && | |
125 | test_create_commit "$test_count/sub proj" sub1 && | |
43711746 | 126 | ( |
f2bb7fef | 127 | cd "$test_count" && |
914d5125 | 128 | git fetch ./"sub proj" HEAD && |
43711746 | 129 | git subtree add --prefix="sub dir" FETCH_HEAD && |
db6952b2 | 130 | test "$(last_commit_subject)" = "Add '\''sub dir/'\'' from commit '\''$(git rev-parse FETCH_HEAD)'\''" |
43711746 | 131 | ) |
d3a04e06 DG |
132 | ' |
133 | ||
c9924996 | 134 | test_expect_success 'add subproj as subtree into sub dir/ with --prefix and --message' ' |
f2bb7fef LS |
135 | subtree_test_create_repo "$test_count" && |
136 | subtree_test_create_repo "$test_count/sub proj" && | |
137 | test_create_commit "$test_count" main1 && | |
138 | test_create_commit "$test_count/sub proj" sub1 && | |
43711746 | 139 | ( |
f2bb7fef | 140 | cd "$test_count" && |
914d5125 | 141 | git fetch ./"sub proj" HEAD && |
43711746 | 142 | git subtree add --prefix="sub dir" --message="Added subproject" FETCH_HEAD && |
db6952b2 | 143 | test "$(last_commit_subject)" = "Added subproject" |
43711746 | 144 | ) |
d3a04e06 DG |
145 | ' |
146 | ||
43711746 | 147 | test_expect_success 'add subproj as subtree into sub dir/ with --prefix as -P and --message as -m' ' |
f2bb7fef LS |
148 | subtree_test_create_repo "$test_count" && |
149 | subtree_test_create_repo "$test_count/sub proj" && | |
150 | test_create_commit "$test_count" main1 && | |
151 | test_create_commit "$test_count/sub proj" sub1 && | |
43711746 | 152 | ( |
f2bb7fef | 153 | cd "$test_count" && |
914d5125 | 154 | git fetch ./"sub proj" HEAD && |
43711746 | 155 | git subtree add -P "sub dir" -m "Added subproject" FETCH_HEAD && |
db6952b2 | 156 | test "$(last_commit_subject)" = "Added subproject" |
43711746 | 157 | ) |
d3a04e06 DG |
158 | ' |
159 | ||
c9924996 | 160 | test_expect_success 'add subproj as subtree into sub dir/ with --squash and --prefix and --message' ' |
f2bb7fef LS |
161 | subtree_test_create_repo "$test_count" && |
162 | subtree_test_create_repo "$test_count/sub proj" && | |
163 | test_create_commit "$test_count" main1 && | |
164 | test_create_commit "$test_count/sub proj" sub1 && | |
43711746 | 165 | ( |
f2bb7fef | 166 | cd "$test_count" && |
914d5125 | 167 | git fetch ./"sub proj" HEAD && |
43711746 | 168 | git subtree add --prefix="sub dir" --message="Added subproject with squash" --squash FETCH_HEAD && |
db6952b2 | 169 | test "$(last_commit_subject)" = "Added subproject with squash" |
43711746 | 170 | ) |
d3a04e06 DG |
171 | ' |
172 | ||
43711746 TZ |
173 | # |
174 | # Tests for 'git subtree merge' | |
175 | # | |
d3a04e06 | 176 | |
9a3e3ca2 LS |
177 | test_expect_success 'merge rejects flags for split' ' |
178 | subtree_test_create_repo "$test_count" && | |
179 | subtree_test_create_repo "$test_count/sub proj" && | |
180 | test_create_commit "$test_count" main1 && | |
181 | test_create_commit "$test_count/sub proj" sub1 && | |
182 | ( | |
183 | cd "$test_count" && | |
184 | git fetch ./"sub proj" HEAD && | |
185 | git subtree add --prefix="sub dir" FETCH_HEAD | |
186 | ) && | |
187 | test_create_commit "$test_count/sub proj" sub2 && | |
188 | ( | |
189 | cd "$test_count" && | |
190 | git fetch ./"sub proj" HEAD && | |
191 | test_wrong_flag git subtree merge --prefix="sub dir" --annotate=foo FETCH_HEAD && | |
192 | test_wrong_flag git subtree merge --prefix="sub dir" --branch=foo FETCH_HEAD && | |
193 | test_wrong_flag git subtree merge --prefix="sub dir" --ignore-joins FETCH_HEAD && | |
194 | test_wrong_flag git subtree merge --prefix="sub dir" --onto=foo FETCH_HEAD && | |
195 | test_wrong_flag git subtree merge --prefix="sub dir" --rejoin FETCH_HEAD | |
196 | ) | |
197 | ' | |
198 | ||
43711746 | 199 | test_expect_success 'merge new subproj history into sub dir/ with --prefix' ' |
f2bb7fef LS |
200 | subtree_test_create_repo "$test_count" && |
201 | subtree_test_create_repo "$test_count/sub proj" && | |
202 | test_create_commit "$test_count" main1 && | |
203 | test_create_commit "$test_count/sub proj" sub1 && | |
43711746 | 204 | ( |
f2bb7fef | 205 | cd "$test_count" && |
914d5125 | 206 | git fetch ./"sub proj" HEAD && |
43711746 TZ |
207 | git subtree add --prefix="sub dir" FETCH_HEAD |
208 | ) && | |
f2bb7fef | 209 | test_create_commit "$test_count/sub proj" sub2 && |
43711746 | 210 | ( |
f2bb7fef | 211 | cd "$test_count" && |
914d5125 | 212 | git fetch ./"sub proj" HEAD && |
43711746 | 213 | git subtree merge --prefix="sub dir" FETCH_HEAD && |
db6952b2 | 214 | test "$(last_commit_subject)" = "Merge commit '\''$(git rev-parse FETCH_HEAD)'\''" |
43711746 | 215 | ) |
d3a04e06 DG |
216 | ' |
217 | ||
43711746 | 218 | test_expect_success 'merge new subproj history into sub dir/ with --prefix and --message' ' |
f2bb7fef LS |
219 | subtree_test_create_repo "$test_count" && |
220 | subtree_test_create_repo "$test_count/sub proj" && | |
221 | test_create_commit "$test_count" main1 && | |
222 | test_create_commit "$test_count/sub proj" sub1 && | |
43711746 | 223 | ( |
f2bb7fef | 224 | cd "$test_count" && |
914d5125 | 225 | git fetch ./"sub proj" HEAD && |
43711746 TZ |
226 | git subtree add --prefix="sub dir" FETCH_HEAD |
227 | ) && | |
f2bb7fef | 228 | test_create_commit "$test_count/sub proj" sub2 && |
43711746 | 229 | ( |
f2bb7fef | 230 | cd "$test_count" && |
914d5125 | 231 | git fetch ./"sub proj" HEAD && |
43711746 | 232 | git subtree merge --prefix="sub dir" --message="Merged changes from subproject" FETCH_HEAD && |
db6952b2 | 233 | test "$(last_commit_subject)" = "Merged changes from subproject" |
43711746 | 234 | ) |
d3a04e06 DG |
235 | ' |
236 | ||
43711746 | 237 | test_expect_success 'merge new subproj history into sub dir/ with --squash and --prefix and --message' ' |
f2bb7fef LS |
238 | subtree_test_create_repo "$test_count/sub proj" && |
239 | subtree_test_create_repo "$test_count" && | |
240 | test_create_commit "$test_count" main1 && | |
241 | test_create_commit "$test_count/sub proj" sub1 && | |
43711746 | 242 | ( |
f2bb7fef | 243 | cd "$test_count" && |
914d5125 | 244 | git fetch ./"sub proj" HEAD && |
43711746 TZ |
245 | git subtree add --prefix="sub dir" FETCH_HEAD |
246 | ) && | |
f2bb7fef | 247 | test_create_commit "$test_count/sub proj" sub2 && |
43711746 | 248 | ( |
f2bb7fef | 249 | cd "$test_count" && |
914d5125 | 250 | git fetch ./"sub proj" HEAD && |
43711746 | 251 | git subtree merge --prefix="sub dir" --message="Merged changes from subproject using squash" --squash FETCH_HEAD && |
db6952b2 | 252 | test "$(last_commit_subject)" = "Merged changes from subproject using squash" |
43711746 | 253 | ) |
d3a04e06 DG |
254 | ' |
255 | ||
43711746 | 256 | test_expect_success 'merge the added subproj again, should do nothing' ' |
f2bb7fef LS |
257 | subtree_test_create_repo "$test_count" && |
258 | subtree_test_create_repo "$test_count/sub proj" && | |
259 | test_create_commit "$test_count" main1 && | |
260 | test_create_commit "$test_count/sub proj" sub1 && | |
43711746 | 261 | ( |
f2bb7fef | 262 | cd "$test_count" && |
914d5125 | 263 | git fetch ./"sub proj" HEAD && |
43711746 TZ |
264 | git subtree add --prefix="sub dir" FETCH_HEAD && |
265 | # this shouldn not actually do anything, since FETCH_HEAD | |
266 | # is already a parent | |
267 | result=$(git merge -s ours -m "merge -s -ours" FETCH_HEAD) && | |
c4566ab4 | 268 | test "${result}" = "Already up to date." |
43711746 | 269 | ) |
4f96fcc9 TZ |
270 | ' |
271 | ||
d16031ca | 272 | test_expect_success 'merge new subproj history into subdir/ with a slash appended to the argument of --prefix' ' |
40b1e1ec LS |
273 | subtree_test_create_repo "$test_count" && |
274 | subtree_test_create_repo "$test_count/subproj" && | |
d16031ca TZ |
275 | test_create_commit "$test_count" main1 && |
276 | test_create_commit "$test_count/subproj" sub1 && | |
277 | ( | |
278 | cd "$test_count" && | |
914d5125 | 279 | git fetch ./subproj HEAD && |
d16031ca TZ |
280 | git subtree add --prefix=subdir/ FETCH_HEAD |
281 | ) && | |
282 | test_create_commit "$test_count/subproj" sub2 && | |
283 | ( | |
284 | cd "$test_count" && | |
914d5125 | 285 | git fetch ./subproj HEAD && |
d16031ca | 286 | git subtree merge --prefix=subdir/ FETCH_HEAD && |
db6952b2 | 287 | test "$(last_commit_subject)" = "Merge commit '\''$(git rev-parse FETCH_HEAD)'\''" |
d16031ca TZ |
288 | ) |
289 | ' | |
290 | ||
0d330673 PB |
291 | test_expect_success 'merge with --squash after annotated tag was added/merged with --squash pre-v2.32.0 ' ' |
292 | test_create_pre2_32_repo "$test_count" && | |
293 | git -C "$test_count-clone" fetch "../$test_count-sub" sub2 && | |
294 | test_must_fail git -C "$test_count-clone" subtree merge --prefix="sub" --squash FETCH_HEAD && | |
295 | git -C "$test_count-clone" subtree merge --prefix="sub" --squash FETCH_HEAD "../$test_count-sub" | |
296 | ' | |
297 | ||
43711746 TZ |
298 | # |
299 | # Tests for 'git subtree split' | |
300 | # | |
4f96fcc9 | 301 | |
b0638aa2 | 302 | test_expect_success 'split requires option --prefix' ' |
f2bb7fef LS |
303 | subtree_test_create_repo "$test_count" && |
304 | subtree_test_create_repo "$test_count/sub proj" && | |
305 | test_create_commit "$test_count" main1 && | |
306 | test_create_commit "$test_count/sub proj" sub1 && | |
43711746 | 307 | ( |
f2bb7fef | 308 | cd "$test_count" && |
914d5125 | 309 | git fetch ./"sub proj" HEAD && |
43711746 | 310 | git subtree add --prefix="sub dir" FETCH_HEAD && |
5626a9e2 | 311 | echo "fatal: you must provide the --prefix option." >expected && |
f7004069 | 312 | test_must_fail git subtree split >actual 2>&1 && |
43711746 TZ |
313 | test_debug "printf '"expected: "'" && |
314 | test_debug "cat expected" && | |
315 | test_debug "printf '"actual: "'" && | |
316 | test_debug "cat actual" && | |
317 | test_cmp expected actual | |
318 | ) | |
d3a04e06 DG |
319 | ' |
320 | ||
b0638aa2 | 321 | test_expect_success 'split requires path given by option --prefix must exist' ' |
f2bb7fef LS |
322 | subtree_test_create_repo "$test_count" && |
323 | subtree_test_create_repo "$test_count/sub proj" && | |
324 | test_create_commit "$test_count" main1 && | |
325 | test_create_commit "$test_count/sub proj" sub1 && | |
43711746 | 326 | ( |
f2bb7fef | 327 | cd "$test_count" && |
914d5125 | 328 | git fetch ./"sub proj" HEAD && |
43711746 | 329 | git subtree add --prefix="sub dir" FETCH_HEAD && |
5626a9e2 | 330 | echo "fatal: '\''non-existent-directory'\'' does not exist; use '\''git subtree add'\''" >expected && |
f7004069 | 331 | test_must_fail git subtree split --prefix=non-existent-directory >actual 2>&1 && |
43711746 TZ |
332 | test_debug "printf '"expected: "'" && |
333 | test_debug "cat expected" && | |
334 | test_debug "printf '"actual: "'" && | |
335 | test_debug "cat actual" && | |
336 | test_cmp expected actual | |
337 | ) | |
d3a04e06 DG |
338 | ' |
339 | ||
9a3e3ca2 LS |
340 | test_expect_success 'split rejects flags for add' ' |
341 | subtree_test_create_repo "$test_count" && | |
342 | subtree_test_create_repo "$test_count/sub proj" && | |
343 | test_create_commit "$test_count" main1 && | |
344 | test_create_commit "$test_count/sub proj" sub1 && | |
345 | ( | |
346 | cd "$test_count" && | |
347 | git fetch ./"sub proj" HEAD && | |
348 | git subtree add --prefix="sub dir" FETCH_HEAD | |
349 | ) && | |
350 | test_create_commit "$test_count" "sub dir"/main-sub1 && | |
351 | test_create_commit "$test_count" main2 && | |
352 | test_create_commit "$test_count/sub proj" sub2 && | |
353 | test_create_commit "$test_count" "sub dir"/main-sub2 && | |
354 | ( | |
355 | cd "$test_count" && | |
356 | git fetch ./"sub proj" HEAD && | |
357 | git subtree merge --prefix="sub dir" FETCH_HEAD && | |
358 | split_hash=$(git subtree split --prefix="sub dir" --annotate="*") && | |
359 | test_wrong_flag git subtree split --prefix="sub dir" --squash && | |
360 | test_wrong_flag git subtree split --prefix="sub dir" --message=foo | |
361 | ) | |
362 | ' | |
363 | ||
4fe2e33c | 364 | test_expect_success 'split sub dir/ with --rejoin' ' |
f2bb7fef LS |
365 | subtree_test_create_repo "$test_count" && |
366 | subtree_test_create_repo "$test_count/sub proj" && | |
367 | test_create_commit "$test_count" main1 && | |
368 | test_create_commit "$test_count/sub proj" sub1 && | |
43711746 | 369 | ( |
f2bb7fef | 370 | cd "$test_count" && |
914d5125 | 371 | git fetch ./"sub proj" HEAD && |
43711746 TZ |
372 | git subtree add --prefix="sub dir" FETCH_HEAD |
373 | ) && | |
f2bb7fef LS |
374 | test_create_commit "$test_count" "sub dir"/main-sub1 && |
375 | test_create_commit "$test_count" main2 && | |
376 | test_create_commit "$test_count/sub proj" sub2 && | |
377 | test_create_commit "$test_count" "sub dir"/main-sub2 && | |
43711746 | 378 | ( |
f2bb7fef | 379 | cd "$test_count" && |
914d5125 | 380 | git fetch ./"sub proj" HEAD && |
43711746 TZ |
381 | git subtree merge --prefix="sub dir" FETCH_HEAD && |
382 | split_hash=$(git subtree split --prefix="sub dir" --annotate="*") && | |
383 | git subtree split --prefix="sub dir" --annotate="*" --rejoin && | |
db6952b2 | 384 | test "$(last_commit_subject)" = "Split '\''sub dir/'\'' into commit '\''$split_hash'\''" |
43711746 | 385 | ) |
f7004069 | 386 | ' |
4fe2e33c | 387 | |
98ba49cc ZF |
388 | # Tests that commits from other subtrees are not processed as |
389 | # part of a split. | |
390 | # | |
391 | # This test performs the following: | |
392 | # - Creates Repo with subtrees 'subA' and 'subB' | |
393 | # - Creates commits in the repo including changes to subtrees | |
394 | # - Runs the following 'split' and commit' commands in order: | |
395 | # - Perform 'split' on subtree A | |
396 | # - Perform 'split' on subtree B | |
397 | # - Create new commits with changes to subtree A and B | |
398 | # - Perform split on subtree A | |
399 | # - Check that the commits in subtree B are not processed | |
400 | # as part of the subtree A split | |
401 | test_expect_success 'split with multiple subtrees' ' | |
402 | subtree_test_create_repo "$test_count" && | |
403 | subtree_test_create_repo "$test_count/subA" && | |
404 | subtree_test_create_repo "$test_count/subB" && | |
405 | test_create_commit "$test_count" main1 && | |
406 | test_create_commit "$test_count/subA" subA1 && | |
407 | test_create_commit "$test_count/subA" subA2 && | |
408 | test_create_commit "$test_count/subA" subA3 && | |
409 | test_create_commit "$test_count/subB" subB1 && | |
410 | git -C "$test_count" fetch ./subA HEAD && | |
411 | git -C "$test_count" subtree add --prefix=subADir FETCH_HEAD && | |
412 | git -C "$test_count" fetch ./subB HEAD && | |
413 | git -C "$test_count" subtree add --prefix=subBDir FETCH_HEAD && | |
414 | test_create_commit "$test_count" subADir/main-subA1 && | |
415 | test_create_commit "$test_count" subBDir/main-subB1 && | |
416 | git -C "$test_count" subtree split --prefix=subADir \ | |
417 | --squash --rejoin -m "Sub A Split 1" && | |
418 | git -C "$test_count" subtree split --prefix=subBDir \ | |
419 | --squash --rejoin -m "Sub B Split 1" && | |
420 | test_create_commit "$test_count" subADir/main-subA2 && | |
421 | test_create_commit "$test_count" subBDir/main-subB2 && | |
422 | git -C "$test_count" subtree split --prefix=subADir \ | |
423 | --squash --rejoin -m "Sub A Split 2" && | |
424 | test "$(git -C "$test_count" subtree split --prefix=subBDir \ | |
425 | --squash --rejoin -d -m "Sub B Split 1" 2>&1 | grep -w "\[1\]")" = "" | |
426 | ' | |
427 | ||
0f12c7d4 | 428 | test_expect_success 'split sub dir/ with --rejoin from scratch' ' |
f2bb7fef LS |
429 | subtree_test_create_repo "$test_count" && |
430 | test_create_commit "$test_count" main1 && | |
0f12c7d4 | 431 | ( |
f2bb7fef | 432 | cd "$test_count" && |
0f12c7d4 DA |
433 | mkdir "sub dir" && |
434 | echo file >"sub dir"/file && | |
435 | git add "sub dir/file" && | |
436 | git commit -m"sub dir file" && | |
437 | split_hash=$(git subtree split --prefix="sub dir" --rejoin) && | |
438 | git subtree split --prefix="sub dir" --rejoin && | |
db6952b2 | 439 | test "$(last_commit_subject)" = "Split '\''sub dir/'\'' into commit '\''$split_hash'\''" |
0f12c7d4 | 440 | ) |
f7004069 | 441 | ' |
0f12c7d4 | 442 | |
4fe2e33c | 443 | test_expect_success 'split sub dir/ with --rejoin and --message' ' |
f2bb7fef LS |
444 | subtree_test_create_repo "$test_count" && |
445 | subtree_test_create_repo "$test_count/sub proj" && | |
446 | test_create_commit "$test_count" main1 && | |
447 | test_create_commit "$test_count/sub proj" sub1 && | |
43711746 | 448 | ( |
f2bb7fef | 449 | cd "$test_count" && |
914d5125 | 450 | git fetch ./"sub proj" HEAD && |
43711746 TZ |
451 | git subtree add --prefix="sub dir" FETCH_HEAD |
452 | ) && | |
f2bb7fef LS |
453 | test_create_commit "$test_count" "sub dir"/main-sub1 && |
454 | test_create_commit "$test_count" main2 && | |
455 | test_create_commit "$test_count/sub proj" sub2 && | |
456 | test_create_commit "$test_count" "sub dir"/main-sub2 && | |
43711746 | 457 | ( |
f2bb7fef | 458 | cd "$test_count" && |
914d5125 | 459 | git fetch ./"sub proj" HEAD && |
43711746 TZ |
460 | git subtree merge --prefix="sub dir" FETCH_HEAD && |
461 | git subtree split --prefix="sub dir" --message="Split & rejoin" --annotate="*" --rejoin && | |
db6952b2 | 462 | test "$(last_commit_subject)" = "Split & rejoin" |
43711746 | 463 | ) |
d3a04e06 DG |
464 | ' |
465 | ||
cb655144 LS |
466 | test_expect_success 'split "sub dir"/ with --rejoin and --squash' ' |
467 | subtree_test_create_repo "$test_count" && | |
468 | subtree_test_create_repo "$test_count/sub proj" && | |
469 | test_create_commit "$test_count" main1 && | |
470 | test_create_commit "$test_count/sub proj" sub1 && | |
471 | ( | |
472 | cd "$test_count" && | |
473 | git fetch ./"sub proj" HEAD && | |
474 | git subtree add --prefix="sub dir" --squash FETCH_HEAD | |
475 | ) && | |
476 | test_create_commit "$test_count" "sub dir"/main-sub1 && | |
477 | test_create_commit "$test_count" main2 && | |
478 | test_create_commit "$test_count/sub proj" sub2 && | |
479 | test_create_commit "$test_count" "sub dir"/main-sub2 && | |
480 | ( | |
481 | cd "$test_count" && | |
482 | git subtree pull --prefix="sub dir" --squash ./"sub proj" HEAD && | |
483 | MAIN=$(git rev-parse --verify HEAD) && | |
484 | SUB=$(git -C "sub proj" rev-parse --verify HEAD) && | |
485 | ||
486 | SPLIT=$(git subtree split --prefix="sub dir" --annotate="*" --rejoin --squash) && | |
487 | ||
488 | test_must_fail git merge-base --is-ancestor $SUB HEAD && | |
489 | test_must_fail git merge-base --is-ancestor $SPLIT HEAD && | |
490 | git rev-list HEAD ^$MAIN >commit-list && | |
491 | test_line_count = 2 commit-list && | |
492 | test "$(git rev-parse --verify HEAD:)" = "$(git rev-parse --verify $MAIN:)" && | |
493 | test "$(git rev-parse --verify HEAD:"sub dir")" = "$(git rev-parse --verify $SPLIT:)" && | |
494 | test "$(git rev-parse --verify HEAD^1)" = $MAIN && | |
495 | test "$(git rev-parse --verify HEAD^2)" != $SPLIT && | |
496 | test "$(git rev-parse --verify HEAD^2:)" = "$(git rev-parse --verify $SPLIT:)" && | |
497 | test "$(last_commit_subject)" = "Split '\''sub dir/'\'' into commit '\''$SPLIT'\''" | |
498 | ) | |
499 | ' | |
500 | ||
501 | test_expect_success 'split then pull "sub dir"/ with --rejoin and --squash' ' | |
502 | # 1. "add" | |
503 | subtree_test_create_repo "$test_count" && | |
504 | subtree_test_create_repo "$test_count/sub proj" && | |
505 | test_create_commit "$test_count" main1 && | |
506 | test_create_commit "$test_count/sub proj" sub1 && | |
507 | git -C "$test_count" subtree --prefix="sub dir" add --squash ./"sub proj" HEAD && | |
508 | ||
509 | # 2. commit from parent | |
510 | test_create_commit "$test_count" "sub dir"/main-sub1 && | |
511 | ||
512 | # 3. "split --rejoin --squash" | |
513 | git -C "$test_count" subtree --prefix="sub dir" split --rejoin --squash && | |
514 | ||
515 | # 4. "pull --squash" | |
516 | test_create_commit "$test_count/sub proj" sub2 && | |
517 | git -C "$test_count" subtree -d --prefix="sub dir" pull --squash ./"sub proj" HEAD && | |
518 | ||
519 | test_must_fail git merge-base HEAD FETCH_HEAD | |
520 | ' | |
521 | ||
43711746 | 522 | test_expect_success 'split "sub dir"/ with --branch' ' |
f2bb7fef LS |
523 | subtree_test_create_repo "$test_count" && |
524 | subtree_test_create_repo "$test_count/sub proj" && | |
525 | test_create_commit "$test_count" main1 && | |
526 | test_create_commit "$test_count/sub proj" sub1 && | |
43711746 | 527 | ( |
f2bb7fef | 528 | cd "$test_count" && |
914d5125 | 529 | git fetch ./"sub proj" HEAD && |
43711746 TZ |
530 | git subtree add --prefix="sub dir" FETCH_HEAD |
531 | ) && | |
f2bb7fef LS |
532 | test_create_commit "$test_count" "sub dir"/main-sub1 && |
533 | test_create_commit "$test_count" main2 && | |
534 | test_create_commit "$test_count/sub proj" sub2 && | |
535 | test_create_commit "$test_count" "sub dir"/main-sub2 && | |
43711746 | 536 | ( |
f2bb7fef | 537 | cd "$test_count" && |
914d5125 | 538 | git fetch ./"sub proj" HEAD && |
43711746 TZ |
539 | git subtree merge --prefix="sub dir" FETCH_HEAD && |
540 | split_hash=$(git subtree split --prefix="sub dir" --annotate="*") && | |
541 | git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br && | |
c4566ab4 | 542 | test "$(git rev-parse subproj-br)" = "$split_hash" |
43711746 | 543 | ) |
d3a04e06 DG |
544 | ' |
545 | ||
43711746 | 546 | test_expect_success 'check hash of split' ' |
f2bb7fef LS |
547 | subtree_test_create_repo "$test_count" && |
548 | subtree_test_create_repo "$test_count/sub proj" && | |
549 | test_create_commit "$test_count" main1 && | |
550 | test_create_commit "$test_count/sub proj" sub1 && | |
43711746 | 551 | ( |
f2bb7fef | 552 | cd "$test_count" && |
914d5125 | 553 | git fetch ./"sub proj" HEAD && |
43711746 TZ |
554 | git subtree add --prefix="sub dir" FETCH_HEAD |
555 | ) && | |
f2bb7fef LS |
556 | test_create_commit "$test_count" "sub dir"/main-sub1 && |
557 | test_create_commit "$test_count" main2 && | |
558 | test_create_commit "$test_count/sub proj" sub2 && | |
559 | test_create_commit "$test_count" "sub dir"/main-sub2 && | |
43711746 | 560 | ( |
f2bb7fef | 561 | cd "$test_count" && |
914d5125 | 562 | git fetch ./"sub proj" HEAD && |
43711746 TZ |
563 | git subtree merge --prefix="sub dir" FETCH_HEAD && |
564 | split_hash=$(git subtree split --prefix="sub dir" --annotate="*") && | |
565 | git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br && | |
c4566ab4 | 566 | test "$(git rev-parse subproj-br)" = "$split_hash" && |
43711746 TZ |
567 | # Check hash of split |
568 | new_hash=$(git rev-parse subproj-br^2) && | |
569 | ( | |
570 | cd ./"sub proj" && | |
571 | subdir_hash=$(git rev-parse HEAD) && | |
63ac4f1a | 572 | test "$new_hash" = "$subdir_hash" |
43711746 TZ |
573 | ) |
574 | ) | |
d3a04e06 DG |
575 | ' |
576 | ||
43711746 | 577 | test_expect_success 'split "sub dir"/ with --branch for an existing branch' ' |
f2bb7fef LS |
578 | subtree_test_create_repo "$test_count" && |
579 | subtree_test_create_repo "$test_count/sub proj" && | |
580 | test_create_commit "$test_count" main1 && | |
581 | test_create_commit "$test_count/sub proj" sub1 && | |
43711746 | 582 | ( |
f2bb7fef | 583 | cd "$test_count" && |
914d5125 | 584 | git fetch ./"sub proj" HEAD && |
43711746 TZ |
585 | git branch subproj-br FETCH_HEAD && |
586 | git subtree add --prefix="sub dir" FETCH_HEAD | |
587 | ) && | |
f2bb7fef LS |
588 | test_create_commit "$test_count" "sub dir"/main-sub1 && |
589 | test_create_commit "$test_count" main2 && | |
590 | test_create_commit "$test_count/sub proj" sub2 && | |
591 | test_create_commit "$test_count" "sub dir"/main-sub2 && | |
43711746 | 592 | ( |
f2bb7fef | 593 | cd "$test_count" && |
914d5125 | 594 | git fetch ./"sub proj" HEAD && |
43711746 TZ |
595 | git subtree merge --prefix="sub dir" FETCH_HEAD && |
596 | split_hash=$(git subtree split --prefix="sub dir" --annotate="*") && | |
597 | git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br && | |
c4566ab4 | 598 | test "$(git rev-parse subproj-br)" = "$split_hash" |
43711746 | 599 | ) |
d3a04e06 DG |
600 | ' |
601 | ||
43711746 | 602 | test_expect_success 'split "sub dir"/ with --branch for an incompatible branch' ' |
f2bb7fef LS |
603 | subtree_test_create_repo "$test_count" && |
604 | subtree_test_create_repo "$test_count/sub proj" && | |
605 | test_create_commit "$test_count" main1 && | |
606 | test_create_commit "$test_count/sub proj" sub1 && | |
43711746 | 607 | ( |
f2bb7fef | 608 | cd "$test_count" && |
43711746 | 609 | git branch init HEAD && |
914d5125 | 610 | git fetch ./"sub proj" HEAD && |
43711746 TZ |
611 | git subtree add --prefix="sub dir" FETCH_HEAD |
612 | ) && | |
f2bb7fef LS |
613 | test_create_commit "$test_count" "sub dir"/main-sub1 && |
614 | test_create_commit "$test_count" main2 && | |
615 | test_create_commit "$test_count/sub proj" sub2 && | |
616 | test_create_commit "$test_count" "sub dir"/main-sub2 && | |
43711746 | 617 | ( |
f2bb7fef | 618 | cd "$test_count" && |
914d5125 | 619 | git fetch ./"sub proj" HEAD && |
43711746 TZ |
620 | git subtree merge --prefix="sub dir" FETCH_HEAD && |
621 | test_must_fail git subtree split --prefix="sub dir" --branch init | |
622 | ) | |
d3a04e06 | 623 | ' |
847e8681 | 624 | |
1762382a PB |
625 | test_expect_success 'split after annotated tag was added/merged with --squash pre-v2.32.0' ' |
626 | test_create_pre2_32_repo "$test_count" && | |
627 | test_must_fail git -C "$test_count-clone" subtree split --prefix="sub" HEAD && | |
628 | git -C "$test_count-clone" subtree split --prefix="sub" HEAD "../$test_count-sub" | |
629 | ' | |
630 | ||
b04538d9 LS |
631 | # |
632 | # Tests for 'git subtree pull' | |
633 | # | |
634 | ||
635 | test_expect_success 'pull requires option --prefix' ' | |
636 | subtree_test_create_repo "$test_count" && | |
637 | subtree_test_create_repo "$test_count/sub proj" && | |
638 | test_create_commit "$test_count" main1 && | |
639 | test_create_commit "$test_count/sub proj" sub1 && | |
640 | ( | |
641 | cd "$test_count" && | |
642 | git fetch ./"sub proj" HEAD && | |
643 | git subtree add --prefix="sub dir" FETCH_HEAD | |
644 | ) && | |
645 | test_create_commit "$test_count/sub proj" sub2 && | |
646 | ( | |
647 | cd "$test_count" && | |
648 | test_must_fail git subtree pull ./"sub proj" HEAD >out 2>err && | |
649 | ||
5626a9e2 | 650 | echo "fatal: you must provide the --prefix option." >expected && |
b04538d9 LS |
651 | test_must_be_empty out && |
652 | test_cmp expected err | |
653 | ) | |
654 | ' | |
655 | ||
656 | test_expect_success 'pull requires path given by option --prefix must exist' ' | |
657 | subtree_test_create_repo "$test_count" && | |
658 | subtree_test_create_repo "$test_count/sub proj" && | |
659 | test_create_commit "$test_count" main1 && | |
660 | test_create_commit "$test_count/sub proj" sub1 && | |
661 | ( | |
662 | test_must_fail git subtree pull --prefix="sub dir" ./"sub proj" HEAD >out 2>err && | |
663 | ||
5626a9e2 | 664 | echo "fatal: '\''sub dir'\'' does not exist; use '\''git subtree add'\''" >expected && |
b04538d9 LS |
665 | test_must_be_empty out && |
666 | test_cmp expected err | |
667 | ) | |
668 | ' | |
669 | ||
670 | test_expect_success 'pull basic operation' ' | |
671 | subtree_test_create_repo "$test_count" && | |
672 | subtree_test_create_repo "$test_count/sub proj" && | |
673 | test_create_commit "$test_count" main1 && | |
674 | test_create_commit "$test_count/sub proj" sub1 && | |
675 | ( | |
676 | cd "$test_count" && | |
677 | git fetch ./"sub proj" HEAD && | |
678 | git subtree add --prefix="sub dir" FETCH_HEAD | |
679 | ) && | |
680 | test_create_commit "$test_count/sub proj" sub2 && | |
681 | ( | |
682 | cd "$test_count" && | |
683 | exp=$(git -C "sub proj" rev-parse --verify HEAD:) && | |
684 | git subtree pull --prefix="sub dir" ./"sub proj" HEAD && | |
685 | act=$(git rev-parse --verify HEAD:"sub dir") && | |
686 | test "$act" = "$exp" | |
687 | ) | |
688 | ' | |
689 | ||
9a3e3ca2 LS |
690 | test_expect_success 'pull rejects flags for split' ' |
691 | subtree_test_create_repo "$test_count" && | |
692 | subtree_test_create_repo "$test_count/sub proj" && | |
693 | test_create_commit "$test_count" main1 && | |
694 | test_create_commit "$test_count/sub proj" sub1 && | |
695 | ( | |
696 | cd "$test_count" && | |
697 | git fetch ./"sub proj" HEAD && | |
698 | git subtree add --prefix="sub dir" FETCH_HEAD | |
699 | ) && | |
700 | test_create_commit "$test_count/sub proj" sub2 && | |
701 | ( | |
702 | test_must_fail git subtree pull --prefix="sub dir" --annotate=foo ./"sub proj" HEAD && | |
703 | test_must_fail git subtree pull --prefix="sub dir" --branch=foo ./"sub proj" HEAD && | |
704 | test_must_fail git subtree pull --prefix="sub dir" --ignore-joins ./"sub proj" HEAD && | |
705 | test_must_fail git subtree pull --prefix="sub dir" --onto=foo ./"sub proj" HEAD && | |
706 | test_must_fail git subtree pull --prefix="sub dir" --rejoin ./"sub proj" HEAD | |
707 | ) | |
708 | ' | |
709 | ||
0d330673 PB |
710 | test_expect_success 'pull with --squash after annotated tag was added/merged with --squash pre-v2.32.0 ' ' |
711 | test_create_pre2_32_repo "$test_count" && | |
712 | git -C "$test_count-clone" subtree -d pull --prefix="sub" --squash "../$test_count-sub" sub2 | |
713 | ' | |
714 | ||
b04538d9 LS |
715 | # |
716 | # Tests for 'git subtree push' | |
717 | # | |
718 | ||
719 | test_expect_success 'push requires option --prefix' ' | |
720 | subtree_test_create_repo "$test_count" && | |
721 | subtree_test_create_repo "$test_count/sub proj" && | |
722 | test_create_commit "$test_count" main1 && | |
723 | test_create_commit "$test_count/sub proj" sub1 && | |
724 | ( | |
725 | cd "$test_count" && | |
726 | git fetch ./"sub proj" HEAD && | |
727 | git subtree add --prefix="sub dir" FETCH_HEAD && | |
5626a9e2 | 728 | echo "fatal: you must provide the --prefix option." >expected && |
b04538d9 LS |
729 | test_must_fail git subtree push "./sub proj" from-mainline >actual 2>&1 && |
730 | test_debug "printf '"expected: "'" && | |
731 | test_debug "cat expected" && | |
732 | test_debug "printf '"actual: "'" && | |
733 | test_debug "cat actual" && | |
734 | test_cmp expected actual | |
735 | ) | |
736 | ' | |
737 | ||
738 | test_expect_success 'push requires path given by option --prefix must exist' ' | |
739 | subtree_test_create_repo "$test_count" && | |
740 | subtree_test_create_repo "$test_count/sub proj" && | |
741 | test_create_commit "$test_count" main1 && | |
742 | test_create_commit "$test_count/sub proj" sub1 && | |
743 | ( | |
744 | cd "$test_count" && | |
745 | git fetch ./"sub proj" HEAD && | |
746 | git subtree add --prefix="sub dir" FETCH_HEAD && | |
5626a9e2 | 747 | echo "fatal: '\''non-existent-directory'\'' does not exist; use '\''git subtree add'\''" >expected && |
b04538d9 LS |
748 | test_must_fail git subtree push --prefix=non-existent-directory "./sub proj" from-mainline >actual 2>&1 && |
749 | test_debug "printf '"expected: "'" && | |
750 | test_debug "cat expected" && | |
751 | test_debug "printf '"actual: "'" && | |
752 | test_debug "cat actual" && | |
753 | test_cmp expected actual | |
754 | ) | |
755 | ' | |
756 | ||
9a3e3ca2 LS |
757 | test_expect_success 'push rejects flags for add' ' |
758 | subtree_test_create_repo "$test_count" && | |
759 | subtree_test_create_repo "$test_count/sub proj" && | |
760 | test_create_commit "$test_count" main1 && | |
761 | test_create_commit "$test_count/sub proj" sub1 && | |
762 | ( | |
763 | cd "$test_count" && | |
764 | git fetch ./"sub proj" HEAD && | |
765 | git subtree add --prefix="sub dir" FETCH_HEAD | |
766 | ) && | |
767 | test_create_commit "$test_count" "sub dir"/main-sub1 && | |
768 | test_create_commit "$test_count" main2 && | |
769 | test_create_commit "$test_count/sub proj" sub2 && | |
770 | test_create_commit "$test_count" "sub dir"/main-sub2 && | |
771 | ( | |
772 | cd "$test_count" && | |
773 | git fetch ./"sub proj" HEAD && | |
774 | git subtree merge --prefix="sub dir" FETCH_HEAD && | |
775 | test_wrong_flag git subtree split --prefix="sub dir" --squash ./"sub proj" from-mainline && | |
776 | test_wrong_flag git subtree split --prefix="sub dir" --message=foo ./"sub proj" from-mainline | |
777 | ) | |
778 | ' | |
779 | ||
b04538d9 LS |
780 | test_expect_success 'push basic operation' ' |
781 | subtree_test_create_repo "$test_count" && | |
782 | subtree_test_create_repo "$test_count/sub proj" && | |
783 | test_create_commit "$test_count" main1 && | |
784 | test_create_commit "$test_count/sub proj" sub1 && | |
785 | ( | |
786 | cd "$test_count" && | |
787 | git fetch ./"sub proj" HEAD && | |
788 | git subtree add --prefix="sub dir" FETCH_HEAD | |
789 | ) && | |
790 | test_create_commit "$test_count" "sub dir"/main-sub1 && | |
791 | test_create_commit "$test_count" main2 && | |
792 | test_create_commit "$test_count/sub proj" sub2 && | |
793 | test_create_commit "$test_count" "sub dir"/main-sub2 && | |
794 | ( | |
795 | cd "$test_count" && | |
796 | git fetch ./"sub proj" HEAD && | |
797 | git subtree merge --prefix="sub dir" FETCH_HEAD && | |
798 | before=$(git rev-parse --verify HEAD) && | |
799 | split_hash=$(git subtree split --prefix="sub dir") && | |
800 | git subtree push --prefix="sub dir" ./"sub proj" from-mainline && | |
801 | test "$before" = "$(git rev-parse --verify HEAD)" && | |
802 | test "$split_hash" = "$(git -C "sub proj" rev-parse --verify refs/heads/from-mainline)" | |
803 | ) | |
804 | ' | |
805 | ||
94389e7c LS |
806 | test_expect_success 'push sub dir/ with --rejoin' ' |
807 | subtree_test_create_repo "$test_count" && | |
808 | subtree_test_create_repo "$test_count/sub proj" && | |
809 | test_create_commit "$test_count" main1 && | |
810 | test_create_commit "$test_count/sub proj" sub1 && | |
811 | ( | |
812 | cd "$test_count" && | |
813 | git fetch ./"sub proj" HEAD && | |
814 | git subtree add --prefix="sub dir" FETCH_HEAD | |
815 | ) && | |
816 | test_create_commit "$test_count" "sub dir"/main-sub1 && | |
817 | test_create_commit "$test_count" main2 && | |
818 | test_create_commit "$test_count/sub proj" sub2 && | |
819 | test_create_commit "$test_count" "sub dir"/main-sub2 && | |
820 | ( | |
821 | cd "$test_count" && | |
822 | git fetch ./"sub proj" HEAD && | |
823 | git subtree merge --prefix="sub dir" FETCH_HEAD && | |
824 | split_hash=$(git subtree split --prefix="sub dir" --annotate="*") && | |
825 | git subtree push --prefix="sub dir" --annotate="*" --rejoin ./"sub proj" from-mainline && | |
826 | test "$(last_commit_subject)" = "Split '\''sub dir/'\'' into commit '\''$split_hash'\''" && | |
827 | test "$split_hash" = "$(git -C "sub proj" rev-parse --verify refs/heads/from-mainline)" | |
828 | ) | |
829 | ' | |
830 | ||
831 | test_expect_success 'push sub dir/ with --rejoin from scratch' ' | |
832 | subtree_test_create_repo "$test_count" && | |
833 | test_create_commit "$test_count" main1 && | |
834 | ( | |
835 | cd "$test_count" && | |
836 | mkdir "sub dir" && | |
837 | echo file >"sub dir"/file && | |
838 | git add "sub dir/file" && | |
839 | git commit -m"sub dir file" && | |
840 | split_hash=$(git subtree split --prefix="sub dir" --rejoin) && | |
841 | git init --bare "sub proj.git" && | |
842 | git subtree push --prefix="sub dir" --rejoin ./"sub proj.git" from-mainline && | |
843 | test "$(last_commit_subject)" = "Split '\''sub dir/'\'' into commit '\''$split_hash'\''" && | |
844 | test "$split_hash" = "$(git -C "sub proj.git" rev-parse --verify refs/heads/from-mainline)" | |
845 | ) | |
846 | ' | |
847 | ||
848 | test_expect_success 'push sub dir/ with --rejoin and --message' ' | |
849 | subtree_test_create_repo "$test_count" && | |
850 | subtree_test_create_repo "$test_count/sub proj" && | |
851 | test_create_commit "$test_count" main1 && | |
852 | test_create_commit "$test_count/sub proj" sub1 && | |
853 | ( | |
854 | cd "$test_count" && | |
855 | git fetch ./"sub proj" HEAD && | |
856 | git subtree add --prefix="sub dir" FETCH_HEAD | |
857 | ) && | |
858 | test_create_commit "$test_count" "sub dir"/main-sub1 && | |
859 | test_create_commit "$test_count" main2 && | |
860 | test_create_commit "$test_count/sub proj" sub2 && | |
861 | test_create_commit "$test_count" "sub dir"/main-sub2 && | |
862 | ( | |
863 | cd "$test_count" && | |
864 | git fetch ./"sub proj" HEAD && | |
865 | git subtree merge --prefix="sub dir" FETCH_HEAD && | |
866 | git subtree push --prefix="sub dir" --message="Split & rejoin" --annotate="*" --rejoin ./"sub proj" from-mainline && | |
867 | test "$(last_commit_subject)" = "Split & rejoin" && | |
868 | split_hash="$(git rev-parse --verify HEAD^2)" && | |
869 | test "$split_hash" = "$(git -C "sub proj" rev-parse --verify refs/heads/from-mainline)" | |
870 | ) | |
871 | ' | |
872 | ||
873 | test_expect_success 'push "sub dir"/ with --rejoin and --squash' ' | |
874 | subtree_test_create_repo "$test_count" && | |
875 | subtree_test_create_repo "$test_count/sub proj" && | |
876 | test_create_commit "$test_count" main1 && | |
877 | test_create_commit "$test_count/sub proj" sub1 && | |
878 | ( | |
879 | cd "$test_count" && | |
880 | git fetch ./"sub proj" HEAD && | |
881 | git subtree add --prefix="sub dir" --squash FETCH_HEAD | |
882 | ) && | |
883 | test_create_commit "$test_count" "sub dir"/main-sub1 && | |
884 | test_create_commit "$test_count" main2 && | |
885 | test_create_commit "$test_count/sub proj" sub2 && | |
886 | test_create_commit "$test_count" "sub dir"/main-sub2 && | |
887 | ( | |
888 | cd "$test_count" && | |
889 | git subtree pull --prefix="sub dir" --squash ./"sub proj" HEAD && | |
890 | MAIN=$(git rev-parse --verify HEAD) && | |
891 | SUB=$(git -C "sub proj" rev-parse --verify HEAD) && | |
892 | ||
893 | SPLIT=$(git subtree split --prefix="sub dir" --annotate="*") && | |
894 | git subtree push --prefix="sub dir" --annotate="*" --rejoin --squash ./"sub proj" from-mainline && | |
895 | ||
896 | test_must_fail git merge-base --is-ancestor $SUB HEAD && | |
897 | test_must_fail git merge-base --is-ancestor $SPLIT HEAD && | |
898 | git rev-list HEAD ^$MAIN >commit-list && | |
899 | test_line_count = 2 commit-list && | |
900 | test "$(git rev-parse --verify HEAD:)" = "$(git rev-parse --verify $MAIN:)" && | |
901 | test "$(git rev-parse --verify HEAD:"sub dir")" = "$(git rev-parse --verify $SPLIT:)" && | |
902 | test "$(git rev-parse --verify HEAD^1)" = $MAIN && | |
903 | test "$(git rev-parse --verify HEAD^2)" != $SPLIT && | |
904 | test "$(git rev-parse --verify HEAD^2:)" = "$(git rev-parse --verify $SPLIT:)" && | |
905 | test "$(last_commit_subject)" = "Split '\''sub dir/'\'' into commit '\''$SPLIT'\''" && | |
906 | test "$SPLIT" = "$(git -C "sub proj" rev-parse --verify refs/heads/from-mainline)" | |
907 | ) | |
908 | ' | |
909 | ||
910 | test_expect_success 'push "sub dir"/ with --branch' ' | |
911 | subtree_test_create_repo "$test_count" && | |
912 | subtree_test_create_repo "$test_count/sub proj" && | |
913 | test_create_commit "$test_count" main1 && | |
914 | test_create_commit "$test_count/sub proj" sub1 && | |
915 | ( | |
916 | cd "$test_count" && | |
917 | git fetch ./"sub proj" HEAD && | |
918 | git subtree add --prefix="sub dir" FETCH_HEAD | |
919 | ) && | |
920 | test_create_commit "$test_count" "sub dir"/main-sub1 && | |
921 | test_create_commit "$test_count" main2 && | |
922 | test_create_commit "$test_count/sub proj" sub2 && | |
923 | test_create_commit "$test_count" "sub dir"/main-sub2 && | |
924 | ( | |
925 | cd "$test_count" && | |
926 | git fetch ./"sub proj" HEAD && | |
927 | git subtree merge --prefix="sub dir" FETCH_HEAD && | |
928 | split_hash=$(git subtree split --prefix="sub dir" --annotate="*") && | |
929 | git subtree push --prefix="sub dir" --annotate="*" --branch subproj-br ./"sub proj" from-mainline && | |
930 | test "$(git rev-parse subproj-br)" = "$split_hash" && | |
931 | test "$split_hash" = "$(git -C "sub proj" rev-parse --verify refs/heads/from-mainline)" | |
932 | ) | |
933 | ' | |
934 | ||
935 | test_expect_success 'check hash of push' ' | |
936 | subtree_test_create_repo "$test_count" && | |
937 | subtree_test_create_repo "$test_count/sub proj" && | |
938 | test_create_commit "$test_count" main1 && | |
939 | test_create_commit "$test_count/sub proj" sub1 && | |
940 | ( | |
941 | cd "$test_count" && | |
942 | git fetch ./"sub proj" HEAD && | |
943 | git subtree add --prefix="sub dir" FETCH_HEAD | |
944 | ) && | |
945 | test_create_commit "$test_count" "sub dir"/main-sub1 && | |
946 | test_create_commit "$test_count" main2 && | |
947 | test_create_commit "$test_count/sub proj" sub2 && | |
948 | test_create_commit "$test_count" "sub dir"/main-sub2 && | |
949 | ( | |
950 | cd "$test_count" && | |
951 | git fetch ./"sub proj" HEAD && | |
952 | git subtree merge --prefix="sub dir" FETCH_HEAD && | |
953 | split_hash=$(git subtree split --prefix="sub dir" --annotate="*") && | |
954 | git subtree push --prefix="sub dir" --annotate="*" --branch subproj-br ./"sub proj" from-mainline && | |
955 | test "$(git rev-parse subproj-br)" = "$split_hash" && | |
956 | # Check hash of split | |
957 | new_hash=$(git rev-parse subproj-br^2) && | |
958 | ( | |
959 | cd ./"sub proj" && | |
960 | subdir_hash=$(git rev-parse HEAD) && | |
961 | test "$new_hash" = "$subdir_hash" | |
962 | ) && | |
963 | test "$split_hash" = "$(git -C "sub proj" rev-parse --verify refs/heads/from-mainline)" | |
964 | ) | |
965 | ' | |
966 | ||
967 | test_expect_success 'push "sub dir"/ with --branch for an existing branch' ' | |
968 | subtree_test_create_repo "$test_count" && | |
969 | subtree_test_create_repo "$test_count/sub proj" && | |
970 | test_create_commit "$test_count" main1 && | |
971 | test_create_commit "$test_count/sub proj" sub1 && | |
972 | ( | |
973 | cd "$test_count" && | |
974 | git fetch ./"sub proj" HEAD && | |
975 | git branch subproj-br FETCH_HEAD && | |
976 | git subtree add --prefix="sub dir" FETCH_HEAD | |
977 | ) && | |
978 | test_create_commit "$test_count" "sub dir"/main-sub1 && | |
979 | test_create_commit "$test_count" main2 && | |
980 | test_create_commit "$test_count/sub proj" sub2 && | |
981 | test_create_commit "$test_count" "sub dir"/main-sub2 && | |
982 | ( | |
983 | cd "$test_count" && | |
984 | git fetch ./"sub proj" HEAD && | |
985 | git subtree merge --prefix="sub dir" FETCH_HEAD && | |
986 | split_hash=$(git subtree split --prefix="sub dir" --annotate="*") && | |
987 | git subtree push --prefix="sub dir" --annotate="*" --branch subproj-br ./"sub proj" from-mainline && | |
988 | test "$(git rev-parse subproj-br)" = "$split_hash" && | |
989 | test "$split_hash" = "$(git -C "sub proj" rev-parse --verify refs/heads/from-mainline)" | |
990 | ) | |
991 | ' | |
992 | ||
993 | test_expect_success 'push "sub dir"/ with --branch for an incompatible branch' ' | |
994 | subtree_test_create_repo "$test_count" && | |
995 | subtree_test_create_repo "$test_count/sub proj" && | |
996 | test_create_commit "$test_count" main1 && | |
997 | test_create_commit "$test_count/sub proj" sub1 && | |
998 | ( | |
999 | cd "$test_count" && | |
1000 | git branch init HEAD && | |
1001 | git fetch ./"sub proj" HEAD && | |
1002 | git subtree add --prefix="sub dir" FETCH_HEAD | |
1003 | ) && | |
1004 | test_create_commit "$test_count" "sub dir"/main-sub1 && | |
1005 | test_create_commit "$test_count" main2 && | |
1006 | test_create_commit "$test_count/sub proj" sub2 && | |
1007 | test_create_commit "$test_count" "sub dir"/main-sub2 && | |
1008 | ( | |
1009 | cd "$test_count" && | |
1010 | git fetch ./"sub proj" HEAD && | |
1011 | git subtree merge --prefix="sub dir" FETCH_HEAD && | |
1012 | test_must_fail git subtree push --prefix="sub dir" --branch init "./sub proj" from-mainline | |
1013 | ) | |
1014 | ' | |
1015 | ||
49470cd4 LS |
1016 | test_expect_success 'push "sub dir"/ with a local rev' ' |
1017 | subtree_test_create_repo "$test_count" && | |
1018 | subtree_test_create_repo "$test_count/sub proj" && | |
1019 | test_create_commit "$test_count" main1 && | |
1020 | test_create_commit "$test_count/sub proj" sub1 && | |
1021 | ( | |
1022 | cd "$test_count" && | |
1023 | git fetch ./"sub proj" HEAD && | |
1024 | git subtree add --prefix="sub dir" FETCH_HEAD | |
1025 | ) && | |
1026 | test_create_commit "$test_count" "sub dir"/main-sub1 && | |
1027 | test_create_commit "$test_count" "sub dir"/main-sub2 && | |
1028 | ( | |
1029 | cd "$test_count" && | |
1030 | bad_tree=$(git rev-parse --verify HEAD:"sub dir") && | |
1031 | good_tree=$(git rev-parse --verify HEAD^:"sub dir") && | |
1032 | git subtree push --prefix="sub dir" --annotate="*" ./"sub proj" HEAD^:from-mainline && | |
1033 | split_tree=$(git -C "sub proj" rev-parse --verify refs/heads/from-mainline:) && | |
1034 | test "$split_tree" = "$good_tree" | |
1035 | ) | |
1036 | ' | |
1037 | ||
1762382a PB |
1038 | test_expect_success 'push after annotated tag was added/merged with --squash pre-v2.32.0' ' |
1039 | test_create_pre2_32_repo "$test_count" && | |
1040 | test_create_commit "$test_count-clone" sub/main-sub1 && | |
1041 | git -C "$test_count-clone" subtree push --prefix="sub" "../$test_count-sub" from-mainline | |
1042 | ' | |
1043 | ||
43711746 TZ |
1044 | # |
1045 | # Validity checking | |
1046 | # | |
b0638aa2 | 1047 | |
43711746 | 1048 | test_expect_success 'make sure exactly the right set of files ends up in the subproj' ' |
f2bb7fef LS |
1049 | subtree_test_create_repo "$test_count" && |
1050 | subtree_test_create_repo "$test_count/sub proj" && | |
1051 | test_create_commit "$test_count" main1 && | |
1052 | test_create_commit "$test_count/sub proj" sub1 && | |
43711746 | 1053 | ( |
f2bb7fef | 1054 | cd "$test_count" && |
914d5125 | 1055 | git fetch ./"sub proj" HEAD && |
43711746 TZ |
1056 | git subtree add --prefix="sub dir" FETCH_HEAD |
1057 | ) && | |
f2bb7fef LS |
1058 | test_create_commit "$test_count" "sub dir"/main-sub1 && |
1059 | test_create_commit "$test_count" main2 && | |
1060 | test_create_commit "$test_count/sub proj" sub2 && | |
1061 | test_create_commit "$test_count" "sub dir"/main-sub2 && | |
43711746 | 1062 | ( |
f2bb7fef | 1063 | cd "$test_count" && |
914d5125 | 1064 | git fetch ./"sub proj" HEAD && |
43711746 TZ |
1065 | git subtree merge --prefix="sub dir" FETCH_HEAD && |
1066 | git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin | |
1067 | ) && | |
f2bb7fef LS |
1068 | test_create_commit "$test_count/sub proj" sub3 && |
1069 | test_create_commit "$test_count" "sub dir"/main-sub3 && | |
43711746 | 1070 | ( |
f2bb7fef | 1071 | cd "$test_count/sub proj" && |
43711746 TZ |
1072 | git fetch .. subproj-br && |
1073 | git merge FETCH_HEAD | |
1074 | ) && | |
f2bb7fef | 1075 | test_create_commit "$test_count/sub proj" sub4 && |
43711746 | 1076 | ( |
f2bb7fef | 1077 | cd "$test_count" && |
43711746 TZ |
1078 | git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin |
1079 | ) && | |
f2bb7fef | 1080 | test_create_commit "$test_count" "sub dir"/main-sub4 && |
43711746 | 1081 | ( |
f2bb7fef | 1082 | cd "$test_count" && |
43711746 TZ |
1083 | git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin |
1084 | ) && | |
1085 | ( | |
f2bb7fef | 1086 | cd "$test_count/sub proj" && |
43711746 TZ |
1087 | git fetch .. subproj-br && |
1088 | git merge FETCH_HEAD && | |
1089 | ||
6a8ad880 JN |
1090 | test_write_lines main-sub1 main-sub2 main-sub3 main-sub4 \ |
1091 | sub1 sub2 sub3 sub4 >expect && | |
1092 | git ls-files >actual && | |
1093 | test_cmp expect actual | |
43711746 | 1094 | ) |
d3a04e06 | 1095 | ' |
b0638aa2 | 1096 | |
43711746 | 1097 | test_expect_success 'make sure the subproj *only* contains commits that affect the "sub dir"' ' |
f2bb7fef LS |
1098 | subtree_test_create_repo "$test_count" && |
1099 | subtree_test_create_repo "$test_count/sub proj" && | |
1100 | test_create_commit "$test_count" main1 && | |
1101 | test_create_commit "$test_count/sub proj" sub1 && | |
43711746 | 1102 | ( |
f2bb7fef | 1103 | cd "$test_count" && |
914d5125 | 1104 | git fetch ./"sub proj" HEAD && |
43711746 TZ |
1105 | git subtree add --prefix="sub dir" FETCH_HEAD |
1106 | ) && | |
f2bb7fef LS |
1107 | test_create_commit "$test_count" "sub dir"/main-sub1 && |
1108 | test_create_commit "$test_count" main2 && | |
1109 | test_create_commit "$test_count/sub proj" sub2 && | |
1110 | test_create_commit "$test_count" "sub dir"/main-sub2 && | |
43711746 | 1111 | ( |
f2bb7fef | 1112 | cd "$test_count" && |
914d5125 | 1113 | git fetch ./"sub proj" HEAD && |
43711746 TZ |
1114 | git subtree merge --prefix="sub dir" FETCH_HEAD && |
1115 | git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin | |
1116 | ) && | |
f2bb7fef LS |
1117 | test_create_commit "$test_count/sub proj" sub3 && |
1118 | test_create_commit "$test_count" "sub dir"/main-sub3 && | |
43711746 | 1119 | ( |
f2bb7fef | 1120 | cd "$test_count/sub proj" && |
43711746 TZ |
1121 | git fetch .. subproj-br && |
1122 | git merge FETCH_HEAD | |
1123 | ) && | |
f2bb7fef | 1124 | test_create_commit "$test_count/sub proj" sub4 && |
43711746 | 1125 | ( |
f2bb7fef | 1126 | cd "$test_count" && |
43711746 TZ |
1127 | git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin |
1128 | ) && | |
f2bb7fef | 1129 | test_create_commit "$test_count" "sub dir"/main-sub4 && |
43711746 | 1130 | ( |
f2bb7fef | 1131 | cd "$test_count" && |
43711746 TZ |
1132 | git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin |
1133 | ) && | |
1134 | ( | |
f2bb7fef | 1135 | cd "$test_count/sub proj" && |
43711746 TZ |
1136 | git fetch .. subproj-br && |
1137 | git merge FETCH_HEAD && | |
1138 | ||
6a8ad880 JN |
1139 | test_write_lines main-sub1 main-sub2 main-sub3 main-sub4 \ |
1140 | sub1 sub2 sub3 sub4 >expect && | |
1141 | git log --name-only --pretty=format:"" >log && | |
1142 | sort <log | sed "/^\$/ d" >actual && | |
1143 | test_cmp expect actual | |
43711746 | 1144 | ) |
d3a04e06 | 1145 | ' |
1490e154 | 1146 | |
d3a04e06 | 1147 | test_expect_success 'make sure exactly the right set of files ends up in the mainline' ' |
f2bb7fef LS |
1148 | subtree_test_create_repo "$test_count" && |
1149 | subtree_test_create_repo "$test_count/sub proj" && | |
1150 | test_create_commit "$test_count" main1 && | |
1151 | test_create_commit "$test_count/sub proj" sub1 && | |
43711746 | 1152 | ( |
f2bb7fef | 1153 | cd "$test_count" && |
914d5125 | 1154 | git fetch ./"sub proj" HEAD && |
43711746 TZ |
1155 | git subtree add --prefix="sub dir" FETCH_HEAD |
1156 | ) && | |
f2bb7fef LS |
1157 | test_create_commit "$test_count" "sub dir"/main-sub1 && |
1158 | test_create_commit "$test_count" main2 && | |
1159 | test_create_commit "$test_count/sub proj" sub2 && | |
1160 | test_create_commit "$test_count" "sub dir"/main-sub2 && | |
43711746 | 1161 | ( |
f2bb7fef | 1162 | cd "$test_count" && |
914d5125 | 1163 | git fetch ./"sub proj" HEAD && |
43711746 TZ |
1164 | git subtree merge --prefix="sub dir" FETCH_HEAD && |
1165 | git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin | |
1166 | ) && | |
f2bb7fef LS |
1167 | test_create_commit "$test_count/sub proj" sub3 && |
1168 | test_create_commit "$test_count" "sub dir"/main-sub3 && | |
43711746 | 1169 | ( |
f2bb7fef | 1170 | cd "$test_count/sub proj" && |
43711746 TZ |
1171 | git fetch .. subproj-br && |
1172 | git merge FETCH_HEAD | |
1173 | ) && | |
f2bb7fef | 1174 | test_create_commit "$test_count/sub proj" sub4 && |
43711746 | 1175 | ( |
f2bb7fef | 1176 | cd "$test_count" && |
43711746 TZ |
1177 | git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin |
1178 | ) && | |
f2bb7fef | 1179 | test_create_commit "$test_count" "sub dir"/main-sub4 && |
43711746 | 1180 | ( |
f2bb7fef | 1181 | cd "$test_count" && |
43711746 TZ |
1182 | git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin |
1183 | ) && | |
1184 | ( | |
f2bb7fef | 1185 | cd "$test_count/sub proj" && |
43711746 TZ |
1186 | git fetch .. subproj-br && |
1187 | git merge FETCH_HEAD | |
1188 | ) && | |
1189 | ( | |
f2bb7fef | 1190 | cd "$test_count" && |
914d5125 | 1191 | git subtree pull --prefix="sub dir" ./"sub proj" HEAD && |
43711746 | 1192 | |
6a8ad880 JN |
1193 | test_write_lines main1 main2 >chkm && |
1194 | test_write_lines main-sub1 main-sub2 main-sub3 main-sub4 >chkms && | |
1195 | sed "s,^,sub dir/," chkms >chkms_sub && | |
1196 | test_write_lines sub1 sub2 sub3 sub4 >chks && | |
1197 | sed "s,^,sub dir/," chks >chks_sub && | |
1198 | ||
1199 | cat chkm chkms_sub chks_sub >expect && | |
1200 | git ls-files >actual && | |
1201 | test_cmp expect actual | |
1202 | ) | |
d3a04e06 DG |
1203 | ' |
1204 | ||
d3a04e06 | 1205 | test_expect_success 'make sure each filename changed exactly once in the entire history' ' |
f2bb7fef LS |
1206 | subtree_test_create_repo "$test_count" && |
1207 | subtree_test_create_repo "$test_count/sub proj" && | |
1208 | test_create_commit "$test_count" main1 && | |
1209 | test_create_commit "$test_count/sub proj" sub1 && | |
43711746 | 1210 | ( |
f2bb7fef | 1211 | cd "$test_count" && |
ad6eee36 | 1212 | git config log.date relative && |
914d5125 | 1213 | git fetch ./"sub proj" HEAD && |
43711746 TZ |
1214 | git subtree add --prefix="sub dir" FETCH_HEAD |
1215 | ) && | |
f2bb7fef LS |
1216 | test_create_commit "$test_count" "sub dir"/main-sub1 && |
1217 | test_create_commit "$test_count" main2 && | |
1218 | test_create_commit "$test_count/sub proj" sub2 && | |
1219 | test_create_commit "$test_count" "sub dir"/main-sub2 && | |
43711746 | 1220 | ( |
f2bb7fef | 1221 | cd "$test_count" && |
914d5125 | 1222 | git fetch ./"sub proj" HEAD && |
43711746 TZ |
1223 | git subtree merge --prefix="sub dir" FETCH_HEAD && |
1224 | git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin | |
1225 | ) && | |
f2bb7fef LS |
1226 | test_create_commit "$test_count/sub proj" sub3 && |
1227 | test_create_commit "$test_count" "sub dir"/main-sub3 && | |
43711746 | 1228 | ( |
f2bb7fef | 1229 | cd "$test_count/sub proj" && |
43711746 TZ |
1230 | git fetch .. subproj-br && |
1231 | git merge FETCH_HEAD | |
1232 | ) && | |
f2bb7fef | 1233 | test_create_commit "$test_count/sub proj" sub4 && |
43711746 | 1234 | ( |
f2bb7fef | 1235 | cd "$test_count" && |
43711746 TZ |
1236 | git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin |
1237 | ) && | |
f2bb7fef | 1238 | test_create_commit "$test_count" "sub dir"/main-sub4 && |
43711746 | 1239 | ( |
f2bb7fef | 1240 | cd "$test_count" && |
43711746 TZ |
1241 | git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin |
1242 | ) && | |
1243 | ( | |
f2bb7fef | 1244 | cd "$test_count/sub proj" && |
43711746 TZ |
1245 | git fetch .. subproj-br && |
1246 | git merge FETCH_HEAD | |
1247 | ) && | |
1248 | ( | |
f2bb7fef | 1249 | cd "$test_count" && |
914d5125 | 1250 | git subtree pull --prefix="sub dir" ./"sub proj" HEAD && |
43711746 | 1251 | |
6a8ad880 JN |
1252 | test_write_lines main1 main2 >chkm && |
1253 | test_write_lines sub1 sub2 sub3 sub4 >chks && | |
1254 | test_write_lines main-sub1 main-sub2 main-sub3 main-sub4 >chkms && | |
1255 | sed "s,^,sub dir/," chkms >chkms_sub && | |
43711746 TZ |
1256 | |
1257 | # main-sub?? and /"sub dir"/main-sub?? both change, because those are the | |
1258 | # changes that were split into their own history. And "sub dir"/sub?? never | |
1259 | # change, since they were *only* changed in the subtree branch. | |
6a8ad880 JN |
1260 | git log --name-only --pretty=format:"" >log && |
1261 | sort <log >sorted-log && | |
1262 | sed "/^$/ d" sorted-log >actual && | |
1263 | ||
1264 | cat chkms chkm chks chkms_sub >expect-unsorted && | |
1265 | sort expect-unsorted >expect && | |
1266 | test_cmp expect actual | |
43711746 | 1267 | ) |
d3a04e06 DG |
1268 | ' |
1269 | ||
d3a04e06 | 1270 | test_expect_success 'make sure the --rejoin commits never make it into subproj' ' |
f2bb7fef LS |
1271 | subtree_test_create_repo "$test_count" && |
1272 | subtree_test_create_repo "$test_count/sub proj" && | |
1273 | test_create_commit "$test_count" main1 && | |
1274 | test_create_commit "$test_count/sub proj" sub1 && | |
43711746 | 1275 | ( |
f2bb7fef | 1276 | cd "$test_count" && |
914d5125 | 1277 | git fetch ./"sub proj" HEAD && |
43711746 TZ |
1278 | git subtree add --prefix="sub dir" FETCH_HEAD |
1279 | ) && | |
f2bb7fef LS |
1280 | test_create_commit "$test_count" "sub dir"/main-sub1 && |
1281 | test_create_commit "$test_count" main2 && | |
1282 | test_create_commit "$test_count/sub proj" sub2 && | |
1283 | test_create_commit "$test_count" "sub dir"/main-sub2 && | |
43711746 | 1284 | ( |
f2bb7fef | 1285 | cd "$test_count" && |
914d5125 | 1286 | git fetch ./"sub proj" HEAD && |
43711746 TZ |
1287 | git subtree merge --prefix="sub dir" FETCH_HEAD && |
1288 | git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin | |
1289 | ) && | |
f2bb7fef LS |
1290 | test_create_commit "$test_count/sub proj" sub3 && |
1291 | test_create_commit "$test_count" "sub dir"/main-sub3 && | |
43711746 | 1292 | ( |
f2bb7fef | 1293 | cd "$test_count/sub proj" && |
43711746 TZ |
1294 | git fetch .. subproj-br && |
1295 | git merge FETCH_HEAD | |
1296 | ) && | |
f2bb7fef | 1297 | test_create_commit "$test_count/sub proj" sub4 && |
43711746 | 1298 | ( |
f2bb7fef | 1299 | cd "$test_count" && |
43711746 TZ |
1300 | git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin |
1301 | ) && | |
f2bb7fef | 1302 | test_create_commit "$test_count" "sub dir"/main-sub4 && |
43711746 | 1303 | ( |
f2bb7fef | 1304 | cd "$test_count" && |
43711746 TZ |
1305 | git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin |
1306 | ) && | |
1307 | ( | |
f2bb7fef | 1308 | cd "$test_count/sub proj" && |
43711746 TZ |
1309 | git fetch .. subproj-br && |
1310 | git merge FETCH_HEAD | |
1311 | ) && | |
1312 | ( | |
f2bb7fef | 1313 | cd "$test_count" && |
914d5125 | 1314 | git subtree pull --prefix="sub dir" ./"sub proj" HEAD && |
c4566ab4 | 1315 | test "$(git log --pretty=format:"%s" HEAD^2 | grep -i split)" = "" |
43711746 | 1316 | ) |
d3a04e06 DG |
1317 | ' |
1318 | ||
d3a04e06 | 1319 | test_expect_success 'make sure no "git subtree" tagged commits make it into subproj' ' |
f2bb7fef LS |
1320 | subtree_test_create_repo "$test_count" && |
1321 | subtree_test_create_repo "$test_count/sub proj" && | |
1322 | test_create_commit "$test_count" main1 && | |
1323 | test_create_commit "$test_count/sub proj" sub1 && | |
43711746 | 1324 | ( |
f2bb7fef | 1325 | cd "$test_count" && |
914d5125 | 1326 | git fetch ./"sub proj" HEAD && |
43711746 TZ |
1327 | git subtree add --prefix="sub dir" FETCH_HEAD |
1328 | ) && | |
f2bb7fef LS |
1329 | test_create_commit "$test_count" "sub dir"/main-sub1 && |
1330 | test_create_commit "$test_count" main2 && | |
1331 | test_create_commit "$test_count/sub proj" sub2 && | |
1332 | test_create_commit "$test_count" "sub dir"/main-sub2 && | |
43711746 | 1333 | ( |
f2bb7fef | 1334 | cd "$test_count" && |
914d5125 | 1335 | git fetch ./"sub proj" HEAD && |
43711746 TZ |
1336 | git subtree merge --prefix="sub dir" FETCH_HEAD && |
1337 | git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin | |
1338 | ) && | |
f2bb7fef LS |
1339 | test_create_commit "$test_count/sub proj" sub3 && |
1340 | test_create_commit "$test_count" "sub dir"/main-sub3 && | |
43711746 | 1341 | ( |
f2bb7fef | 1342 | cd "$test_count/sub proj" && |
43711746 TZ |
1343 | git fetch .. subproj-br && |
1344 | git merge FETCH_HEAD | |
1345 | ) && | |
f2bb7fef | 1346 | test_create_commit "$test_count/sub proj" sub4 && |
43711746 | 1347 | ( |
f2bb7fef | 1348 | cd "$test_count" && |
43711746 TZ |
1349 | git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin |
1350 | ) && | |
f2bb7fef | 1351 | test_create_commit "$test_count" "sub dir"/main-sub4 && |
43711746 | 1352 | ( |
f2bb7fef | 1353 | cd "$test_count" && |
43711746 TZ |
1354 | git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin |
1355 | ) && | |
1356 | ( | |
f2bb7fef | 1357 | cd "$test_count/sub proj" && |
43711746 TZ |
1358 | git fetch .. subproj-br && |
1359 | git merge FETCH_HEAD | |
1360 | ) && | |
1361 | ( | |
f2bb7fef | 1362 | cd "$test_count" && |
914d5125 | 1363 | git subtree pull --prefix="sub dir" ./"sub proj" HEAD && |
43711746 TZ |
1364 | |
1365 | # They are meaningless to subproj since one side of the merge refers to the mainline | |
c4566ab4 | 1366 | test "$(git log --pretty=format:"%s%n%b" HEAD^2 | grep "git-subtree.*:")" = "" |
43711746 | 1367 | ) |
d3a04e06 DG |
1368 | ' |
1369 | ||
43711746 TZ |
1370 | # |
1371 | # A new set of tests | |
1372 | # | |
d3a04e06 | 1373 | |
43711746 | 1374 | test_expect_success 'make sure "git subtree split" find the correct parent' ' |
f2bb7fef LS |
1375 | subtree_test_create_repo "$test_count" && |
1376 | subtree_test_create_repo "$test_count/sub proj" && | |
1377 | test_create_commit "$test_count" main1 && | |
1378 | test_create_commit "$test_count/sub proj" sub1 && | |
43711746 | 1379 | ( |
f2bb7fef | 1380 | cd "$test_count" && |
914d5125 | 1381 | git fetch ./"sub proj" HEAD && |
43711746 TZ |
1382 | git subtree add --prefix="sub dir" FETCH_HEAD |
1383 | ) && | |
f2bb7fef | 1384 | test_create_commit "$test_count/sub proj" sub2 && |
43711746 | 1385 | ( |
f2bb7fef | 1386 | cd "$test_count" && |
914d5125 | 1387 | git fetch ./"sub proj" HEAD && |
43711746 TZ |
1388 | git branch subproj-ref FETCH_HEAD && |
1389 | git subtree merge --prefix="sub dir" FETCH_HEAD | |
1390 | ) && | |
f2bb7fef | 1391 | test_create_commit "$test_count" "sub dir"/main-sub1 && |
43711746 | 1392 | ( |
f2bb7fef | 1393 | cd "$test_count" && |
43711746 TZ |
1394 | git subtree split --prefix="sub dir" --branch subproj-br && |
1395 | ||
1396 | # at this point, the new commit parent should be subproj-ref, if it is | |
914d5125 | 1397 | # not, something went wrong (the "newparent" of "HEAD~" commit should |
43711746 TZ |
1398 | # have been sub2, but it was not, because its cache was not set to |
1399 | # itself) | |
c4566ab4 | 1400 | test "$(git log --pretty=format:%P -1 subproj-br)" = "$(git rev-parse subproj-ref)" |
43711746 | 1401 | ) |
d3a04e06 DG |
1402 | ' |
1403 | ||
43711746 | 1404 | test_expect_success 'split a new subtree without --onto option' ' |
f2bb7fef LS |
1405 | subtree_test_create_repo "$test_count" && |
1406 | subtree_test_create_repo "$test_count/sub proj" && | |
1407 | test_create_commit "$test_count" main1 && | |
1408 | test_create_commit "$test_count/sub proj" sub1 && | |
43711746 | 1409 | ( |
f2bb7fef | 1410 | cd "$test_count" && |
914d5125 | 1411 | git fetch ./"sub proj" HEAD && |
43711746 TZ |
1412 | git subtree add --prefix="sub dir" FETCH_HEAD |
1413 | ) && | |
f2bb7fef | 1414 | test_create_commit "$test_count/sub proj" sub2 && |
43711746 | 1415 | ( |
f2bb7fef | 1416 | cd "$test_count" && |
914d5125 | 1417 | git fetch ./"sub proj" HEAD && |
43711746 TZ |
1418 | git subtree merge --prefix="sub dir" FETCH_HEAD |
1419 | ) && | |
f2bb7fef | 1420 | test_create_commit "$test_count" "sub dir"/main-sub1 && |
43711746 | 1421 | ( |
f2bb7fef | 1422 | cd "$test_count" && |
43711746 TZ |
1423 | git subtree split --prefix="sub dir" --branch subproj-br |
1424 | ) && | |
f2bb7fef LS |
1425 | mkdir "$test_count"/"sub dir2" && |
1426 | test_create_commit "$test_count" "sub dir2"/main-sub2 && | |
43711746 | 1427 | ( |
f2bb7fef | 1428 | cd "$test_count" && |
43711746 TZ |
1429 | |
1430 | # also test that we still can split out an entirely new subtree | |
1431 | # if the parent of the first commit in the tree is not empty, | |
2e3a16b2 | 1432 | # then the new subtree has accidentally been attached to something |
43711746 | 1433 | git subtree split --prefix="sub dir2" --branch subproj2-br && |
c4566ab4 | 1434 | test "$(git log --pretty=format:%P -1 subproj2-br)" = "" |
43711746 | 1435 | ) |
d3a04e06 | 1436 | ' |
13ea2b5e | 1437 | |
d3a04e06 | 1438 | test_expect_success 'verify one file change per commit' ' |
f2bb7fef LS |
1439 | subtree_test_create_repo "$test_count" && |
1440 | subtree_test_create_repo "$test_count/sub proj" && | |
1441 | test_create_commit "$test_count" main1 && | |
1442 | test_create_commit "$test_count/sub proj" sub1 && | |
43711746 | 1443 | ( |
f2bb7fef | 1444 | cd "$test_count" && |
914d5125 | 1445 | git fetch ./"sub proj" HEAD && |
43711746 TZ |
1446 | git branch sub1 FETCH_HEAD && |
1447 | git subtree add --prefix="sub dir" sub1 | |
1448 | ) && | |
f2bb7fef | 1449 | test_create_commit "$test_count/sub proj" sub2 && |
43711746 | 1450 | ( |
f2bb7fef | 1451 | cd "$test_count" && |
914d5125 | 1452 | git fetch ./"sub proj" HEAD && |
43711746 TZ |
1453 | git subtree merge --prefix="sub dir" FETCH_HEAD |
1454 | ) && | |
f2bb7fef | 1455 | test_create_commit "$test_count" "sub dir"/main-sub1 && |
43711746 | 1456 | ( |
f2bb7fef | 1457 | cd "$test_count" && |
43711746 TZ |
1458 | git subtree split --prefix="sub dir" --branch subproj-br |
1459 | ) && | |
f2bb7fef LS |
1460 | mkdir "$test_count"/"sub dir2" && |
1461 | test_create_commit "$test_count" "sub dir2"/main-sub2 && | |
43711746 | 1462 | ( |
f2bb7fef | 1463 | cd "$test_count" && |
43711746 TZ |
1464 | git subtree split --prefix="sub dir2" --branch subproj2-br && |
1465 | ||
f1cd2d93 LS |
1466 | git log --format="%H" >commit-list && |
1467 | while read commit | |
1468 | do | |
1469 | git log -n1 --format="" --name-only "$commit" >file-list && | |
1470 | test_line_count -le 1 file-list || return 1 | |
1471 | done <commit-list | |
b0638aa2 | 1472 | ) |
d3a04e06 DG |
1473 | ' |
1474 | ||
43711746 | 1475 | test_expect_success 'push split to subproj' ' |
f2bb7fef LS |
1476 | subtree_test_create_repo "$test_count" && |
1477 | subtree_test_create_repo "$test_count/sub proj" && | |
1478 | test_create_commit "$test_count" main1 && | |
1479 | test_create_commit "$test_count/sub proj" sub1 && | |
43711746 | 1480 | ( |
f2bb7fef | 1481 | cd "$test_count" && |
914d5125 | 1482 | git fetch ./"sub proj" HEAD && |
43711746 TZ |
1483 | git subtree add --prefix="sub dir" FETCH_HEAD |
1484 | ) && | |
f2bb7fef LS |
1485 | test_create_commit "$test_count" "sub dir"/main-sub1 && |
1486 | test_create_commit "$test_count" main2 && | |
1487 | test_create_commit "$test_count/sub proj" sub2 && | |
1488 | test_create_commit "$test_count" "sub dir"/main-sub2 && | |
43711746 | 1489 | ( |
f2bb7fef | 1490 | cd $test_count/"sub proj" && |
f7004069 LS |
1491 | git branch sub-branch-1 && |
1492 | cd .. && | |
914d5125 | 1493 | git fetch ./"sub proj" HEAD && |
43711746 TZ |
1494 | git subtree merge --prefix="sub dir" FETCH_HEAD |
1495 | ) && | |
f2bb7fef | 1496 | test_create_commit "$test_count" "sub dir"/main-sub3 && |
f7004069 | 1497 | ( |
f2bb7fef | 1498 | cd "$test_count" && |
f7004069 LS |
1499 | git subtree push ./"sub proj" --prefix "sub dir" sub-branch-1 && |
1500 | cd ./"sub proj" && | |
1501 | git checkout sub-branch-1 && | |
db6952b2 | 1502 | test "$(last_commit_subject)" = "sub dir/main-sub3" |
43711746 | 1503 | ) |
5b6ab38b AS |
1504 | ' |
1505 | ||
933cfeb9 DW |
1506 | # |
1507 | # This test covers 2 cases in subtree split copy_or_skip code | |
1508 | # 1) Merges where one parent is a superset of the changes of the other | |
1509 | # parent regarding changes to the subtree, in this case the merge | |
1510 | # commit should be copied | |
1511 | # 2) Merges where only one parent operate on the subtree, and the merge | |
1512 | # commit should be skipped | |
1513 | # | |
1514 | # (1) is checked by ensuring subtree_tip is a descendent of subtree_branch | |
1515 | # (2) should have a check added (not_a_subtree_change shouldn't be present | |
1516 | # on the produced subtree) | |
1517 | # | |
1518 | # Other related cases which are not tested (or currently handled correctly) | |
1519 | # - Case (1) where there are more than 2 parents, it will sometimes correctly copy | |
1520 | # the merge, and sometimes not | |
1521 | # - Merge commit where both parents have same tree as the merge, currently | |
1522 | # will always be skipped, even if they reached that state via different | |
1523 | # set of commits. | |
1524 | # | |
1525 | ||
933cfeb9 | 1526 | test_expect_success 'subtree descendant check' ' |
f2bb7fef LS |
1527 | subtree_test_create_repo "$test_count" && |
1528 | defaultBranch=$(sed "s,ref: refs/heads/,," "$test_count/.git/HEAD") && | |
1529 | test_create_commit "$test_count" folder_subtree/a && | |
933cfeb9 | 1530 | ( |
f2bb7fef | 1531 | cd "$test_count" && |
933cfeb9 DW |
1532 | git branch branch |
1533 | ) && | |
f2bb7fef LS |
1534 | test_create_commit "$test_count" folder_subtree/0 && |
1535 | test_create_commit "$test_count" folder_subtree/b && | |
c576868e | 1536 | cherry=$(cd "$test_count" && git rev-parse HEAD) && |
933cfeb9 | 1537 | ( |
f2bb7fef | 1538 | cd "$test_count" && |
933cfeb9 DW |
1539 | git checkout branch |
1540 | ) && | |
f2bb7fef | 1541 | test_create_commit "$test_count" commit_on_branch && |
933cfeb9 | 1542 | ( |
f2bb7fef | 1543 | cd "$test_count" && |
933cfeb9 | 1544 | git cherry-pick $cherry && |
914d5125 | 1545 | git checkout $defaultBranch && |
933cfeb9 DW |
1546 | git merge -m "merge should be kept on subtree" branch && |
1547 | git branch no_subtree_work_branch | |
1548 | ) && | |
f2bb7fef | 1549 | test_create_commit "$test_count" folder_subtree/d && |
933cfeb9 | 1550 | ( |
f2bb7fef | 1551 | cd "$test_count" && |
933cfeb9 DW |
1552 | git checkout no_subtree_work_branch |
1553 | ) && | |
f2bb7fef | 1554 | test_create_commit "$test_count" not_a_subtree_change && |
933cfeb9 | 1555 | ( |
f2bb7fef | 1556 | cd "$test_count" && |
914d5125 | 1557 | git checkout $defaultBranch && |
933cfeb9 DW |
1558 | git merge -m "merge should be skipped on subtree" no_subtree_work_branch && |
1559 | ||
914d5125 | 1560 | git subtree split --prefix folder_subtree/ --branch subtree_tip $defaultBranch && |
933cfeb9 | 1561 | git subtree split --prefix folder_subtree/ --branch subtree_branch branch && |
c4566ab4 | 1562 | test $(git rev-list --count subtree_tip..subtree_branch) = 0 |
933cfeb9 DW |
1563 | ) |
1564 | ' | |
1565 | ||
d3a04e06 | 1566 | test_done |