@@ -32,25 +32,6 @@ check_equal()
32
32
fi
33
33
}
34
34
35
- fixnl ()
36
- {
37
- t=" "
38
- while read x; do
39
- t=" $t$x "
40
- done
41
- echo $t
42
- }
43
-
44
- multiline ()
45
- {
46
- while read x; do
47
- set -- $x
48
- for d in " $@ " ; do
49
- echo " $d "
50
- done
51
- done
52
- }
53
-
54
35
undo ()
55
36
{
56
37
git reset --hard HEAD~
@@ -62,11 +43,11 @@ last_commit_message()
62
43
}
63
44
64
45
test_expect_success ' init subproj' '
65
- test_create_repo subproj
46
+ test_create_repo "sub proj"
66
47
'
67
48
68
49
# To the subproject!
69
- cd subproj
50
+ cd ./ " sub proj "
70
51
71
52
test_expect_success ' add sub1' '
72
53
create sub1 &&
@@ -106,39 +87,39 @@ test_expect_success 'add main4' '
106
87
'
107
88
108
89
test_expect_success ' fetch subproj history' '
109
- git fetch ./subproj sub1 &&
90
+ git fetch ./"sub proj" sub1 &&
110
91
git branch sub1 FETCH_HEAD
111
92
'
112
93
113
94
test_expect_success ' no subtree exists in main tree' '
114
- test_must_fail git subtree merge --prefix=subdir sub1
95
+ test_must_fail git subtree merge --prefix="sub dir" sub1
115
96
'
116
97
117
98
test_expect_success ' no pull from non-existant subtree' '
118
- test_must_fail git subtree pull --prefix=subdir ./subproj sub1
99
+ test_must_fail git subtree pull --prefix="sub dir" ./"sub proj" sub1
119
100
'
120
101
121
102
test_expect_success ' check if --message works for add' '
122
- git subtree add --prefix=subdir --message="Added subproject" sub1 &&
103
+ git subtree add --prefix="sub dir" --message="Added subproject" sub1 &&
123
104
check_equal ' ' "$(last_commit_message)"' ' "Added subproject" &&
124
105
undo
125
106
'
126
107
127
108
test_expect_success ' check if --message works as -m and --prefix as -P' '
128
- git subtree add -P subdir -m "Added subproject using git subtree" sub1 &&
109
+ git subtree add -P "sub dir" -m "Added subproject using git subtree" sub1 &&
129
110
check_equal ' ' "$(last_commit_message)"' ' "Added subproject using git subtree" &&
130
111
undo
131
112
'
132
113
133
114
test_expect_success ' check if --message works with squash too' '
134
- git subtree add -P subdir -m "Added subproject with squash" --squash sub1 &&
115
+ git subtree add -P "sub dir" -m "Added subproject with squash" --squash sub1 &&
135
116
check_equal ' ' "$(last_commit_message)"' ' "Added subproject with squash" &&
136
117
undo
137
118
'
138
119
139
120
test_expect_success ' add subproj to mainline' '
140
- git subtree add --prefix=subdir / FETCH_HEAD &&
141
- check_equal ' ' "$(last_commit_message)"' ' "Add ' " 'subdir /'" ' from commit ' " '" ' ' ' "$(git rev-parse sub1)"' ' ' " '" ' "
121
+ git subtree add --prefix="sub dir" / FETCH_HEAD &&
122
+ check_equal ' ' "$(last_commit_message)"' ' "Add ' " 'sub dir /'" ' from commit ' " '" ' ' ' "$(git rev-parse sub1)"' ' ' " '" ' "
142
123
'
143
124
144
125
# this shouldn't actually do anything, since FETCH_HEAD is already a parent
@@ -147,7 +128,7 @@ test_expect_success 'merge fetched subproj' '
147
128
'
148
129
149
130
test_expect_success ' add main-sub5' '
150
- create subdir /main-sub5 &&
131
+ create "sub dir /main-sub5" &&
151
132
git commit -m "main-sub5"
152
133
'
153
134
@@ -157,29 +138,29 @@ test_expect_success 'add main6' '
157
138
'
158
139
159
140
test_expect_success ' add main-sub7' '
160
- create subdir /main-sub7 &&
141
+ create "sub dir /main-sub7" &&
161
142
git commit -m "main-sub7"
162
143
'
163
144
164
145
test_expect_success ' fetch new subproj history' '
165
- git fetch ./subproj sub2 &&
146
+ git fetch ./"sub proj" sub2 &&
166
147
git branch sub2 FETCH_HEAD
167
148
'
168
149
169
150
test_expect_success ' check if --message works for merge' '
170
- git subtree merge --prefix=subdir -m "Merged changes from subproject" sub2 &&
151
+ git subtree merge --prefix="sub dir" -m "Merged changes from subproject" sub2 &&
171
152
check_equal ' ' "$(last_commit_message)"' ' "Merged changes from subproject" &&
172
153
undo
173
154
'
174
155
175
156
test_expect_success ' check if --message for merge works with squash too' '
176
- git subtree merge --prefix subdir -m "Merged changes from subproject using squash" --squash sub2 &&
157
+ git subtree merge --prefix "sub dir" -m "Merged changes from subproject using squash" --squash sub2 &&
177
158
check_equal ' ' "$(last_commit_message)"' ' "Merged changes from subproject using squash" &&
178
159
undo
179
160
'
180
161
181
162
test_expect_success ' merge new subproj history into subdir' '
182
- git subtree merge --prefix=subdir FETCH_HEAD &&
163
+ git subtree merge --prefix="sub dir" FETCH_HEAD &&
183
164
git branch pre-split &&
184
165
check_equal ' ' "$(last_commit_message)"' ' "Merge commit ' " '" ' "$(git rev-parse sub2)"' " '" ' into mainline" &&
185
166
undo
@@ -208,53 +189,53 @@ test_expect_success 'Check that the <prefix> exists for a split' '
208
189
'
209
190
210
191
test_expect_success ' check if --message works for split+rejoin' '
211
- spl1=' ' "$(git subtree split --annotate=' " '*'" ' --prefix subdir --onto FETCH_HEAD --message "Split & rejoin" --rejoin)"' ' &&
192
+ spl1=' ' "$(git subtree split --annotate=' " '*'" ' --prefix "sub dir" --onto FETCH_HEAD --message "Split & rejoin" --rejoin)"' ' &&
212
193
git branch spl1 "$spl1" &&
213
194
check_equal ' ' "$(last_commit_message)"' ' "Split & rejoin" &&
214
195
undo
215
196
'
216
197
217
198
test_expect_success ' check split with --branch' '
218
- spl1=$(git subtree split --annotate=' " '*'" ' --prefix subdir --onto FETCH_HEAD --message "Split & rejoin" --rejoin) &&
199
+ spl1=$(git subtree split --annotate=' " '*'" ' --prefix "sub dir" --onto FETCH_HEAD --message "Split & rejoin" --rejoin) &&
219
200
undo &&
220
- git subtree split --annotate=' " '*'" ' --prefix subdir --onto FETCH_HEAD --branch splitbr1 &&
201
+ git subtree split --annotate=' " '*'" ' --prefix "sub dir" --onto FETCH_HEAD --branch splitbr1 &&
221
202
check_equal ' ' "$(git rev-parse splitbr1)"' ' "$spl1"
222
203
'
223
204
224
205
test_expect_success ' check hash of split' '
225
- spl1=$(git subtree split --prefix subdir ) &&
226
- git subtree split --prefix subdir --branch splitbr1test &&
206
+ spl1=$(git subtree split --prefix "sub dir" ) &&
207
+ git subtree split --prefix "sub dir" --branch splitbr1test &&
227
208
check_equal ' ' "$(git rev-parse splitbr1test)"' ' "$spl1" &&
228
209
new_hash=$(git rev-parse splitbr1test~2) &&
229
210
check_equal ' ' "$new_hash"' ' "$subdir_hash"
230
211
'
231
212
232
213
test_expect_success ' check split with --branch for an existing branch' '
233
- spl1=' ' "$(git subtree split --annotate=' " '*'" ' --prefix subdir --onto FETCH_HEAD --message "Split & rejoin" --rejoin)"' ' &&
214
+ spl1=' ' "$(git subtree split --annotate=' " '*'" ' --prefix "sub dir" --onto FETCH_HEAD --message "Split & rejoin" --rejoin)"' ' &&
234
215
undo &&
235
216
git branch splitbr2 sub1 &&
236
- git subtree split --annotate=' " '*'" ' --prefix subdir --onto FETCH_HEAD --branch splitbr2 &&
217
+ git subtree split --annotate=' " '*'" ' --prefix "sub dir" --onto FETCH_HEAD --branch splitbr2 &&
237
218
check_equal ' ' "$(git rev-parse splitbr2)"' ' "$spl1"
238
219
'
239
220
240
221
test_expect_success ' check split with --branch for an incompatible branch' '
241
- test_must_fail git subtree split --prefix subdir --onto FETCH_HEAD --branch subdir
222
+ test_must_fail git subtree split --prefix "sub dir" --onto FETCH_HEAD --branch subdir
242
223
'
243
224
244
225
test_expect_success ' check split+rejoin' '
245
- spl1=' ' "$(git subtree split --annotate=' " '*'" ' --prefix subdir --onto FETCH_HEAD --message "Split & rejoin" --rejoin)"' ' &&
226
+ spl1=' ' "$(git subtree split --annotate=' " '*'" ' --prefix "sub dir" --onto FETCH_HEAD --message "Split & rejoin" --rejoin)"' ' &&
246
227
undo &&
247
- git subtree split --annotate=' " '*'" ' --prefix subdir --onto FETCH_HEAD --rejoin &&
248
- check_equal ' ' "$(last_commit_message)"' ' "Split ' " '" ' subdir /' " '" ' into commit ' " '" ' "$spl1"' " '" ' "
228
+ git subtree split --annotate=' " '*'" ' --prefix "sub dir" --onto FETCH_HEAD --rejoin &&
229
+ check_equal ' ' "$(last_commit_message)"' ' "Split ' " '" ' sub dir /' " '" ' into commit ' " '" ' "$spl1"' " '" ' "
249
230
'
250
231
251
232
test_expect_success ' add main-sub8' '
252
- create subdir /main-sub8 &&
233
+ create "sub dir /main-sub8" &&
253
234
git commit -m "main-sub8"
254
235
'
255
236
256
237
# To the subproject!
257
- cd ./subproj
238
+ cd ./" sub proj "
258
239
259
240
test_expect_success ' merge split into subproj' '
260
241
git fetch .. spl1 &&
@@ -271,22 +252,22 @@ test_expect_success 'add sub9' '
271
252
cd ..
272
253
273
254
test_expect_success ' split for sub8' '
274
- split2=' ' "$(git subtree split --annotate=' " '*'" ' --prefix subdir/ --rejoin)"' ' &&
255
+ split2=' ' "$(git subtree split --annotate=' " '*'" ' --prefix "sub dir/" --rejoin)"' ' &&
275
256
git branch split2 "$split2"
276
257
'
277
258
278
259
test_expect_success ' add main-sub10' '
279
- create subdir /main-sub10 &&
260
+ create "sub dir /main-sub10" &&
280
261
git commit -m "main-sub10"
281
262
'
282
263
283
264
test_expect_success ' split for sub10' '
284
- spl3=' ' "$(git subtree split --annotate=' " '*'" ' --prefix subdir --rejoin)"' ' &&
265
+ spl3=' ' "$(git subtree split --annotate=' " '*'" ' --prefix "sub dir" --rejoin)"' ' &&
285
266
git branch spl3 "$spl3"
286
267
'
287
268
288
269
# To the subproject!
289
- cd ./subproj
270
+ cd ./" sub proj "
290
271
291
272
test_expect_success ' merge split into subproj' '
292
273
git fetch .. spl3 &&
@@ -295,42 +276,64 @@ test_expect_success 'merge split into subproj' '
295
276
git branch subproj-merge-spl3
296
277
'
297
278
298
- chkm=" main4 main6"
299
- chkms=" main-sub10 main-sub5 main-sub7 main-sub8"
300
- chkms_sub=$( echo $chkms | multiline | sed ' s,^,subdir/,' | fixnl)
301
- chks=" sub1 sub2 sub3 sub9"
302
- chks_sub=$( echo $chks | multiline | sed ' s,^,subdir/,' | fixnl)
279
+ chkm=" main4
280
+ main6"
281
+ chkms=" main-sub10
282
+ main-sub5
283
+ main-sub7
284
+ main-sub8"
285
+ chkms_sub=$( cat << TXT | sed 's,^,sub dir/,'
286
+ $chkms
287
+ TXT
288
+ )
289
+ chks=" sub1
290
+ sub2
291
+ sub3
292
+ sub9"
293
+ chks_sub=$( cat << TXT | sed 's,^,sub dir/,'
294
+ $chks
295
+ TXT
296
+ )
303
297
304
298
test_expect_success ' make sure exactly the right set of files ends up in the subproj' '
305
- subfiles=' ' "$(git ls-files | fixnl)"' ' &&
306
- check_equal "$subfiles" "$chkms $chks"
299
+ subfiles="$(git ls-files)" &&
300
+ check_equal "$subfiles" "$chkms
301
+ $chks"
307
302
'
308
-
309
303
test_expect_success ' make sure the subproj history *only* contains commits that affect the subdir' '
310
- allchanges=' ' "$(git log --name-only --pretty=format:' " ''" ' | sort | fixnl)"' ' &&
311
- check_equal "$allchanges" "$chkms $chks"
304
+ allchanges=' ' "$(git log --name-only --pretty=format:' " ''" ' | sort | sed "/^$/d")"' ' &&
305
+ check_equal "$allchanges" "$chkms
306
+ $chks"
312
307
'
313
308
314
309
# Back to mainline
315
310
cd ..
316
311
317
312
test_expect_success ' pull from subproj' '
318
- git fetch ./subproj subproj-merge-spl3 &&
313
+ git fetch ./"sub proj" subproj-merge-spl3 &&
319
314
git branch subproj-merge-spl3 FETCH_HEAD &&
320
- git subtree pull --prefix=subdir ./subproj subproj-merge-spl3
315
+ git subtree pull --prefix="sub dir" ./"sub proj" subproj-merge-spl3
321
316
'
322
317
323
318
test_expect_success ' make sure exactly the right set of files ends up in the mainline' '
324
- mainfiles=' ' "$(git ls-files | fixnl)"' ' &&
325
- check_equal "$mainfiles" "$chkm $chkms_sub $chks_sub"
319
+ mainfiles=$(git ls-files) &&
320
+ check_equal "$mainfiles" "$chkm
321
+ $chkms_sub
322
+ $chks_sub"
326
323
'
327
324
328
325
test_expect_success ' make sure each filename changed exactly once in the entire history' '
329
326
# main-sub?? and /subdir/main-sub?? both change, because those are the
330
327
# changes that were split into their own history. And subdir/sub?? never
331
328
# change, since they were *only* changed in the subtree branch.
332
- allchanges=' ' "$(git log --name-only --pretty=format:' " ''" ' | sort | fixnl)"' ' &&
333
- check_equal "$allchanges" ' ' "$(echo $chkms $chkm $chks $chkms_sub | multiline | sort | fixnl)"' '
329
+ allchanges=' ' "$(git log --name-only --pretty=format:' " ''" ' | sort | sed "/^$/d")"' ' &&
330
+ check_equal "$allchanges" ' ' "$(cat <<TXT | sort
331
+ $chkms
332
+ $chkm
333
+ $chks
334
+ $chkms_sub
335
+ TXT
336
+ )"' '
334
337
'
335
338
336
339
test_expect_success ' make sure the --rejoin commits never make it into subproj' '
@@ -377,7 +380,7 @@ cd ../main
377
380
test_expect_success ' add sub as subdir in main' '
378
381
git fetch ../sub master &&
379
382
git branch sub2 FETCH_HEAD &&
380
- git subtree add --prefix subdir sub2
383
+ git subtree add --prefix "sub dir" sub2
381
384
'
382
385
383
386
cd ../sub
@@ -392,16 +395,16 @@ cd ../main
392
395
test_expect_success ' merge from sub' '
393
396
git fetch ../sub master &&
394
397
git branch sub3 FETCH_HEAD &&
395
- git subtree merge --prefix subdir sub3
398
+ git subtree merge --prefix "sub dir" sub3
396
399
'
397
400
398
401
test_expect_success ' add main-sub4' '
399
- create subdir /main-sub4 &&
402
+ create "sub dir /main-sub4" &&
400
403
git commit -m "main-sub4"
401
404
'
402
405
403
406
test_expect_success ' split for main-sub4 without --onto' '
404
- git subtree split --prefix subdir --branch mainsub4
407
+ git subtree split --prefix "sub dir" --branch mainsub4
405
408
'
406
409
407
410
# at this point, the new commit parent should be sub3 if it is not,
0 commit comments