contrib/subtree: Make each test self-contained
Each test runs a full repository creation and any subtree actions needed to perform the test. Each test starts with a clean slate, making debugging and post-mortem analysis much easier. Signed-off-by: Techlive Zheng <techlivezheng@gmail.com> Signed-off-by: David A. Greene <greened@obbligato.org> Signed-off-by: Jeff King <peff@peff.net>
Techlive Zheng committed
Nov 12, 2015 at 20:32 UTC
43711746bd01eff9d8bac658bf1d6a39151088f2
1 file changed
+840
-418
contrib/subtree/t/t7900-subtree.sh
+840
-418
@@ -14,6 +14,15 @@ export TEST_DIRECTORY
14
15
. ../../../t/test-lib.sh
16
17
+subtree_test_create_repo()
18
+{
19
+ test_create_repo "$1"
20
+ (
21
+ cd $1
22
+ git config log.date relative
23
+ )
24
+}
25
+
26
create()
27
{
28
echo "$1" >"$1"
@@ -61,515 +70,928 @@ join_commits()
70
echo "$commit $all"
71
}
72
73
+test_create_commit() (
74
+ repo=$1
75
+ commit=$2
76
+ cd "$repo"
77
+ mkdir -p $(dirname "$commit") \
78
+ || error "Could not create directory for commit"
79
+ echo "$commit" >"$commit"
80
+ git add "$commit" || error "Could not add commit"
81
+ git commit -m "$commit" || error "Could not commit"
82
+)
83
+
84
last_commit_message()
85
{
86
git log --pretty=format:%s -1
87
}
88
69
-test_expect_success 'init subproj' '
70
- test_create_repo "sub proj"
71
-'
72
-
73
-# To the subproject!
74
-cd ./"sub proj"
75
-
76
-test_expect_success 'add sub1' '
77
- create sub1 &&
78
- git commit -m "sub1" &&
79
- git branch sub1 &&
80
- git branch -m master subproj
81
-'
82
-
83
-# Save this hash for testing later.
84
-
85
-subdir_hash=$(git rev-parse HEAD)
86
-
87
-test_expect_success 'add sub2' '
88
- create sub2 &&
89
- git commit -m "sub2" &&
90
- git branch sub2
91
-'
92
-
93
-test_expect_success 'add sub3' '
94
- create sub3 &&
95
- git commit -m "sub3" &&
96
- git branch sub3
97
-'
98
-
99
-# Back to mainline
100
-cd ..
101
-
102
-test_expect_success 'enable log.date=relative to catch errors' '
103
- git config log.date relative
104
-'
105
-
106
-test_expect_success 'add main4' '
107
- create main4 &&
108
- git commit -m "main4" &&
109
- git branch -m master mainline &&
110
- git branch subdir
111
-'
112
-
113
-test_expect_success 'fetch subproj history' '
114
- git fetch ./"sub proj" sub1 &&
115
- git branch sub1 FETCH_HEAD
116
-'
117
-
118
-test_expect_success 'no subtree exists in main tree' '
119
- test_must_fail git subtree merge --prefix="sub dir" sub1
120
-'
89
+subtree_test_count=0
90
+next_test() {
91
+ subtree_test_count=$(($subtree_test_count+1))
92
+}
93
122
-test_expect_success 'no pull from non-existant subtree' '
123
- test_must_fail git subtree pull --prefix="sub dir" ./"sub proj" sub1
124
-'
94
+#
95
+# Tests for 'git subtree add'
96
+#
97
98
+next_test
99
test_expect_success 'no merge from non-existent subtree' '
127
- test_must_fail git subtree merge --prefix="sub dir" FETCH_HEAD
100
+ subtree_test_create_repo "$subtree_test_count" &&
101
+ subtree_test_create_repo "$subtree_test_count/sub proj" &&
102
+ test_create_commit "$subtree_test_count" main1 &&
103
+ test_create_commit "$subtree_test_count/sub proj" sub1 &&
104
+ (
105
+ cd "$subtree_test_count" &&
106
+ git fetch ./"sub proj" master &&
107
+ test_must_fail git subtree merge --prefix="sub dir" FETCH_HEAD
108
+ )
109
'
110
130
-test_expect_success 'add subproj as subtree into sub dir/ with --prefix' '
131
- git subtree add --prefix="sub dir" sub1 &&
132
- check_equal "$(last_commit_message)" "Add '\''sub dir/'\'' from commit '\''$(git rev-parse sub1)'\''" &&
133
- undo
134
-'
111
+next_test
112
+test_expect_success 'no pull from non-existent subtree' '
113
+ subtree_test_create_repo "$subtree_test_count" &&
114
+ subtree_test_create_repo "$subtree_test_count/sub proj" &&
115
+ test_create_commit "$subtree_test_count" main1 &&
116
+ test_create_commit "$subtree_test_count/sub proj" sub1 &&
117
+ (
118
+ cd "$subtree_test_count" &&
119
+ git fetch ./"sub proj" master &&
120
+ test_must_fail git subtree pull --prefix="sub dir" ./"sub proj" master
121
+ )'
122
136
-test_expect_success 'check if --message works for add' '
137
- git subtree add --prefix="sub dir" --message="Added subproject" sub1 &&
138
- check_equal ''"$(last_commit_message)"'' "Added subproject" &&
139
- undo
123
+next_test
124
+test_expect_success 'add subproj as subtree into sub dir/ with --prefix' '
125
+ subtree_test_create_repo "$subtree_test_count" &&
126
+ subtree_test_create_repo "$subtree_test_count/sub proj" &&
127
+ test_create_commit "$subtree_test_count" main1 &&
128
+ test_create_commit "$subtree_test_count/sub proj" sub1 &&
129
+ (
130
+ cd "$subtree_test_count" &&
131
+ git fetch ./"sub proj" master &&
132
+ git subtree add --prefix="sub dir" FETCH_HEAD &&
133
+ check_equal "$(last_commit_message)" "Add '\''sub dir/'\'' from commit '\''$(git rev-parse FETCH_HEAD)'\''"
134
+ )
135
'
136
137
+next_test
138
test_expect_success 'add subproj as subtree into sub dir/ with --prefix and --message' '
143
- git subtree add --prefix="sub dir" --message="Added subproject" sub1 &&
144
- check_equal "$(last_commit_message)" "Added subproject" &&
145
- undo
146
-'
147
-
148
-test_expect_success 'check if --message works as -m and --prefix as -P' '
149
- git subtree add -P "sub dir" -m "Added subproject using git subtree" sub1 &&
150
- check_equal ''"$(last_commit_message)"'' "Added subproject using git subtree" &&
151
- undo
139
+ subtree_test_create_repo "$subtree_test_count" &&
140
+ subtree_test_create_repo "$subtree_test_count/sub proj" &&
141
+ test_create_commit "$subtree_test_count" main1 &&
142
+ test_create_commit "$subtree_test_count/sub proj" sub1 &&
143
+ (
144
+ cd "$subtree_test_count" &&
145
+ git fetch ./"sub proj" master &&
146
+ git subtree add --prefix="sub dir" --message="Added subproject" FETCH_HEAD &&
147
+ check_equal "$(last_commit_message)" "Added subproject"
148
+ )
149
'
150
154
-test_expect_success 'check if --message works with squash too' '
155
- git subtree add -P "sub dir" -m "Added subproject with squash" --squash sub1 &&
156
- check_equal ''"$(last_commit_message)"'' "Added subproject with squash" &&
157
- undo
151
+next_test
152
+test_expect_success 'add subproj as subtree into sub dir/ with --prefix as -P and --message as -m' '
153
+ subtree_test_create_repo "$subtree_test_count" &&
154
+ subtree_test_create_repo "$subtree_test_count/sub proj" &&
155
+ test_create_commit "$subtree_test_count" main1 &&
156
+ test_create_commit "$subtree_test_count/sub proj" sub1 &&
157
+ (
158
+ cd "$subtree_test_count" &&
159
+ git fetch ./"sub proj" master &&
160
+ git subtree add -P "sub dir" -m "Added subproject" FETCH_HEAD &&
161
+ check_equal "$(last_commit_message)" "Added subproject"
162
+ )
163
'
164
165
+next_test
166
test_expect_success 'add subproj as subtree into sub dir/ with --squash and --prefix and --message' '
161
- git subtree add --prefix="sub dir" --message="Added subproject with squash" --squash sub1 &&
162
- check_equal "$(last_commit_message)" "Added subproject with squash" &&
163
- undo
164
-'
165
-
166
-# Maybe delete
167
-test_expect_success 'add subproj to mainline' '
168
- git subtree add --prefix="sub dir"/ FETCH_HEAD &&
169
- check_equal ''"$(last_commit_message)"'' "Add '"'sub dir/'"' from commit '"'"'''"$(git rev-parse sub1)"'''"'"'"
170
-'
171
-
172
-test_expect_success 'merge the added subproj again, should do nothing' '
173
- # this shouldn not actually do anything, since FETCH_HEAD
174
- # is already a parent
175
- result=$(git merge -s ours -m "merge -s -ours" FETCH_HEAD) &&
176
- check_equal "${result}" "Already up-to-date."
177
-'
178
-
179
-test_expect_success 'add main-sub5' '
180
- create "sub dir/main-sub5" &&
181
- git commit -m "main-sub5"
182
-'
183
-
184
-test_expect_success 'add main6' '
185
- create main6 &&
186
- git commit -m "main6 boring"
187
-'
188
-
189
-test_expect_success 'add main-sub7' '
190
- create "sub dir/main-sub7" &&
191
- git commit -m "main-sub7"
167
+ subtree_test_create_repo "$subtree_test_count" &&
168
+ subtree_test_create_repo "$subtree_test_count/sub proj" &&
169
+ test_create_commit "$subtree_test_count" main1 &&
170
+ test_create_commit "$subtree_test_count/sub proj" sub1 &&
171
+ (
172
+ cd "$subtree_test_count" &&
173
+ git fetch ./"sub proj" master &&
174
+ git subtree add --prefix="sub dir" --message="Added subproject with squash" --squash FETCH_HEAD &&
175
+ check_equal "$(last_commit_message)" "Added subproject with squash"
176
+ )
177
'
178
194
-test_expect_success 'fetch new subproj history' '
195
- git fetch ./"sub proj" sub2 &&
196
- git branch sub2 FETCH_HEAD
197
-'
179
+#
180
+# Tests for 'git subtree merge'
181
+#
182
199
-test_expect_success 'check if --message works for merge' '
200
- git subtree merge --prefix="sub dir" -m "Merged changes from subproject" sub2 &&
201
- check_equal ''"$(last_commit_message)"'' "Merged changes from subproject" &&
202
- undo
183
+next_test
184
+test_expect_success 'merge new subproj history into sub dir/ with --prefix' '
185
+ subtree_test_create_repo "$subtree_test_count" &&
186
+ subtree_test_create_repo "$subtree_test_count/sub proj" &&
187
+ test_create_commit "$subtree_test_count" main1 &&
188
+ test_create_commit "$subtree_test_count/sub proj" sub1 &&
189
+ (
190
+ cd "$subtree_test_count" &&
191
+ git fetch ./"sub proj" master &&
192
+ git subtree add --prefix="sub dir" FETCH_HEAD
193
+ ) &&
194
+ test_create_commit "$subtree_test_count/sub proj" sub2 &&
195
+ (
196
+ cd "$subtree_test_count" &&
197
+ git fetch ./"sub proj" master &&
198
+ git subtree merge --prefix="sub dir" FETCH_HEAD &&
199
+ check_equal "$(last_commit_message)" "Merge commit '\''$(git rev-parse FETCH_HEAD)'\''"
200
+ )
201
'
202
205
-test_expect_success 'check if --message for merge works with squash too' '
206
- git subtree merge --prefix "sub dir" -m "Merged changes from subproject using squash" --squash sub2 &&
207
- check_equal ''"$(last_commit_message)"'' "Merged changes from subproject using squash" &&
208
- undo
203
+next_test
204
+test_expect_success 'merge new subproj history into sub dir/ with --prefix and --message' '
205
+ subtree_test_create_repo "$subtree_test_count" &&
206
+ subtree_test_create_repo "$subtree_test_count/sub proj" &&
207
+ test_create_commit "$subtree_test_count" main1 &&
208
+ test_create_commit "$subtree_test_count/sub proj" sub1 &&
209
+ (
210
+ cd "$subtree_test_count" &&
211
+ git fetch ./"sub proj" master &&
212
+ git subtree add --prefix="sub dir" FETCH_HEAD
213
+ ) &&
214
+ test_create_commit "$subtree_test_count/sub proj" sub2 &&
215
+ (
216
+ cd "$subtree_test_count" &&
217
+ git fetch ./"sub proj" master &&
218
+ git subtree merge --prefix="sub dir" --message="Merged changes from subproject" FETCH_HEAD &&
219
+ check_equal "$(last_commit_message)" "Merged changes from subproject"
220
+ )
221
'
222
211
-test_expect_success 'merge new subproj history into subdir' '
212
- git subtree merge --prefix="sub dir" FETCH_HEAD &&
213
- check_equal ''"$(last_commit_message)"'' "Merge commit '"'"'"$(git rev-parse sub2)"'"'"' into mainline" &&
214
- undo
223
+next_test
224
+test_expect_success 'merge new subproj history into sub dir/ with --squash and --prefix and --message' '
225
+ subtree_test_create_repo "$subtree_test_count/sub proj" &&
226
+ subtree_test_create_repo "$subtree_test_count" &&
227
+ test_create_commit "$subtree_test_count" main1 &&
228
+ test_create_commit "$subtree_test_count/sub proj" sub1 &&
229
+ (
230
+ cd "$subtree_test_count" &&
231
+ git fetch ./"sub proj" master &&
232
+ git subtree add --prefix="sub dir" FETCH_HEAD
233
+ ) &&
234
+ test_create_commit "$subtree_test_count/sub proj" sub2 &&
235
+ (
236
+ cd "$subtree_test_count" &&
237
+ git fetch ./"sub proj" master &&
238
+ git subtree merge --prefix="sub dir" --message="Merged changes from subproject using squash" --squash FETCH_HEAD &&
239
+ check_equal "$(last_commit_message)" "Merged changes from subproject using squash"
240
+ )
241
'
242
217
-test_expect_success 'merge new subproj history into subdir/ with --prefix and --message' '
218
- git subtree merge --prefix="sub dir" --message="Merged changes from subproject" FETCH_HEAD &&
219
- check_equal "$(last_commit_message)" "Merged changes from subproject" &&
220
- undo
243
+next_test
244
+test_expect_success 'merge the added subproj again, should do nothing' '
245
+ subtree_test_create_repo "$subtree_test_count" &&
246
+ subtree_test_create_repo "$subtree_test_count/sub proj" &&
247
+ test_create_commit "$subtree_test_count" main1 &&
248
+ test_create_commit "$subtree_test_count/sub proj" sub1 &&
249
+ (
250
+ cd "$subtree_test_count" &&
251
+ git fetch ./"sub proj" master &&
252
+ git subtree add --prefix="sub dir" FETCH_HEAD &&
253
+ # this shouldn not actually do anything, since FETCH_HEAD
254
+ # is already a parent
255
+ result=$(git merge -s ours -m "merge -s -ours" FETCH_HEAD) &&
256
+ check_equal "${result}" "Already up-to-date."
257
+ )
258
'
259
223
-test_expect_success 'merge new subproj history into subdir/ with --squash and --prefix and --message' '
224
- git subtree merge --prefix="sub dir" --message="Merged changes from subproject using squash" --squash FETCH_HEAD &&
225
- check_equal "$(last_commit_message)" "Merged changes from subproject using squash" &&
226
- undo
227
-'
260
+#
261
+# Tests for 'git subtree split'
262
+#
263
264
+next_test
265
test_expect_success 'split requires option --prefix' '
230
- echo "You must provide the --prefix option." > expected &&
231
- test_must_fail git subtree split > actual 2>&1 &&
232
- test_debug "printf '"'"'expected: '"'"'" &&
233
- test_debug "cat expected" &&
234
- test_debug "printf '"'"'actual: '"'"'" &&
235
- test_debug "cat actual" &&
236
- test_cmp expected actual &&
237
- rm -f expected actual
266
+ subtree_test_create_repo "$subtree_test_count" &&
267
+ subtree_test_create_repo "$subtree_test_count/sub proj" &&
268
+ test_create_commit "$subtree_test_count" main1 &&
269
+ test_create_commit "$subtree_test_count/sub proj" sub1 &&
270
+ (
271
+ cd "$subtree_test_count" &&
272
+ git fetch ./"sub proj" master &&
273
+ git subtree add --prefix="sub dir" FETCH_HEAD &&
274
+ echo "You must provide the --prefix option." > expected &&
275
+ test_must_fail git subtree split > actual 2>&1 &&
276
+ test_debug "printf '"expected: "'" &&
277
+ test_debug "cat expected" &&
278
+ test_debug "printf '"actual: "'" &&
279
+ test_debug "cat actual" &&
280
+ test_cmp expected actual
281
+ )
282
'
283
284
+next_test
285
test_expect_success 'split requires path given by option --prefix must exist' '
241
- echo "'\''non-existent-directory'\'' does not exist; use '\''git subtree add'\''" > expected &&
242
- test_must_fail git subtree split --prefix=non-existent-directory > actual 2>&1 &&
243
- test_debug "printf '"'"'expected: '"'"'" &&
244
- test_debug "cat expected" &&
245
- test_debug "printf '"'"'actual: '"'"'" &&
246
- test_debug "cat actual" &&
247
- test_cmp expected actual &&
248
- rm -f expected actual
249
-'
250
-
251
-test_expect_success 'check if --message works for split+rejoin' '
252
- spl1=''"$(git subtree split --annotate='"'*'"' --prefix "sub dir" --onto FETCH_HEAD --message "Split & rejoin" --rejoin)"'' &&
253
- check_equal ''"$(last_commit_message)"'' "Split & rejoin" &&
254
- undo
255
-'
256
-
257
-test_expect_success 'check split with --branch' '
258
- spl1=$(git subtree split --annotate='"'*'"' --prefix "sub dir" --onto FETCH_HEAD --message "Split & rejoin" --rejoin) &&
259
- undo &&
260
- git subtree split --annotate='"'*'"' --prefix "sub dir" --onto FETCH_HEAD --branch splitbr1 &&
261
- check_equal ''"$(git rev-parse splitbr1)"'' "$spl1"
262
-'
263
-
264
-test_expect_success 'check hash of split' '
265
- spl1=$(git subtree split --prefix "sub dir") &&
266
- git subtree split --prefix "sub dir" --branch splitbr1test &&
267
- check_equal ''"$(git rev-parse splitbr1test)"'' "$spl1" &&
268
- new_hash=$(git rev-parse splitbr1test~2) &&
269
- check_equal ''"$new_hash"'' "$subdir_hash"
270
-'
271
-
272
-test_expect_success 'check split with --branch for an existing branch' '
273
- spl1=''"$(git subtree split --annotate='"'*'"' --prefix "sub dir" --onto FETCH_HEAD --message "Split & rejoin" --rejoin)"'' &&
274
- undo &&
275
- git branch splitbr2 sub1 &&
276
- git subtree split --annotate='"'*'"' --prefix "sub dir" --onto FETCH_HEAD --branch splitbr2 &&
277
- check_equal ''"$(git rev-parse splitbr2)"'' "$spl1"
278
-'
279
-
280
-test_expect_success 'check split with --branch for an incompatible branch' '
281
- test_must_fail git subtree split --prefix "sub dir" --onto FETCH_HEAD --branch subdir
286
+ subtree_test_create_repo "$subtree_test_count" &&
287
+ subtree_test_create_repo "$subtree_test_count/sub proj" &&
288
+ test_create_commit "$subtree_test_count" main1 &&
289
+ test_create_commit "$subtree_test_count/sub proj" sub1 &&
290
+ (
291
+ cd "$subtree_test_count" &&
292
+ git fetch ./"sub proj" master &&
293
+ git subtree add --prefix="sub dir" FETCH_HEAD &&
294
+ echo "'\''non-existent-directory'\'' does not exist; use '\''git subtree add'\''" > expected &&
295
+ test_must_fail git subtree split --prefix=non-existent-directory > actual 2>&1 &&
296
+ test_debug "printf '"expected: "'" &&
297
+ test_debug "cat expected" &&
298
+ test_debug "printf '"actual: "'" &&
299
+ test_debug "cat actual" &&
300
+ test_cmp expected actual
301
+ )
302
'
303
304
+next_test
305
test_expect_success 'split sub dir/ with --rejoin' '
285
- spl1=$(git subtree split --prefix="sub dir" --annotate="*") &&
286
- git branch spl1 "$spl1" &&
287
- git subtree split --prefix="sub dir" --annotate="*" --rejoin &&
288
- check_equal "$(last_commit_message)" "Split '\''sub dir/'\'' into commit '\''$spl1'\''" &&
289
- undo
290
-'
306
+ subtree_test_create_repo "$subtree_test_count" &&
307
+ subtree_test_create_repo "$subtree_test_count/sub proj" &&
308
+ test_create_commit "$subtree_test_count" main1 &&
309
+ test_create_commit "$subtree_test_count/sub proj" sub1 &&
310
+ (
311
+ cd "$subtree_test_count" &&
312
+ git fetch ./"sub proj" master &&
313
+ git subtree add --prefix="sub dir" FETCH_HEAD
314
+ ) &&
315
+ test_create_commit "$subtree_test_count" "sub dir"/main-sub1 &&
316
+ test_create_commit "$subtree_test_count" main2 &&
317
+ test_create_commit "$subtree_test_count/sub proj" sub2 &&
318
+ test_create_commit "$subtree_test_count" "sub dir"/main-sub2 &&
319
+ (
320
+ cd "$subtree_test_count" &&
321
+ git fetch ./"sub proj" master &&
322
+ git subtree merge --prefix="sub dir" FETCH_HEAD &&
323
+ split_hash=$(git subtree split --prefix="sub dir" --annotate="*") &&
324
+ git subtree split --prefix="sub dir" --annotate="*" --rejoin &&
325
+ check_equal "$(last_commit_message)" "Split '\''sub dir/'\'' into commit '\''$split_hash'\''"
326
+ )
327
+ '
328
329
+next_test
330
test_expect_success 'split sub dir/ with --rejoin and --message' '
293
- git subtree split --prefix="sub dir" --message="Split & rejoin" --annotate="*" --rejoin &&
294
- check_equal "$(last_commit_message)" "Split & rejoin" &&
295
- undo
296
-'
297
-
298
-test_expect_success 'check split+rejoin+onto' '
299
- spl1=''"$(git subtree split --annotate='"'*'"' --prefix "sub dir" --onto FETCH_HEAD --message "Split & rejoin" --rejoin)"'' &&
300
- undo &&
301
- git subtree split --annotate='"'*'"' --prefix "sub dir" --onto FETCH_HEAD --rejoin &&
302
- check_equal ''"$(last_commit_message)"'' "Split '"'"'sub dir/'"'"' into commit '"'"'"$spl1"'"'"'"
303
-'
304
-
305
-test_expect_success 'add main-sub8' '
306
- create "sub dir/main-sub8" &&
307
- git commit -m "main-sub8"
308
-'
309
-
310
-# To the subproject!
311
-cd ./"sub proj"
312
-
313
-test_expect_success 'merge split into subproj' '
314
- git fetch .. spl1 &&
315
- git branch spl1 FETCH_HEAD &&
316
- git merge FETCH_HEAD
317
-'
318
-
319
-test_expect_success 'add sub9' '
320
- create sub9 &&
321
- git commit -m "sub9"
331
+ subtree_test_create_repo "$subtree_test_count" &&
332
+ subtree_test_create_repo "$subtree_test_count/sub proj" &&
333
+ test_create_commit "$subtree_test_count" main1 &&
334
+ test_create_commit "$subtree_test_count/sub proj" sub1 &&
335
+ (
336
+ cd "$subtree_test_count" &&
337
+ git fetch ./"sub proj" master &&
338
+ git subtree add --prefix="sub dir" FETCH_HEAD
339
+ ) &&
340
+ test_create_commit "$subtree_test_count" "sub dir"/main-sub1 &&
341
+ test_create_commit "$subtree_test_count" main2 &&
342
+ test_create_commit "$subtree_test_count/sub proj" sub2 &&
343
+ test_create_commit "$subtree_test_count" "sub dir"/main-sub2 &&
344
+ (
345
+ cd "$subtree_test_count" &&
346
+ git fetch ./"sub proj" master &&
347
+ git subtree merge --prefix="sub dir" FETCH_HEAD &&
348
+ git subtree split --prefix="sub dir" --message="Split & rejoin" --annotate="*" --rejoin &&
349
+ check_equal "$(last_commit_message)" "Split & rejoin"
350
+ )
351
'
352
324
-# Back to mainline
325
-cd ..
326
-
327
-test_expect_success 'split for sub8' '
328
- split2=''"$(git subtree split --annotate='"'*'"' --prefix "sub dir/" --rejoin)"'' &&
329
- git branch split2 "$split2"
353
+next_test
354
+test_expect_success 'split "sub dir"/ with --branch' '
355
+ subtree_test_create_repo "$subtree_test_count" &&
356
+ subtree_test_create_repo "$subtree_test_count/sub proj" &&
357
+ test_create_commit "$subtree_test_count" main1 &&
358
+ test_create_commit "$subtree_test_count/sub proj" sub1 &&
359
+ (
360
+ cd "$subtree_test_count" &&
361
+ git fetch ./"sub proj" master &&
362
+ git subtree add --prefix="sub dir" FETCH_HEAD
363
+ ) &&
364
+ test_create_commit "$subtree_test_count" "sub dir"/main-sub1 &&
365
+ test_create_commit "$subtree_test_count" main2 &&
366
+ test_create_commit "$subtree_test_count/sub proj" sub2 &&
367
+ test_create_commit "$subtree_test_count" "sub dir"/main-sub2 &&
368
+ (
369
+ cd "$subtree_test_count" &&
370
+ git fetch ./"sub proj" master &&
371
+ git subtree merge --prefix="sub dir" FETCH_HEAD &&
372
+ split_hash=$(git subtree split --prefix="sub dir" --annotate="*") &&
373
+ git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br &&
374
+ check_equal "$(git rev-parse subproj-br)" "$split_hash"
375
+ )
376
'
377
332
-test_expect_success 'add main-sub10' '
333
- create "sub dir/main-sub10" &&
334
- git commit -m "main-sub10"
378
+next_test
379
+test_expect_success 'check hash of split' '
380
+ subtree_test_create_repo "$subtree_test_count" &&
381
+ subtree_test_create_repo "$subtree_test_count/sub proj" &&
382
+ test_create_commit "$subtree_test_count" main1 &&
383
+ test_create_commit "$subtree_test_count/sub proj" sub1 &&
384
+ (
385
+ cd "$subtree_test_count" &&
386
+ git fetch ./"sub proj" master &&
387
+ git subtree add --prefix="sub dir" FETCH_HEAD
388
+ ) &&
389
+ test_create_commit "$subtree_test_count" "sub dir"/main-sub1 &&
390
+ test_create_commit "$subtree_test_count" main2 &&
391
+ test_create_commit "$subtree_test_count/sub proj" sub2 &&
392
+ test_create_commit "$subtree_test_count" "sub dir"/main-sub2 &&
393
+ (
394
+ cd "$subtree_test_count" &&
395
+ git fetch ./"sub proj" master &&
396
+ git subtree merge --prefix="sub dir" FETCH_HEAD &&
397
+ split_hash=$(git subtree split --prefix="sub dir" --annotate="*") &&
398
+ git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br &&
399
+ check_equal "$(git rev-parse subproj-br)" "$split_hash" &&
400
+ # Check hash of split
401
+ new_hash=$(git rev-parse subproj-br^2) &&
402
+ (
403
+ cd ./"sub proj" &&
404
+ subdir_hash=$(git rev-parse HEAD) &&
405
+ check_equal ''"$new_hash"'' "$subdir_hash"
406
+ )
407
+ )
408
'
409
337
-test_expect_success 'split for sub10' '
338
- spl3=''"$(git subtree split --annotate='"'*'"' --prefix "sub dir" --rejoin)"'' &&
339
- git branch spl3 "$spl3"
410
+next_test
411
+test_expect_success 'split "sub dir"/ with --branch for an existing branch' '
412
+ subtree_test_create_repo "$subtree_test_count" &&
413
+ subtree_test_create_repo "$subtree_test_count/sub proj" &&
414
+ test_create_commit "$subtree_test_count" main1 &&
415
+ test_create_commit "$subtree_test_count/sub proj" sub1 &&
416
+ (
417
+ cd "$subtree_test_count" &&
418
+ git fetch ./"sub proj" master &&
419
+ git branch subproj-br FETCH_HEAD &&
420
+ git subtree add --prefix="sub dir" FETCH_HEAD
421
+ ) &&
422
+ test_create_commit "$subtree_test_count" "sub dir"/main-sub1 &&
423
+ test_create_commit "$subtree_test_count" main2 &&
424
+ test_create_commit "$subtree_test_count/sub proj" sub2 &&
425
+ test_create_commit "$subtree_test_count" "sub dir"/main-sub2 &&
426
+ (
427
+ cd "$subtree_test_count" &&
428
+ git fetch ./"sub proj" master &&
429
+ git subtree merge --prefix="sub dir" FETCH_HEAD &&
430
+ split_hash=$(git subtree split --prefix="sub dir" --annotate="*") &&
431
+ git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br &&
432
+ check_equal "$(git rev-parse subproj-br)" "$split_hash"
433
+ )
434
'
435
342
-# To the subproject!
343
-cd ./"sub proj"
344
-
345
-test_expect_success 'merge split into subproj' '
346
- git fetch .. spl3 &&
347
- git branch spl3 FETCH_HEAD &&
348
- git merge FETCH_HEAD &&
349
- git branch subproj-merge-spl3
436
+next_test
437
+test_expect_success 'split "sub dir"/ with --branch for an incompatible branch' '
438
+ subtree_test_create_repo "$subtree_test_count" &&
439
+ subtree_test_create_repo "$subtree_test_count/sub proj" &&
440
+ test_create_commit "$subtree_test_count" main1 &&
441
+ test_create_commit "$subtree_test_count/sub proj" sub1 &&
442
+ (
443
+ cd "$subtree_test_count" &&
444
+ git branch init HEAD &&
445
+ git fetch ./"sub proj" master &&
446
+ git subtree add --prefix="sub dir" FETCH_HEAD
447
+ ) &&
448
+ test_create_commit "$subtree_test_count" "sub dir"/main-sub1 &&
449
+ test_create_commit "$subtree_test_count" main2 &&
450
+ test_create_commit "$subtree_test_count/sub proj" sub2 &&
451
+ test_create_commit "$subtree_test_count" "sub dir"/main-sub2 &&
452
+ (
453
+ cd "$subtree_test_count" &&
454
+ git fetch ./"sub proj" master &&
455
+ git subtree merge --prefix="sub dir" FETCH_HEAD &&
456
+ test_must_fail git subtree split --prefix="sub dir" --branch init
457
+ )
458
'
459
352
-chkm="main4
353
-main6"
354
-
355
-chkms="main-sub10
356
-main-sub5
357
-main-sub7
358
-main-sub8"
359
-
360
-chkms_sub=$(cat <<TXT | sed 's,^,sub dir/,'
361
-$chkms
362
-TXT
363
-)
460
+#
461
+# Validity checking
462
+#
463
365
-chks="sub1
464
+next_test
465
+test_expect_success 'make sure exactly the right set of files ends up in the subproj' '
466
+ subtree_test_create_repo "$subtree_test_count" &&
467
+ subtree_test_create_repo "$subtree_test_count/sub proj" &&
468
+ test_create_commit "$subtree_test_count" main1 &&
469
+ test_create_commit "$subtree_test_count/sub proj" sub1 &&
470
+ (
471
+ cd "$subtree_test_count" &&
472
+ git fetch ./"sub proj" master &&
473
+ git subtree add --prefix="sub dir" FETCH_HEAD
474
+ ) &&
475
+ test_create_commit "$subtree_test_count" "sub dir"/main-sub1 &&
476
+ test_create_commit "$subtree_test_count" main2 &&
477
+ test_create_commit "$subtree_test_count/sub proj" sub2 &&
478
+ test_create_commit "$subtree_test_count" "sub dir"/main-sub2 &&
479
+ (
480
+ cd "$subtree_test_count" &&
481
+ git fetch ./"sub proj" master &&
482
+ git subtree merge --prefix="sub dir" FETCH_HEAD &&
483
+ git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
484
+ ) &&
485
+ test_create_commit "$subtree_test_count/sub proj" sub3 &&
486
+ test_create_commit "$subtree_test_count" "sub dir"/main-sub3 &&
487
+ (
488
+ cd "$subtree_test_count/sub proj" &&
489
+ git fetch .. subproj-br &&
490
+ git merge FETCH_HEAD
491
+ ) &&
492
+ test_create_commit "$subtree_test_count/sub proj" sub4 &&
493
+ (
494
+ cd "$subtree_test_count" &&
495
+ git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
496
+ ) &&
497
+ test_create_commit "$subtree_test_count" "sub dir"/main-sub4 &&
498
+ (
499
+ cd "$subtree_test_count" &&
500
+ git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
501
+ ) &&
502
+ (
503
+ cd "$subtree_test_count/sub proj" &&
504
+ git fetch .. subproj-br &&
505
+ git merge FETCH_HEAD &&
506
+
507
+ chks="sub1
508
sub2
509
sub3
368
-sub9"
369
-
370
-chks_sub=$(cat <<TXT | sed 's,^,sub dir/,'
510
+sub4" &&
511
+ chks_sub=$(cat <<TXT | sed '\''s,^,sub dir/,'\''
512
$chks
513
TXT
373
-)
514
+) &&
515
+ chkms="main-sub1
516
+main-sub2
517
+main-sub3
518
+main-sub4" &&
519
+ chkms_sub=$(cat <<TXT | sed '\''s,^,sub dir/,'\''
520
+$chkms
521
+TXT
522
+) &&
523
375
-test_expect_success 'make sure exactly the right set of files ends up in the subproj' '
376
- subfiles="$(git ls-files)" &&
377
- check_equal "$subfiles" "$chkms
524
+ subfiles=$(git ls-files) &&
525
+ check_equal "$subfiles" "$chkms
526
$chks"
527
+ )
528
'
529
381
-test_expect_success 'make sure the subproj history *only* contains commits that affect the subdir' '
382
- allchanges=''"$(git log --name-only --pretty=format:'"''"' | sort | sed "/^$/d")"'' &&
383
- check_equal "$allchanges" "$chkms
530
+next_test
531
+test_expect_success 'make sure the subproj *only* contains commits that affect the "sub dir"' '
532
+ subtree_test_create_repo "$subtree_test_count" &&
533
+ subtree_test_create_repo "$subtree_test_count/sub proj" &&
534
+ test_create_commit "$subtree_test_count" main1 &&
535
+ test_create_commit "$subtree_test_count/sub proj" sub1 &&
536
+ (
537
+ cd "$subtree_test_count" &&
538
+ git fetch ./"sub proj" master &&
539
+ git subtree add --prefix="sub dir" FETCH_HEAD
540
+ ) &&
541
+ test_create_commit "$subtree_test_count" "sub dir"/main-sub1 &&
542
+ test_create_commit "$subtree_test_count" main2 &&
543
+ test_create_commit "$subtree_test_count/sub proj" sub2 &&
544
+ test_create_commit "$subtree_test_count" "sub dir"/main-sub2 &&
545
+ (
546
+ cd "$subtree_test_count" &&
547
+ git fetch ./"sub proj" master &&
548
+ git subtree merge --prefix="sub dir" FETCH_HEAD &&
549
+ git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
550
+ ) &&
551
+ test_create_commit "$subtree_test_count/sub proj" sub3 &&
552
+ test_create_commit "$subtree_test_count" "sub dir"/main-sub3 &&
553
+ (
554
+ cd "$subtree_test_count/sub proj" &&
555
+ git fetch .. subproj-br &&
556
+ git merge FETCH_HEAD
557
+ ) &&
558
+ test_create_commit "$subtree_test_count/sub proj" sub4 &&
559
+ (
560
+ cd "$subtree_test_count" &&
561
+ git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
562
+ ) &&
563
+ test_create_commit "$subtree_test_count" "sub dir"/main-sub4 &&
564
+ (
565
+ cd "$subtree_test_count" &&
566
+ git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
567
+ ) &&
568
+ (
569
+ cd "$subtree_test_count/sub proj" &&
570
+ git fetch .. subproj-br &&
571
+ git merge FETCH_HEAD &&
572
+
573
+ chks="sub1
574
+sub2
575
+sub3
576
+sub4" &&
577
+ chks_sub=$(cat <<TXT | sed '\''s,^,sub dir/,'\''
578
+$chks
579
+TXT
580
+) &&
581
+ chkms="main-sub1
582
+main-sub2
583
+main-sub3
584
+main-sub4" &&
585
+ chkms_sub=$(cat <<TXT | sed '\''s,^,sub dir/,'\''
586
+$chkms
587
+TXT
588
+) &&
589
+ allchanges=$(git log --name-only --pretty=format:"" | sort | sed "/^$/d") &&
590
+ check_equal "$allchanges" "$chkms
591
$chks"
592
+ )
593
'
594
387
-# Back to mainline
388
-cd ..
389
-
390
-test_expect_success 'pull from subproj' '
391
- git fetch ./"sub proj" subproj-merge-spl3 &&
392
- git branch subproj-merge-spl3 FETCH_HEAD &&
393
- git subtree pull --prefix="sub dir" ./"sub proj" subproj-merge-spl3
394
-'
395
-
595
+next_test
596
test_expect_success 'make sure exactly the right set of files ends up in the mainline' '
397
- mainfiles=$(git ls-files) &&
398
- check_equal "$mainfiles" "$chkm
597
+ subtree_test_create_repo "$subtree_test_count" &&
598
+ subtree_test_create_repo "$subtree_test_count/sub proj" &&
599
+ test_create_commit "$subtree_test_count" main1 &&
600
+ test_create_commit "$subtree_test_count/sub proj" sub1 &&
601
+ (
602
+ cd "$subtree_test_count" &&
603
+ git fetch ./"sub proj" master &&
604
+ git subtree add --prefix="sub dir" FETCH_HEAD
605
+ ) &&
606
+ test_create_commit "$subtree_test_count" "sub dir"/main-sub1 &&
607
+ test_create_commit "$subtree_test_count" main2 &&
608
+ test_create_commit "$subtree_test_count/sub proj" sub2 &&
609
+ test_create_commit "$subtree_test_count" "sub dir"/main-sub2 &&
610
+ (
611
+ cd "$subtree_test_count" &&
612
+ git fetch ./"sub proj" master &&
613
+ git subtree merge --prefix="sub dir" FETCH_HEAD &&
614
+ git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
615
+ ) &&
616
+ test_create_commit "$subtree_test_count/sub proj" sub3 &&
617
+ test_create_commit "$subtree_test_count" "sub dir"/main-sub3 &&
618
+ (
619
+ cd "$subtree_test_count/sub proj" &&
620
+ git fetch .. subproj-br &&
621
+ git merge FETCH_HEAD
622
+ ) &&
623
+ test_create_commit "$subtree_test_count/sub proj" sub4 &&
624
+ (
625
+ cd "$subtree_test_count" &&
626
+ git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
627
+ ) &&
628
+ test_create_commit "$subtree_test_count" "sub dir"/main-sub4 &&
629
+ (
630
+ cd "$subtree_test_count" &&
631
+ git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
632
+ ) &&
633
+ (
634
+ cd "$subtree_test_count/sub proj" &&
635
+ git fetch .. subproj-br &&
636
+ git merge FETCH_HEAD
637
+ ) &&
638
+ (
639
+ cd "$subtree_test_count" &&
640
+ git subtree pull --prefix="sub dir" ./"sub proj" master &&
641
+
642
+ chkm="main1
643
+main2" &&
644
+ chks="sub1
645
+sub2
646
+sub3
647
+sub4" &&
648
+ chks_sub=$(cat <<TXT | sed '\''s,^,sub dir/,'\''
649
+$chks
650
+TXT
651
+) &&
652
+ chkms="main-sub1
653
+main-sub2
654
+main-sub3
655
+main-sub4" &&
656
+ chkms_sub=$(cat <<TXT | sed '\''s,^,sub dir/,'\''
657
+$chkms
658
+TXT
659
+) &&
660
+ mainfiles=$(git ls-files) &&
661
+ check_equal "$mainfiles" "$chkm
662
$chkms_sub
663
$chks_sub"
664
+)
665
'
666
667
+next_test
668
test_expect_success 'make sure each filename changed exactly once in the entire history' '
404
- # main-sub?? and sub dir/main-sub?? both change, because those are the
405
- # changes that were split into their own history. And sub dir/sub?? never
406
- # change, since they were *only* changed in the subtree branch.
407
- allchanges=''"$(git log --name-only --pretty=format:'"''"' | sort | sed "/^$/d")"'' &&
408
- expected=''"$(cat <<TXT | sort
669
+ subtree_test_create_repo "$subtree_test_count" &&
670
+ subtree_test_create_repo "$subtree_test_count/sub proj" &&
671
+ test_create_commit "$subtree_test_count" main1 &&
672
+ test_create_commit "$subtree_test_count/sub proj" sub1 &&
673
+ (
674
+ cd "$subtree_test_count" &&
675
+ git config log.date relative
676
+ git fetch ./"sub proj" master &&
677
+ git subtree add --prefix="sub dir" FETCH_HEAD
678
+ ) &&
679
+ test_create_commit "$subtree_test_count" "sub dir"/main-sub1 &&
680
+ test_create_commit "$subtree_test_count" main2 &&
681
+ test_create_commit "$subtree_test_count/sub proj" sub2 &&
682
+ test_create_commit "$subtree_test_count" "sub dir"/main-sub2 &&
683
+ (
684
+ cd "$subtree_test_count" &&
685
+ git fetch ./"sub proj" master &&
686
+ git subtree merge --prefix="sub dir" FETCH_HEAD &&
687
+ git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
688
+ ) &&
689
+ test_create_commit "$subtree_test_count/sub proj" sub3 &&
690
+ test_create_commit "$subtree_test_count" "sub dir"/main-sub3 &&
691
+ (
692
+ cd "$subtree_test_count/sub proj" &&
693
+ git fetch .. subproj-br &&
694
+ git merge FETCH_HEAD
695
+ ) &&
696
+ test_create_commit "$subtree_test_count/sub proj" sub4 &&
697
+ (
698
+ cd "$subtree_test_count" &&
699
+ git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
700
+ ) &&
701
+ test_create_commit "$subtree_test_count" "sub dir"/main-sub4 &&
702
+ (
703
+ cd "$subtree_test_count" &&
704
+ git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
705
+ ) &&
706
+ (
707
+ cd "$subtree_test_count/sub proj" &&
708
+ git fetch .. subproj-br &&
709
+ git merge FETCH_HEAD
710
+ ) &&
711
+ (
712
+ cd "$subtree_test_count" &&
713
+ git subtree pull --prefix="sub dir" ./"sub proj" master &&
714
+
715
+ chkm="main1
716
+main2" &&
717
+ chks="sub1
718
+sub2
719
+sub3
720
+sub4" &&
721
+ chks_sub=$(cat <<TXT | sed '\''s,^,sub dir/,'\''
722
+$chks
723
+TXT
724
+) &&
725
+ chkms="main-sub1
726
+main-sub2
727
+main-sub3
728
+main-sub4" &&
729
+ chkms_sub=$(cat <<TXT | sed '\''s,^,sub dir/,'\''
730
+$chkms
731
+TXT
732
+) &&
733
+
734
+ # main-sub?? and /"sub dir"/main-sub?? both change, because those are the
735
+ # changes that were split into their own history. And "sub dir"/sub?? never
736
+ # change, since they were *only* changed in the subtree branch.
737
+ allchanges=$(git log --name-only --pretty=format:"" | sort | sed "/^$/d") &&
738
+ expected=''"$(cat <<TXT | sort
739
$chkms
740
$chkm
741
$chks
742
$chkms_sub
743
TXT
744
)"'' &&
415
- check_equal "$allchanges" "$expected"
745
+ check_equal "$allchanges" "$expected"
746
+ )
747
'
748
749
+next_test
750
test_expect_success 'make sure the --rejoin commits never make it into subproj' '
419
- check_equal "$(git log --pretty=format:"%s" HEAD^2 | grep -i split)" ""
751
+ subtree_test_create_repo "$subtree_test_count" &&
752
+ subtree_test_create_repo "$subtree_test_count/sub proj" &&
753
+ test_create_commit "$subtree_test_count" main1 &&
754
+ test_create_commit "$subtree_test_count/sub proj" sub1 &&
755
+ (
756
+ cd "$subtree_test_count" &&
757
+ git fetch ./"sub proj" master &&
758
+ git subtree add --prefix="sub dir" FETCH_HEAD
759
+ ) &&
760
+ test_create_commit "$subtree_test_count" "sub dir"/main-sub1 &&
761
+ test_create_commit "$subtree_test_count" main2 &&
762
+ test_create_commit "$subtree_test_count/sub proj" sub2 &&
763
+ test_create_commit "$subtree_test_count" "sub dir"/main-sub2 &&
764
+ (
765
+ cd "$subtree_test_count" &&
766
+ git fetch ./"sub proj" master &&
767
+ git subtree merge --prefix="sub dir" FETCH_HEAD &&
768
+ git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
769
+ ) &&
770
+ test_create_commit "$subtree_test_count/sub proj" sub3 &&
771
+ test_create_commit "$subtree_test_count" "sub dir"/main-sub3 &&
772
+ (
773
+ cd "$subtree_test_count/sub proj" &&
774
+ git fetch .. subproj-br &&
775
+ git merge FETCH_HEAD
776
+ ) &&
777
+ test_create_commit "$subtree_test_count/sub proj" sub4 &&
778
+ (
779
+ cd "$subtree_test_count" &&
780
+ git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
781
+ ) &&
782
+ test_create_commit "$subtree_test_count" "sub dir"/main-sub4 &&
783
+ (
784
+ cd "$subtree_test_count" &&
785
+ git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
786
+ ) &&
787
+ (
788
+ cd "$subtree_test_count/sub proj" &&
789
+ git fetch .. subproj-br &&
790
+ git merge FETCH_HEAD
791
+ ) &&
792
+ (
793
+ cd "$subtree_test_count" &&
794
+ git subtree pull --prefix="sub dir" ./"sub proj" master &&
795
+ check_equal "$(git log --pretty=format:"%s" HEAD^2 | grep -i split)" ""
796
+ )
797
'
798
799
+next_test
800
test_expect_success 'make sure no "git subtree" tagged commits make it into subproj' '
423
- # They are meaningless to subproj since one side of the merge refers to the mainline
424
- check_equal "$(git log --pretty=format:"%s%n%b" HEAD^2 | grep "git-subtree.*:")" ""
425
-'
426
-
427
-# prepare second pair of repositories
428
-mkdir test2
429
-cd test2
430
-
431
-test_expect_success 'init main' '
432
- test_create_repo main
433
-'
434
-
435
-cd main
436
-
437
-test_expect_success 'add main1' '
438
- create main1 &&
439
- git commit -m "main1"
440
-'
441
-
442
-cd ..
443
-
444
-test_expect_success 'init sub' '
445
- test_create_repo sub
446
-'
447
-
448
-cd sub
449
-
450
-test_expect_success 'add sub2' '
451
- create sub2 &&
452
- git commit -m "sub2"
453
-'
454
-
455
-cd ../main
456
-
457
-# check if split can find proper base without --onto
458
-
459
-test_expect_success 'add sub as subdir in main' '
460
- git fetch ../sub master &&
461
- git branch sub2 FETCH_HEAD &&
462
- git subtree add --prefix "sub dir" sub2
463
-'
464
-
465
-cd ../sub
466
-
467
-test_expect_success 'add sub3' '
468
- create sub3 &&
469
- git commit -m "sub3"
470
-'
471
-
472
-cd ../main
473
-
474
-test_expect_success 'merge from sub' '
475
- git fetch ../sub master &&
476
- git branch sub3 FETCH_HEAD &&
477
- git subtree merge --prefix "sub dir" sub3
478
-'
479
-
480
-test_expect_success 'add main-sub4' '
481
- create "sub dir/main-sub4" &&
482
- git commit -m "main-sub4"
483
-'
484
-
485
-test_expect_success 'split for main-sub4 without --onto' '
486
- git subtree split --prefix "sub dir" --branch mainsub4
801
+ subtree_test_create_repo "$subtree_test_count" &&
802
+ subtree_test_create_repo "$subtree_test_count/sub proj" &&
803
+ test_create_commit "$subtree_test_count" main1 &&
804
+ test_create_commit "$subtree_test_count/sub proj" sub1 &&
805
+ (
806
+ cd "$subtree_test_count" &&
807
+ git fetch ./"sub proj" master &&
808
+ git subtree add --prefix="sub dir" FETCH_HEAD
809
+ ) &&
810
+ test_create_commit "$subtree_test_count" "sub dir"/main-sub1 &&
811
+ test_create_commit "$subtree_test_count" main2 &&
812
+ test_create_commit "$subtree_test_count/sub proj" sub2 &&
813
+ test_create_commit "$subtree_test_count" "sub dir"/main-sub2 &&
814
+ (
815
+ cd "$subtree_test_count" &&
816
+ git fetch ./"sub proj" master &&
817
+ git subtree merge --prefix="sub dir" FETCH_HEAD &&
818
+ git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
819
+ ) &&
820
+ test_create_commit "$subtree_test_count/sub proj" sub3 &&
821
+ test_create_commit "$subtree_test_count" "sub dir"/main-sub3 &&
822
+ (
823
+ cd "$subtree_test_count/sub proj" &&
824
+ git fetch .. subproj-br &&
825
+ git merge FETCH_HEAD
826
+ ) &&
827
+ test_create_commit "$subtree_test_count/sub proj" sub4 &&
828
+ (
829
+ cd "$subtree_test_count" &&
830
+ git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
831
+ ) &&
832
+ test_create_commit "$subtree_test_count" "sub dir"/main-sub4 &&
833
+ (
834
+ cd "$subtree_test_count" &&
835
+ git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
836
+ ) &&
837
+ (
838
+ cd "$subtree_test_count/sub proj" &&
839
+ git fetch .. subproj-br &&
840
+ git merge FETCH_HEAD
841
+ ) &&
842
+ (
843
+ cd "$subtree_test_count" &&
844
+ git subtree pull --prefix="sub dir" ./"sub proj" master &&
845
+
846
+ # They are meaningless to subproj since one side of the merge refers to the mainline
847
+ check_equal "$(git log --pretty=format:"%s%n%b" HEAD^2 | grep "git-subtree.*:")" ""
848
+ )
849
'
850
489
-# At this point, the new commit parent should be sub3. If it is not,
490
-# something went wrong (the "newparent" of "master~" commit should
491
-# have been sub3, but it was not, because its cache was not set to
492
-# itself).
493
-
494
-test_expect_success 'check that the commit parent is sub3' '
495
- check_equal "$(git log --pretty=format:%P -1 mainsub4)" "$(git rev-parse sub3)"
496
-'
851
+#
852
+# A new set of tests
853
+#
854
498
-test_expect_success 'add main-sub5' '
499
- mkdir subdir2 &&
500
- create subdir2/main-sub5 &&
501
- git commit -m "main-sub5"
855
+next_test
856
+test_expect_success 'make sure "git subtree split" find the correct parent' '
857
+ subtree_test_create_repo "$subtree_test_count" &&
858
+ subtree_test_create_repo "$subtree_test_count/sub proj" &&
859
+ test_create_commit "$subtree_test_count" main1 &&
860
+ test_create_commit "$subtree_test_count/sub proj" sub1 &&
861
+ (
862
+ cd "$subtree_test_count" &&
863
+ git fetch ./"sub proj" master &&
864
+ git subtree add --prefix="sub dir" FETCH_HEAD
865
+ ) &&
866
+ test_create_commit "$subtree_test_count/sub proj" sub2 &&
867
+ (
868
+ cd "$subtree_test_count" &&
869
+ git fetch ./"sub proj" master &&
870
+ git branch subproj-ref FETCH_HEAD &&
871
+ git subtree merge --prefix="sub dir" FETCH_HEAD
872
+ ) &&
873
+ test_create_commit "$subtree_test_count" "sub dir"/main-sub1 &&
874
+ (
875
+ cd "$subtree_test_count" &&
876
+ git subtree split --prefix="sub dir" --branch subproj-br &&
877
+
878
+ # at this point, the new commit parent should be subproj-ref, if it is
879
+ # not, something went wrong (the "newparent" of "master~" commit should
880
+ # have been sub2, but it was not, because its cache was not set to
881
+ # itself)
882
+ check_equal "$(git log --pretty=format:%P -1 subproj-br)" "$(git rev-parse subproj-ref)"
883
+ )
884
'
885
504
-test_expect_success 'split for main-sub5 without --onto' '
505
- # also test that we still can split out an entirely new subtree
506
- # if the parent of the first commit in the tree is not empty,
507
- # then the new subtree has accidentally been attached to something
508
- git subtree split --prefix subdir2 --branch mainsub5 &&
509
- check_equal ''"$(git log --pretty=format:%P -1 mainsub5)"'' ""
886
+next_test
887
+test_expect_success 'split a new subtree without --onto option' '
888
+ subtree_test_create_repo "$subtree_test_count" &&
889
+ subtree_test_create_repo "$subtree_test_count/sub proj" &&
890
+ test_create_commit "$subtree_test_count" main1 &&
891
+ test_create_commit "$subtree_test_count/sub proj" sub1 &&
892
+ (
893
+ cd "$subtree_test_count" &&
894
+ git fetch ./"sub proj" master &&
895
+ git subtree add --prefix="sub dir" FETCH_HEAD
896
+ ) &&
897
+ test_create_commit "$subtree_test_count/sub proj" sub2 &&
898
+ (
899
+ cd "$subtree_test_count" &&
900
+ git fetch ./"sub proj" master &&
901
+ git subtree merge --prefix="sub dir" FETCH_HEAD
902
+ ) &&
903
+ test_create_commit "$subtree_test_count" "sub dir"/main-sub1 &&
904
+ (
905
+ cd "$subtree_test_count" &&
906
+ git subtree split --prefix="sub dir" --branch subproj-br
907
+ ) &&
908
+ mkdir "$subtree_test_count"/"sub dir2" &&
909
+ test_create_commit "$subtree_test_count" "sub dir2"/main-sub2 &&
910
+ (
911
+ cd "$subtree_test_count" &&
912
+
913
+ # also test that we still can split out an entirely new subtree
914
+ # if the parent of the first commit in the tree is not empty,
915
+ # then the new subtree has accidently been attached to something
916
+ git subtree split --prefix="sub dir2" --branch subproj2-br &&
917
+ check_equal "$(git log --pretty=format:%P -1 subproj2-br)" ""
918
+ )
919
'
920
921
+next_test
922
test_expect_success 'verify one file change per commit' '
513
- x= &&
514
- list=''"$(git log --pretty=format:'"'commit: %H'"' | join_commits)"'' &&
515
-# test_debug "echo HERE" &&
516
-# test_debug "echo ''"$list"''" &&
517
- git log --pretty=format:'"'commit: %H'"' | join_commits |
518
- ( while read commit a b; do
519
- test_debug "echo Verifying commit "''"$commit"''
520
- test_debug "echo a: "''"$a"''
521
- test_debug "echo b: "''"$b"''
522
- check_equal "$b" ""
523
- x=1
524
- done
525
- check_equal "$x" "1"
923
+ subtree_test_create_repo "$subtree_test_count" &&
924
+ subtree_test_create_repo "$subtree_test_count/sub proj" &&
925
+ test_create_commit "$subtree_test_count" main1 &&
926
+ test_create_commit "$subtree_test_count/sub proj" sub1 &&
927
+ (
928
+ cd "$subtree_test_count" &&
929
+ git fetch ./"sub proj" master &&
930
+ git branch sub1 FETCH_HEAD &&
931
+ git subtree add --prefix="sub dir" sub1
932
+ ) &&
933
+ test_create_commit "$subtree_test_count/sub proj" sub2 &&
934
+ (
935
+ cd "$subtree_test_count" &&
936
+ git fetch ./"sub proj" master &&
937
+ git subtree merge --prefix="sub dir" FETCH_HEAD
938
+ ) &&
939
+ test_create_commit "$subtree_test_count" "sub dir"/main-sub1 &&
940
+ (
941
+ cd "$subtree_test_count" &&
942
+ git subtree split --prefix="sub dir" --branch subproj-br
943
+ ) &&
944
+ mkdir "$subtree_test_count"/"sub dir2" &&
945
+ test_create_commit "$subtree_test_count" "sub dir2"/main-sub2 &&
946
+ (
947
+ cd "$subtree_test_count" &&
948
+ git subtree split --prefix="sub dir2" --branch subproj2-br &&
949
+
950
+ x= &&
951
+ git log --pretty=format:"commit: %H" | join_commits |
952
+ (
953
+ while read commit a b; do
954
+ test_debug "echo Verifying commit $commit"
955
+ test_debug "echo a: $a"
956
+ test_debug "echo b: $b"
957
+ check_equal "$b" ""
958
+ x=1
959
+ done
960
+ check_equal "$x" 1
961
+ )
962
)
963
'
964
529
-# test push
530
-
531
-cd ../..
532
-
533
-mkdir -p test-push
534
-
535
-cd test-push
536
-
537
-test_expect_success 'init main' '
538
- test_create_repo main
539
-'
540
-
541
-test_expect_success 'init sub' '
542
- test_create_repo "sub project"
543
-'
544
-
545
-cd ./"sub project"
546
-
547
-test_expect_success 'add subproject' '
548
- create "sub project" &&
549
- git commit -m "Sub project: 1" &&
550
- git branch sub-branch-1
551
-'
552
-
553
-cd ../main
554
-
555
-test_expect_success 'make first commit and add subproject' '
556
- create "main-1" &&
557
- git commit -m "main: 1" &&
558
- git subtree add "../sub project" --prefix "sub dir" --message "Added subproject" sub-branch-1 &&
559
- check_equal "$(last_commit_message)" "Added subproject"
560
-'
561
-
562
-test_expect_success 'make second commit to a subproject file and push it into a sub project' '
563
- create "sub dir/sub1" &&
564
- git commit -m "Sub project: 2" &&
565
- git subtree push "../sub project" --prefix "sub dir" sub-branch-1
566
-'
567
-
568
-cd ../"sub project"
569
-
570
-test_expect_success 'Test second commit is pushed' '
571
- git checkout sub-branch-1 &&
572
- check_equal "$(last_commit_message)" "Sub project: 2"
965
+next_test
966
+test_expect_success 'push split to subproj' '
967
+ subtree_test_create_repo "$subtree_test_count" &&
968
+ subtree_test_create_repo "$subtree_test_count/sub proj" &&
969
+ test_create_commit "$subtree_test_count" main1 &&
970
+ test_create_commit "$subtree_test_count/sub proj" sub1 &&
971
+ (
972
+ cd "$subtree_test_count" &&
973
+ git fetch ./"sub proj" master &&
974
+ git subtree add --prefix="sub dir" FETCH_HEAD
975
+ ) &&
976
+ test_create_commit "$subtree_test_count" "sub dir"/main-sub1 &&
977
+ test_create_commit "$subtree_test_count" main2 &&
978
+ test_create_commit "$subtree_test_count/sub proj" sub2 &&
979
+ test_create_commit "$subtree_test_count" "sub dir"/main-sub2 &&
980
+ (
981
+ cd $subtree_test_count/"sub proj" &&
982
+ git branch sub-branch-1 &&
983
+ cd .. &&
984
+ git fetch ./"sub proj" master &&
985
+ git subtree merge --prefix="sub dir" FETCH_HEAD
986
+ ) &&
987
+ test_create_commit "$subtree_test_count" "sub dir"/main-sub3 &&
988
+ (
989
+ cd "$subtree_test_count" &&
990
+ git subtree push ./"sub proj" --prefix "sub dir" sub-branch-1 &&
991
+ cd ./"sub proj" &&
992
+ git checkout sub-branch-1 &&
993
+ check_equal "$(last_commit_message)" "sub dir/main-sub3"
994
+ )
995
'
996
997
test_done