subtree: fix "git subtree split --rejoin"

"git merge" in v2.9 prevents merging unrelated histories. "git subtree split --rejoin" creates unrelated histories when creating a split repo from a raw sub-directory that did not originate from an invocation of "git subtree add". Restore the original behavior by passing --allow-unrelated-histories when merging subtrees. This ensures that the synthetic history created by "git subtree split" can be merged. Add a test to ensure that this feature works as advertised. Reported-by: Brett Cundal <brett.cundal@iugome.com> Helped-by: Johannes Schindelin <Johannes.Schindelin@gmx.de> Signed-off-by: David Aguilar <davvid@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

David Aguilar committed Jul 25, 2016 at 21:14 UTC 0f12c7d4d175bb0566208213b1b340b6794f305c
2 files changed +17
contrib/subtree/git-subtree.sh
+1
@@ -662,6 +662,7 @@ cmd_split()
662 debug "Merging split branch into HEAD..."
663 latest_old=$(cache_get latest_old)
664 git merge -s ours \
665 + --allow-unrelated-histories \
666 -m "$(rejoin_msg "$dir" $latest_old $latest_new)" \
667 $latest_new >&2 || exit $?
668 fi
contrib/subtree/t/t7900-subtree.sh
+16
@@ -346,6 +346,22 @@ test_expect_success 'split sub dir/ with --rejoin' '
346 )
347 '
348
349 +next_test
350 +test_expect_success 'split sub dir/ with --rejoin from scratch' '
351 + subtree_test_create_repo "$subtree_test_count" &&
352 + test_create_commit "$subtree_test_count" main1 &&
353 + (
354 + cd "$subtree_test_count" &&
355 + mkdir "sub dir" &&
356 + echo file >"sub dir"/file &&
357 + git add "sub dir/file" &&
358 + git commit -m"sub dir file" &&
359 + split_hash=$(git subtree split --prefix="sub dir" --rejoin) &&
360 + git subtree split --prefix="sub dir" --rejoin &&
361 + check_equal "$(last_commit_message)" "Split '\''sub dir/'\'' into commit '\''$split_hash'\''"
362 + )
363 + '
364 +
365 next_test
366 test_expect_success 'split sub dir/ with --rejoin and --message' '
367 subtree_test_create_repo "$subtree_test_count" &&