Skip to content

Commit c61eb41

Browse files
ashumkingitster
authored andcommitted
t7900-subtree: test the "space in a subdirectory name" case
In common case there can be spaces in a subdirectory name. Change tests accorgingly to this statement. Also, as far as a call to the `rejoin_msg` function (in `cmd_split`) does not take into account such a case this patch fixes commit message when `--rejoin` option is set . Besides, as `fixnl` and `multiline` functions did not take into account the "new" tested "space in a subdirectory name" case they become unused and redundant, so they are removed. Signed-off-by: Alexey Shumkin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ec371ff commit c61eb41

File tree

2 files changed

+76
-73
lines changed

2 files changed

+76
-73
lines changed

contrib/subtree/git-subtree.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ cmd_split()
648648
debug "Merging split branch into HEAD..."
649649
latest_old=$(cache_get latest_old)
650650
git merge -s ours \
651-
-m "$(rejoin_msg $dir $latest_old $latest_new)" \
651+
-m "$(rejoin_msg "$dir" $latest_old $latest_new)" \
652652
$latest_new >&2 || exit $?
653653
fi
654654
if [ -n "$branch" ]; then

contrib/subtree/t/t7900-subtree.sh

Lines changed: 75 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -32,25 +32,6 @@ check_equal()
3232
fi
3333
}
3434

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-
5435
undo()
5536
{
5637
git reset --hard HEAD~
@@ -62,11 +43,11 @@ last_commit_message()
6243
}
6344

6445
test_expect_success 'init subproj' '
65-
test_create_repo subproj
46+
test_create_repo "sub proj"
6647
'
6748

6849
# To the subproject!
69-
cd subproj
50+
cd ./"sub proj"
7051

7152
test_expect_success 'add sub1' '
7253
create sub1 &&
@@ -106,39 +87,39 @@ test_expect_success 'add main4' '
10687
'
10788

10889
test_expect_success 'fetch subproj history' '
109-
git fetch ./subproj sub1 &&
90+
git fetch ./"sub proj" sub1 &&
11091
git branch sub1 FETCH_HEAD
11192
'
11293

11394
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
11596
'
11697

11798
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
119100
'
120101

121102
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 &&
123104
check_equal ''"$(last_commit_message)"'' "Added subproject" &&
124105
undo
125106
'
126107

127108
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 &&
129110
check_equal ''"$(last_commit_message)"'' "Added subproject using git subtree" &&
130111
undo
131112
'
132113

133114
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 &&
135116
check_equal ''"$(last_commit_message)"'' "Added subproject with squash" &&
136117
undo
137118
'
138119

139120
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)"'''"'"'"
142123
'
143124

144125
# this shouldn't actually do anything, since FETCH_HEAD is already a parent
@@ -147,7 +128,7 @@ test_expect_success 'merge fetched subproj' '
147128
'
148129

149130
test_expect_success 'add main-sub5' '
150-
create subdir/main-sub5 &&
131+
create "sub dir/main-sub5" &&
151132
git commit -m "main-sub5"
152133
'
153134

@@ -157,29 +138,29 @@ test_expect_success 'add main6' '
157138
'
158139

159140
test_expect_success 'add main-sub7' '
160-
create subdir/main-sub7 &&
141+
create "sub dir/main-sub7" &&
161142
git commit -m "main-sub7"
162143
'
163144

164145
test_expect_success 'fetch new subproj history' '
165-
git fetch ./subproj sub2 &&
146+
git fetch ./"sub proj" sub2 &&
166147
git branch sub2 FETCH_HEAD
167148
'
168149

169150
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 &&
171152
check_equal ''"$(last_commit_message)"'' "Merged changes from subproject" &&
172153
undo
173154
'
174155

175156
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 &&
177158
check_equal ''"$(last_commit_message)"'' "Merged changes from subproject using squash" &&
178159
undo
179160
'
180161

181162
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 &&
183164
git branch pre-split &&
184165
check_equal ''"$(last_commit_message)"'' "Merge commit '"'"'"$(git rev-parse sub2)"'"'"' into mainline" &&
185166
undo
@@ -208,53 +189,53 @@ test_expect_success 'Check that the <prefix> exists for a split' '
208189
'
209190

210191
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)"'' &&
212193
git branch spl1 "$spl1" &&
213194
check_equal ''"$(last_commit_message)"'' "Split & rejoin" &&
214195
undo
215196
'
216197

217198
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) &&
219200
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 &&
221202
check_equal ''"$(git rev-parse splitbr1)"'' "$spl1"
222203
'
223204

224205
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 &&
227208
check_equal ''"$(git rev-parse splitbr1test)"'' "$spl1" &&
228209
new_hash=$(git rev-parse splitbr1test~2) &&
229210
check_equal ''"$new_hash"'' "$subdir_hash"
230211
'
231212

232213
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)"'' &&
234215
undo &&
235216
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 &&
237218
check_equal ''"$(git rev-parse splitbr2)"'' "$spl1"
238219
'
239220

240221
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
242223
'
243224

244225
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)"'' &&
246227
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"'"'"'"
249230
'
250231

251232
test_expect_success 'add main-sub8' '
252-
create subdir/main-sub8 &&
233+
create "sub dir/main-sub8" &&
253234
git commit -m "main-sub8"
254235
'
255236

256237
# To the subproject!
257-
cd ./subproj
238+
cd ./"sub proj"
258239

259240
test_expect_success 'merge split into subproj' '
260241
git fetch .. spl1 &&
@@ -271,22 +252,22 @@ test_expect_success 'add sub9' '
271252
cd ..
272253

273254
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)"'' &&
275256
git branch split2 "$split2"
276257
'
277258

278259
test_expect_success 'add main-sub10' '
279-
create subdir/main-sub10 &&
260+
create "sub dir/main-sub10" &&
280261
git commit -m "main-sub10"
281262
'
282263

283264
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)"'' &&
285266
git branch spl3 "$spl3"
286267
'
287268

288269
# To the subproject!
289-
cd ./subproj
270+
cd ./"sub proj"
290271

291272
test_expect_success 'merge split into subproj' '
292273
git fetch .. spl3 &&
@@ -295,42 +276,64 @@ test_expect_success 'merge split into subproj' '
295276
git branch subproj-merge-spl3
296277
'
297278

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+
)
303297

304298
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"
307302
'
308-
309303
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"
312307
'
313308

314309
# Back to mainline
315310
cd ..
316311

317312
test_expect_success 'pull from subproj' '
318-
git fetch ./subproj subproj-merge-spl3 &&
313+
git fetch ./"sub proj" subproj-merge-spl3 &&
319314
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
321316
'
322317

323318
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"
326323
'
327324

328325
test_expect_success 'make sure each filename changed exactly once in the entire history' '
329326
# main-sub?? and /subdir/main-sub?? both change, because those are the
330327
# changes that were split into their own history. And subdir/sub?? never
331328
# 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+
)"''
334337
'
335338

336339
test_expect_success 'make sure the --rejoin commits never make it into subproj' '
@@ -377,7 +380,7 @@ cd ../main
377380
test_expect_success 'add sub as subdir in main' '
378381
git fetch ../sub master &&
379382
git branch sub2 FETCH_HEAD &&
380-
git subtree add --prefix subdir sub2
383+
git subtree add --prefix "sub dir" sub2
381384
'
382385

383386
cd ../sub
@@ -392,16 +395,16 @@ cd ../main
392395
test_expect_success 'merge from sub' '
393396
git fetch ../sub master &&
394397
git branch sub3 FETCH_HEAD &&
395-
git subtree merge --prefix subdir sub3
398+
git subtree merge --prefix "sub dir" sub3
396399
'
397400

398401
test_expect_success 'add main-sub4' '
399-
create subdir/main-sub4 &&
402+
create "sub dir/main-sub4" &&
400403
git commit -m "main-sub4"
401404
'
402405

403406
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
405408
'
406409

407410
# at this point, the new commit parent should be sub3 if it is not,

0 commit comments

Comments
 (0)