@matheusbsbs / matheus-bagliano / commits / c61eb4106d
Fork 0

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 <Alex.Crezoff@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Alexey Shumkin committed Sep 5, 2015 at 01:24 UTC c61eb4106d9ea77ba770c28a018cafa3b81b927e
2 files changed +76 -73
contrib/subtree/git-subtree.sh
+1 -1
@@ -648,7 +648,7 @@ cmd_split()
648 debug "Merging split branch into HEAD..."
649 latest_old=$(cache_get latest_old)
650 git merge -s ours \
651 - -m "$(rejoin_msg $dir $latest_old $latest_new)" \
651 + -m "$(rejoin_msg "$dir" $latest_old $latest_new)" \
652 $latest_new >&2 || exit $?
653 fi
654 if [ -n "$branch" ]; then
contrib/subtree/t/t7900-subtree.sh
+75 -72
@@ -32,25 +32,6 @@ check_equal()
32 fi
33 }
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 -
35 undo()
36 {
37 git reset --hard HEAD~
@@ -62,11 +43,11 @@ last_commit_message()
43 }
44
45 test_expect_success 'init subproj' '
65 - test_create_repo subproj
46 + test_create_repo "sub proj"
47 '
48
49 # To the subproject!
69 -cd subproj
50 +cd ./"sub proj"
51
52 test_expect_success 'add sub1' '
53 create sub1 &&
@@ -106,39 +87,39 @@ test_expect_success 'add main4' '
87 '
88
89 test_expect_success 'fetch subproj history' '
109 - git fetch ./subproj sub1 &&
90 + git fetch ./"sub proj" sub1 &&
91 git branch sub1 FETCH_HEAD
92 '
93
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
96 '
97
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
100 '
101
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 &&
104 check_equal ''"$(last_commit_message)"'' "Added subproject" &&
105 undo
106 '
107
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 &&
110 check_equal ''"$(last_commit_message)"'' "Added subproject using git subtree" &&
111 undo
112 '
113
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 &&
116 check_equal ''"$(last_commit_message)"'' "Added subproject with squash" &&
117 undo
118 '
119
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)"'''"'"'"
123 '
124
125 # this shouldn't actually do anything, since FETCH_HEAD is already a parent
@@ -147,7 +128,7 @@ test_expect_success 'merge fetched subproj' '
128 '
129
130 test_expect_success 'add main-sub5' '
150 - create subdir/main-sub5 &&
131 + create "sub dir/main-sub5" &&
132 git commit -m "main-sub5"
133 '
134
@@ -157,29 +138,29 @@ test_expect_success 'add main6' '
138 '
139
140 test_expect_success 'add main-sub7' '
160 - create subdir/main-sub7 &&
141 + create "sub dir/main-sub7" &&
142 git commit -m "main-sub7"
143 '
144
145 test_expect_success 'fetch new subproj history' '
165 - git fetch ./subproj sub2 &&
146 + git fetch ./"sub proj" sub2 &&
147 git branch sub2 FETCH_HEAD
148 '
149
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 &&
152 check_equal ''"$(last_commit_message)"'' "Merged changes from subproject" &&
153 undo
154 '
155
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 &&
158 check_equal ''"$(last_commit_message)"'' "Merged changes from subproject using squash" &&
159 undo
160 '
161
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 &&
164 git branch pre-split &&
165 check_equal ''"$(last_commit_message)"'' "Merge commit '"'"'"$(git rev-parse sub2)"'"'"' into mainline" &&
166 undo
@@ -208,53 +189,53 @@ test_expect_success 'Check that the <prefix> exists for a split' '
189 '
190
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)"'' &&
193 git branch spl1 "$spl1" &&
194 check_equal ''"$(last_commit_message)"'' "Split & rejoin" &&
195 undo
196 '
197
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) &&
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 &&
202 check_equal ''"$(git rev-parse splitbr1)"'' "$spl1"
203 '
204
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 &&
208 check_equal ''"$(git rev-parse splitbr1test)"'' "$spl1" &&
209 new_hash=$(git rev-parse splitbr1test~2) &&
210 check_equal ''"$new_hash"'' "$subdir_hash"
211 '
212
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)"'' &&
215 undo &&
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 &&
218 check_equal ''"$(git rev-parse splitbr2)"'' "$spl1"
219 '
220
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
223 '
224
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)"'' &&
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"'"'"'"
230 '
231
232 test_expect_success 'add main-sub8' '
252 - create subdir/main-sub8 &&
233 + create "sub dir/main-sub8" &&
234 git commit -m "main-sub8"
235 '
236
237 # To the subproject!
257 -cd ./subproj
238 +cd ./"sub proj"
239
240 test_expect_success 'merge split into subproj' '
241 git fetch .. spl1 &&
@@ -271,22 +252,22 @@ test_expect_success 'add sub9' '
252 cd ..
253
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)"'' &&
256 git branch split2 "$split2"
257 '
258
259 test_expect_success 'add main-sub10' '
279 - create subdir/main-sub10 &&
260 + create "sub dir/main-sub10" &&
261 git commit -m "main-sub10"
262 '
263
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)"'' &&
266 git branch spl3 "$spl3"
267 '
268
269 # To the subproject!
289 -cd ./subproj
270 +cd ./"sub proj"
271
272 test_expect_success 'merge split into subproj' '
273 git fetch .. spl3 &&
@@ -295,42 +276,64 @@ test_expect_success 'merge split into subproj' '
276 git branch subproj-merge-spl3
277 '
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 +)
297
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"
302 '
308 -
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"
307 '
308
309 # Back to mainline
310 cd ..
311
312 test_expect_success 'pull from subproj' '
318 - git fetch ./subproj subproj-merge-spl3 &&
313 + git fetch ./"sub proj" subproj-merge-spl3 &&
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
316 '
317
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"
323 '
324
325 test_expect_success 'make sure each filename changed exactly once in the entire history' '
326 # main-sub?? and /subdir/main-sub?? both change, because those are the
327 # changes that were split into their own history. And subdir/sub?? never
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 +)"''
337 '
338
339 test_expect_success 'make sure the --rejoin commits never make it into subproj' '
@@ -377,7 +380,7 @@ cd ../main
380 test_expect_success 'add sub as subdir in main' '
381 git fetch ../sub master &&
382 git branch sub2 FETCH_HEAD &&
380 - git subtree add --prefix subdir sub2
383 + git subtree add --prefix "sub dir" sub2
384 '
385
386 cd ../sub
@@ -392,16 +395,16 @@ cd ../main
395 test_expect_success 'merge from sub' '
396 git fetch ../sub master &&
397 git branch sub3 FETCH_HEAD &&
395 - git subtree merge --prefix subdir sub3
398 + git subtree merge --prefix "sub dir" sub3
399 '
400
401 test_expect_success 'add main-sub4' '
399 - create subdir/main-sub4 &&
402 + create "sub dir/main-sub4" &&
403 git commit -m "main-sub4"
404 '
405
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
408 '
409
410 # at this point, the new commit parent should be sub3 if it is not,