Skip to content

Commit

Permalink
subtree: fix "git subtree split --rejoin"
Browse files Browse the repository at this point in the history
"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]>
  • Loading branch information
davvid authored and gitster committed Jul 26, 2016
1 parent fbd3199 commit 0f12c7d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions contrib/subtree/git-subtree.sh
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,7 @@ cmd_split()
debug "Merging split branch into HEAD..."
latest_old=$(cache_get latest_old)
git merge -s ours \
--allow-unrelated-histories \
-m "$(rejoin_msg "$dir" $latest_old $latest_new)" \
$latest_new >&2 || exit $?
fi
Expand Down
16 changes: 16 additions & 0 deletions contrib/subtree/t/t7900-subtree.sh
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,22 @@ test_expect_success 'split sub dir/ with --rejoin' '
)
'

next_test
test_expect_success 'split sub dir/ with --rejoin from scratch' '
subtree_test_create_repo "$subtree_test_count" &&
test_create_commit "$subtree_test_count" main1 &&
(
cd "$subtree_test_count" &&
mkdir "sub dir" &&
echo file >"sub dir"/file &&
git add "sub dir/file" &&
git commit -m"sub dir file" &&
split_hash=$(git subtree split --prefix="sub dir" --rejoin) &&
git subtree split --prefix="sub dir" --rejoin &&
check_equal "$(last_commit_message)" "Split '\''sub dir/'\'' into commit '\''$split_hash'\''"
)
'

next_test
test_expect_success 'split sub dir/ with --rejoin and --message' '
subtree_test_create_repo "$subtree_test_count" &&
Expand Down

0 comments on commit 0f12c7d

Please sign in to comment.