Skip to content

Commit 0f12c7d

Browse files
davvidgitster
authored andcommitted
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 <[email protected]> Helped-by: Johannes Schindelin <[email protected]> Signed-off-by: David Aguilar <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent fbd3199 commit 0f12c7d

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

contrib/subtree/git-subtree.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,7 @@ cmd_split()
662662
debug "Merging split branch into HEAD..."
663663
latest_old=$(cache_get latest_old)
664664
git merge -s ours \
665+
--allow-unrelated-histories \
665666
-m "$(rejoin_msg "$dir" $latest_old $latest_new)" \
666667
$latest_new >&2 || exit $?
667668
fi

contrib/subtree/t/t7900-subtree.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,22 @@ test_expect_success 'split sub dir/ with --rejoin' '
346346
)
347347
'
348348

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+
349365
next_test
350366
test_expect_success 'split sub dir/ with --rejoin and --message' '
351367
subtree_test_create_repo "$subtree_test_count" &&

0 commit comments

Comments
 (0)