2012-01-30 06:09:58 +08:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# Copyright (c) 2012 Avery Pennaraum
|
2015-09-05 06:24:11 +08:00
|
|
|
# Copyright (c) 2015 Alexey Shumkin
|
2012-01-30 06:09:58 +08:00
|
|
|
#
|
|
|
|
test_description='Basic porcelain support for subtrees
|
|
|
|
|
2015-11-13 10:32:30 +08:00
|
|
|
This test verifies the basic operation of the add, pull, merge
|
2012-01-30 06:09:58 +08:00
|
|
|
and split subcommands of git subtree.
|
|
|
|
'
|
|
|
|
|
2014-05-23 18:15:31 +08:00
|
|
|
TEST_DIRECTORY=$(pwd)/../../../t
|
2021-04-28 05:17:22 +08:00
|
|
|
. "$TEST_DIRECTORY"/test-lib.sh
|
2012-03-21 07:11:49 +08:00
|
|
|
|
subtree: t7900: comment subtree_test_create_repo
It's unclear what the purpose of t7900-subtree.sh's
`subtree_test_create_repo` helper function is. It wraps test-lib.sh's,
`test_create_repo` but follows that up by setting log.date=relative. Why
does it set log.date=relative?
My first guess was that at one point the tests required that, but no
longer do, and that the function is now vestigial. I even wrote a patch
to get rid of it and was moments away from `git send-email`ing it.
However, by chance when looking for something else in the history, I
discovered the true reason, from e7aac44ed2 (contrib/subtree: ignore
log.date configuration, 2015-07-21). It's testing that setting
log.date=relative doesn't break `git subtree`, as at one point in the past
that did break `git subtree`.
So, add a comment about this, to avoid future such confusion.
And while at it, go ahead and (1) touch up the function to avoid a
pointless subshell and (2) update the one test that didn't use it.
Signed-off-by: Luke Shumaker <lukeshu@datawire.io>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2021-04-28 05:17:23 +08:00
|
|
|
# Use our own wrapper around test-lib.sh's test_create_repo, in order
|
|
|
|
# to set log.date=relative. `git subtree` parses the output of `git
|
|
|
|
# log`, and so it must be careful to not be affected by settings that
|
|
|
|
# change the `git log` output. We test this by setting
|
|
|
|
# log.date=relative for every repo in the tests.
|
2021-04-28 05:17:22 +08:00
|
|
|
subtree_test_create_repo () {
|
2016-07-26 12:14:14 +08:00
|
|
|
test_create_repo "$1" &&
|
subtree: t7900: comment subtree_test_create_repo
It's unclear what the purpose of t7900-subtree.sh's
`subtree_test_create_repo` helper function is. It wraps test-lib.sh's,
`test_create_repo` but follows that up by setting log.date=relative. Why
does it set log.date=relative?
My first guess was that at one point the tests required that, but no
longer do, and that the function is now vestigial. I even wrote a patch
to get rid of it and was moments away from `git send-email`ing it.
However, by chance when looking for something else in the history, I
discovered the true reason, from e7aac44ed2 (contrib/subtree: ignore
log.date configuration, 2015-07-21). It's testing that setting
log.date=relative doesn't break `git subtree`, as at one point in the past
that did break `git subtree`.
So, add a comment about this, to avoid future such confusion.
And while at it, go ahead and (1) touch up the function to avoid a
pointless subshell and (2) update the one test that didn't use it.
Signed-off-by: Luke Shumaker <lukeshu@datawire.io>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2021-04-28 05:17:23 +08:00
|
|
|
git -C "$1" config log.date relative
|
2015-11-13 10:32:35 +08:00
|
|
|
}
|
|
|
|
|
2021-04-28 05:17:22 +08:00
|
|
|
test_create_commit () (
|
2016-07-26 12:14:14 +08:00
|
|
|
repo=$1 &&
|
|
|
|
commit=$2 &&
|
|
|
|
cd "$repo" &&
|
|
|
|
mkdir -p "$(dirname "$commit")" \
|
2015-11-13 10:32:35 +08:00
|
|
|
|| error "Could not create directory for commit"
|
2016-07-26 12:14:14 +08:00
|
|
|
echo "$commit" >"$commit" &&
|
2015-11-13 10:32:35 +08:00
|
|
|
git add "$commit" || error "Could not add commit"
|
|
|
|
git commit -m "$commit" || error "Could not commit"
|
|
|
|
)
|
|
|
|
|
2021-04-28 05:17:27 +08:00
|
|
|
last_commit_subject () {
|
2010-02-09 08:44:41 +08:00
|
|
|
git log --pretty=format:%s -1
|
2010-01-13 06:04:25 +08:00
|
|
|
}
|
|
|
|
|
2021-04-28 05:17:28 +08:00
|
|
|
test_expect_success 'shows short help text for -h' '
|
|
|
|
test_expect_code 129 git subtree -h >out 2>err &&
|
|
|
|
test_must_be_empty err &&
|
|
|
|
grep -e "^ *or: git subtree pull" out &&
|
|
|
|
grep -e --annotate out
|
|
|
|
'
|
|
|
|
|
2015-11-13 10:32:35 +08:00
|
|
|
#
|
|
|
|
# Tests for 'git subtree add'
|
|
|
|
#
|
2012-01-30 06:09:58 +08:00
|
|
|
|
2015-11-13 10:32:31 +08:00
|
|
|
test_expect_success 'no merge from non-existent subtree' '
|
2021-04-28 05:17:21 +08:00
|
|
|
subtree_test_create_repo "$test_count" &&
|
|
|
|
subtree_test_create_repo "$test_count/sub proj" &&
|
|
|
|
test_create_commit "$test_count" main1 &&
|
|
|
|
test_create_commit "$test_count/sub proj" sub1 &&
|
2015-11-13 10:32:35 +08:00
|
|
|
(
|
2021-04-28 05:17:21 +08:00
|
|
|
cd "$test_count" &&
|
2021-04-28 05:17:20 +08:00
|
|
|
git fetch ./"sub proj" HEAD &&
|
2015-11-13 10:32:35 +08:00
|
|
|
test_must_fail git subtree merge --prefix="sub dir" FETCH_HEAD
|
|
|
|
)
|
2015-11-13 10:32:31 +08:00
|
|
|
'
|
|
|
|
|
2015-11-13 10:32:35 +08:00
|
|
|
test_expect_success 'no pull from non-existent subtree' '
|
2021-04-28 05:17:21 +08:00
|
|
|
subtree_test_create_repo "$test_count" &&
|
|
|
|
subtree_test_create_repo "$test_count/sub proj" &&
|
|
|
|
test_create_commit "$test_count" main1 &&
|
|
|
|
test_create_commit "$test_count/sub proj" sub1 &&
|
2015-11-13 10:32:35 +08:00
|
|
|
(
|
2021-04-28 05:17:21 +08:00
|
|
|
cd "$test_count" &&
|
2021-04-28 05:17:20 +08:00
|
|
|
git fetch ./"sub proj" HEAD &&
|
|
|
|
test_must_fail git subtree pull --prefix="sub dir" ./"sub proj" HEAD
|
2021-04-28 05:17:22 +08:00
|
|
|
)
|
|
|
|
'
|
2015-11-13 10:32:32 +08:00
|
|
|
|
2015-11-13 10:32:35 +08:00
|
|
|
test_expect_success 'add subproj as subtree into sub dir/ with --prefix' '
|
2021-04-28 05:17:21 +08:00
|
|
|
subtree_test_create_repo "$test_count" &&
|
|
|
|
subtree_test_create_repo "$test_count/sub proj" &&
|
|
|
|
test_create_commit "$test_count" main1 &&
|
|
|
|
test_create_commit "$test_count/sub proj" sub1 &&
|
2015-11-13 10:32:35 +08:00
|
|
|
(
|
2021-04-28 05:17:21 +08:00
|
|
|
cd "$test_count" &&
|
2021-04-28 05:17:20 +08:00
|
|
|
git fetch ./"sub proj" HEAD &&
|
2015-11-13 10:32:35 +08:00
|
|
|
git subtree add --prefix="sub dir" FETCH_HEAD &&
|
2021-04-28 05:17:27 +08:00
|
|
|
test "$(last_commit_subject)" = "Add '\''sub dir/'\'' from commit '\''$(git rev-parse FETCH_HEAD)'\''"
|
2015-11-13 10:32:35 +08:00
|
|
|
)
|
2012-01-30 06:09:58 +08:00
|
|
|
'
|
|
|
|
|
2015-11-13 10:32:32 +08:00
|
|
|
test_expect_success 'add subproj as subtree into sub dir/ with --prefix and --message' '
|
2021-04-28 05:17:21 +08:00
|
|
|
subtree_test_create_repo "$test_count" &&
|
|
|
|
subtree_test_create_repo "$test_count/sub proj" &&
|
|
|
|
test_create_commit "$test_count" main1 &&
|
|
|
|
test_create_commit "$test_count/sub proj" sub1 &&
|
2015-11-13 10:32:35 +08:00
|
|
|
(
|
2021-04-28 05:17:21 +08:00
|
|
|
cd "$test_count" &&
|
2021-04-28 05:17:20 +08:00
|
|
|
git fetch ./"sub proj" HEAD &&
|
2015-11-13 10:32:35 +08:00
|
|
|
git subtree add --prefix="sub dir" --message="Added subproject" FETCH_HEAD &&
|
2021-04-28 05:17:27 +08:00
|
|
|
test "$(last_commit_subject)" = "Added subproject"
|
2015-11-13 10:32:35 +08:00
|
|
|
)
|
2012-01-30 06:09:58 +08:00
|
|
|
'
|
|
|
|
|
2015-11-13 10:32:35 +08:00
|
|
|
test_expect_success 'add subproj as subtree into sub dir/ with --prefix as -P and --message as -m' '
|
2021-04-28 05:17:21 +08:00
|
|
|
subtree_test_create_repo "$test_count" &&
|
|
|
|
subtree_test_create_repo "$test_count/sub proj" &&
|
|
|
|
test_create_commit "$test_count" main1 &&
|
|
|
|
test_create_commit "$test_count/sub proj" sub1 &&
|
2015-11-13 10:32:35 +08:00
|
|
|
(
|
2021-04-28 05:17:21 +08:00
|
|
|
cd "$test_count" &&
|
2021-04-28 05:17:20 +08:00
|
|
|
git fetch ./"sub proj" HEAD &&
|
2015-11-13 10:32:35 +08:00
|
|
|
git subtree add -P "sub dir" -m "Added subproject" FETCH_HEAD &&
|
2021-04-28 05:17:27 +08:00
|
|
|
test "$(last_commit_subject)" = "Added subproject"
|
2015-11-13 10:32:35 +08:00
|
|
|
)
|
2012-01-30 06:09:58 +08:00
|
|
|
'
|
|
|
|
|
2015-11-13 10:32:32 +08:00
|
|
|
test_expect_success 'add subproj as subtree into sub dir/ with --squash and --prefix and --message' '
|
2021-04-28 05:17:21 +08:00
|
|
|
subtree_test_create_repo "$test_count" &&
|
|
|
|
subtree_test_create_repo "$test_count/sub proj" &&
|
|
|
|
test_create_commit "$test_count" main1 &&
|
|
|
|
test_create_commit "$test_count/sub proj" sub1 &&
|
2015-11-13 10:32:35 +08:00
|
|
|
(
|
2021-04-28 05:17:21 +08:00
|
|
|
cd "$test_count" &&
|
2021-04-28 05:17:20 +08:00
|
|
|
git fetch ./"sub proj" HEAD &&
|
2015-11-13 10:32:35 +08:00
|
|
|
git subtree add --prefix="sub dir" --message="Added subproject with squash" --squash FETCH_HEAD &&
|
2021-04-28 05:17:27 +08:00
|
|
|
test "$(last_commit_subject)" = "Added subproject with squash"
|
2015-11-13 10:32:35 +08:00
|
|
|
)
|
2012-01-30 06:09:58 +08:00
|
|
|
'
|
|
|
|
|
2015-11-13 10:32:35 +08:00
|
|
|
#
|
|
|
|
# Tests for 'git subtree merge'
|
|
|
|
#
|
2012-01-30 06:09:58 +08:00
|
|
|
|
2015-11-13 10:32:35 +08:00
|
|
|
test_expect_success 'merge new subproj history into sub dir/ with --prefix' '
|
2021-04-28 05:17:21 +08:00
|
|
|
subtree_test_create_repo "$test_count" &&
|
|
|
|
subtree_test_create_repo "$test_count/sub proj" &&
|
|
|
|
test_create_commit "$test_count" main1 &&
|
|
|
|
test_create_commit "$test_count/sub proj" sub1 &&
|
2015-11-13 10:32:35 +08:00
|
|
|
(
|
2021-04-28 05:17:21 +08:00
|
|
|
cd "$test_count" &&
|
2021-04-28 05:17:20 +08:00
|
|
|
git fetch ./"sub proj" HEAD &&
|
2015-11-13 10:32:35 +08:00
|
|
|
git subtree add --prefix="sub dir" FETCH_HEAD
|
|
|
|
) &&
|
2021-04-28 05:17:21 +08:00
|
|
|
test_create_commit "$test_count/sub proj" sub2 &&
|
2015-11-13 10:32:35 +08:00
|
|
|
(
|
2021-04-28 05:17:21 +08:00
|
|
|
cd "$test_count" &&
|
2021-04-28 05:17:20 +08:00
|
|
|
git fetch ./"sub proj" HEAD &&
|
2015-11-13 10:32:35 +08:00
|
|
|
git subtree merge --prefix="sub dir" FETCH_HEAD &&
|
2021-04-28 05:17:27 +08:00
|
|
|
test "$(last_commit_subject)" = "Merge commit '\''$(git rev-parse FETCH_HEAD)'\''"
|
2015-11-13 10:32:35 +08:00
|
|
|
)
|
2012-01-30 06:09:58 +08:00
|
|
|
'
|
|
|
|
|
2015-11-13 10:32:35 +08:00
|
|
|
test_expect_success 'merge new subproj history into sub dir/ with --prefix and --message' '
|
2021-04-28 05:17:21 +08:00
|
|
|
subtree_test_create_repo "$test_count" &&
|
|
|
|
subtree_test_create_repo "$test_count/sub proj" &&
|
|
|
|
test_create_commit "$test_count" main1 &&
|
|
|
|
test_create_commit "$test_count/sub proj" sub1 &&
|
2015-11-13 10:32:35 +08:00
|
|
|
(
|
2021-04-28 05:17:21 +08:00
|
|
|
cd "$test_count" &&
|
2021-04-28 05:17:20 +08:00
|
|
|
git fetch ./"sub proj" HEAD &&
|
2015-11-13 10:32:35 +08:00
|
|
|
git subtree add --prefix="sub dir" FETCH_HEAD
|
|
|
|
) &&
|
2021-04-28 05:17:21 +08:00
|
|
|
test_create_commit "$test_count/sub proj" sub2 &&
|
2015-11-13 10:32:35 +08:00
|
|
|
(
|
2021-04-28 05:17:21 +08:00
|
|
|
cd "$test_count" &&
|
2021-04-28 05:17:20 +08:00
|
|
|
git fetch ./"sub proj" HEAD &&
|
2015-11-13 10:32:35 +08:00
|
|
|
git subtree merge --prefix="sub dir" --message="Merged changes from subproject" FETCH_HEAD &&
|
2021-04-28 05:17:27 +08:00
|
|
|
test "$(last_commit_subject)" = "Merged changes from subproject"
|
2015-11-13 10:32:35 +08:00
|
|
|
)
|
2012-01-30 06:09:58 +08:00
|
|
|
'
|
|
|
|
|
2015-11-13 10:32:35 +08:00
|
|
|
test_expect_success 'merge new subproj history into sub dir/ with --squash and --prefix and --message' '
|
2021-04-28 05:17:21 +08:00
|
|
|
subtree_test_create_repo "$test_count/sub proj" &&
|
|
|
|
subtree_test_create_repo "$test_count" &&
|
|
|
|
test_create_commit "$test_count" main1 &&
|
|
|
|
test_create_commit "$test_count/sub proj" sub1 &&
|
2015-11-13 10:32:35 +08:00
|
|
|
(
|
2021-04-28 05:17:21 +08:00
|
|
|
cd "$test_count" &&
|
2021-04-28 05:17:20 +08:00
|
|
|
git fetch ./"sub proj" HEAD &&
|
2015-11-13 10:32:35 +08:00
|
|
|
git subtree add --prefix="sub dir" FETCH_HEAD
|
|
|
|
) &&
|
2021-04-28 05:17:21 +08:00
|
|
|
test_create_commit "$test_count/sub proj" sub2 &&
|
2015-11-13 10:32:35 +08:00
|
|
|
(
|
2021-04-28 05:17:21 +08:00
|
|
|
cd "$test_count" &&
|
2021-04-28 05:17:20 +08:00
|
|
|
git fetch ./"sub proj" HEAD &&
|
2015-11-13 10:32:35 +08:00
|
|
|
git subtree merge --prefix="sub dir" --message="Merged changes from subproject using squash" --squash FETCH_HEAD &&
|
2021-04-28 05:17:27 +08:00
|
|
|
test "$(last_commit_subject)" = "Merged changes from subproject using squash"
|
2015-11-13 10:32:35 +08:00
|
|
|
)
|
2012-01-30 06:09:58 +08:00
|
|
|
'
|
|
|
|
|
2015-11-13 10:32:35 +08:00
|
|
|
test_expect_success 'merge the added subproj again, should do nothing' '
|
2021-04-28 05:17:21 +08:00
|
|
|
subtree_test_create_repo "$test_count" &&
|
|
|
|
subtree_test_create_repo "$test_count/sub proj" &&
|
|
|
|
test_create_commit "$test_count" main1 &&
|
|
|
|
test_create_commit "$test_count/sub proj" sub1 &&
|
2015-11-13 10:32:35 +08:00
|
|
|
(
|
2021-04-28 05:17:21 +08:00
|
|
|
cd "$test_count" &&
|
2021-04-28 05:17:20 +08:00
|
|
|
git fetch ./"sub proj" HEAD &&
|
2015-11-13 10:32:35 +08:00
|
|
|
git subtree add --prefix="sub dir" FETCH_HEAD &&
|
|
|
|
# this shouldn not actually do anything, since FETCH_HEAD
|
|
|
|
# is already a parent
|
|
|
|
result=$(git merge -s ours -m "merge -s -ours" FETCH_HEAD) &&
|
2021-04-28 05:17:24 +08:00
|
|
|
test "${result}" = "Already up to date."
|
2015-11-13 10:32:35 +08:00
|
|
|
)
|
2015-11-13 10:32:33 +08:00
|
|
|
'
|
|
|
|
|
2015-11-13 10:32:36 +08:00
|
|
|
test_expect_success 'merge new subproj history into subdir/ with a slash appended to the argument of --prefix' '
|
subtree: t7900: comment subtree_test_create_repo
It's unclear what the purpose of t7900-subtree.sh's
`subtree_test_create_repo` helper function is. It wraps test-lib.sh's,
`test_create_repo` but follows that up by setting log.date=relative. Why
does it set log.date=relative?
My first guess was that at one point the tests required that, but no
longer do, and that the function is now vestigial. I even wrote a patch
to get rid of it and was moments away from `git send-email`ing it.
However, by chance when looking for something else in the history, I
discovered the true reason, from e7aac44ed2 (contrib/subtree: ignore
log.date configuration, 2015-07-21). It's testing that setting
log.date=relative doesn't break `git subtree`, as at one point in the past
that did break `git subtree`.
So, add a comment about this, to avoid future such confusion.
And while at it, go ahead and (1) touch up the function to avoid a
pointless subshell and (2) update the one test that didn't use it.
Signed-off-by: Luke Shumaker <lukeshu@datawire.io>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2021-04-28 05:17:23 +08:00
|
|
|
subtree_test_create_repo "$test_count" &&
|
|
|
|
subtree_test_create_repo "$test_count/subproj" &&
|
2015-11-13 10:32:36 +08:00
|
|
|
test_create_commit "$test_count" main1 &&
|
|
|
|
test_create_commit "$test_count/subproj" sub1 &&
|
|
|
|
(
|
|
|
|
cd "$test_count" &&
|
2021-04-28 05:17:20 +08:00
|
|
|
git fetch ./subproj HEAD &&
|
2015-11-13 10:32:36 +08:00
|
|
|
git subtree add --prefix=subdir/ FETCH_HEAD
|
|
|
|
) &&
|
|
|
|
test_create_commit "$test_count/subproj" sub2 &&
|
|
|
|
(
|
|
|
|
cd "$test_count" &&
|
2021-04-28 05:17:20 +08:00
|
|
|
git fetch ./subproj HEAD &&
|
2015-11-13 10:32:36 +08:00
|
|
|
git subtree merge --prefix=subdir/ FETCH_HEAD &&
|
2021-04-28 05:17:27 +08:00
|
|
|
test "$(last_commit_subject)" = "Merge commit '\''$(git rev-parse FETCH_HEAD)'\''"
|
2015-11-13 10:32:36 +08:00
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2015-11-13 10:32:35 +08:00
|
|
|
#
|
|
|
|
# Tests for 'git subtree split'
|
|
|
|
#
|
2015-11-13 10:32:33 +08:00
|
|
|
|
2015-11-13 10:32:30 +08:00
|
|
|
test_expect_success 'split requires option --prefix' '
|
2021-04-28 05:17:21 +08:00
|
|
|
subtree_test_create_repo "$test_count" &&
|
|
|
|
subtree_test_create_repo "$test_count/sub proj" &&
|
|
|
|
test_create_commit "$test_count" main1 &&
|
|
|
|
test_create_commit "$test_count/sub proj" sub1 &&
|
2015-11-13 10:32:35 +08:00
|
|
|
(
|
2021-04-28 05:17:21 +08:00
|
|
|
cd "$test_count" &&
|
2021-04-28 05:17:20 +08:00
|
|
|
git fetch ./"sub proj" HEAD &&
|
2015-11-13 10:32:35 +08:00
|
|
|
git subtree add --prefix="sub dir" FETCH_HEAD &&
|
2021-04-28 05:17:22 +08:00
|
|
|
echo "You must provide the --prefix option." >expected &&
|
|
|
|
test_must_fail git subtree split >actual 2>&1 &&
|
2015-11-13 10:32:35 +08:00
|
|
|
test_debug "printf '"expected: "'" &&
|
|
|
|
test_debug "cat expected" &&
|
|
|
|
test_debug "printf '"actual: "'" &&
|
|
|
|
test_debug "cat actual" &&
|
|
|
|
test_cmp expected actual
|
|
|
|
)
|
2012-01-30 06:09:58 +08:00
|
|
|
'
|
|
|
|
|
2015-11-13 10:32:30 +08:00
|
|
|
test_expect_success 'split requires path given by option --prefix must exist' '
|
2021-04-28 05:17:21 +08:00
|
|
|
subtree_test_create_repo "$test_count" &&
|
|
|
|
subtree_test_create_repo "$test_count/sub proj" &&
|
|
|
|
test_create_commit "$test_count" main1 &&
|
|
|
|
test_create_commit "$test_count/sub proj" sub1 &&
|
2015-11-13 10:32:35 +08:00
|
|
|
(
|
2021-04-28 05:17:21 +08:00
|
|
|
cd "$test_count" &&
|
2021-04-28 05:17:20 +08:00
|
|
|
git fetch ./"sub proj" HEAD &&
|
2015-11-13 10:32:35 +08:00
|
|
|
git subtree add --prefix="sub dir" FETCH_HEAD &&
|
2021-04-28 05:17:22 +08:00
|
|
|
echo "'\''non-existent-directory'\'' does not exist; use '\''git subtree add'\''" >expected &&
|
|
|
|
test_must_fail git subtree split --prefix=non-existent-directory >actual 2>&1 &&
|
2015-11-13 10:32:35 +08:00
|
|
|
test_debug "printf '"expected: "'" &&
|
|
|
|
test_debug "cat expected" &&
|
|
|
|
test_debug "printf '"actual: "'" &&
|
|
|
|
test_debug "cat actual" &&
|
|
|
|
test_cmp expected actual
|
|
|
|
)
|
2012-01-30 06:09:58 +08:00
|
|
|
'
|
|
|
|
|
2015-11-13 10:32:34 +08:00
|
|
|
test_expect_success 'split sub dir/ with --rejoin' '
|
2021-04-28 05:17:21 +08:00
|
|
|
subtree_test_create_repo "$test_count" &&
|
|
|
|
subtree_test_create_repo "$test_count/sub proj" &&
|
|
|
|
test_create_commit "$test_count" main1 &&
|
|
|
|
test_create_commit "$test_count/sub proj" sub1 &&
|
2015-11-13 10:32:35 +08:00
|
|
|
(
|
2021-04-28 05:17:21 +08:00
|
|
|
cd "$test_count" &&
|
2021-04-28 05:17:20 +08:00
|
|
|
git fetch ./"sub proj" HEAD &&
|
2015-11-13 10:32:35 +08:00
|
|
|
git subtree add --prefix="sub dir" FETCH_HEAD
|
|
|
|
) &&
|
2021-04-28 05:17:21 +08:00
|
|
|
test_create_commit "$test_count" "sub dir"/main-sub1 &&
|
|
|
|
test_create_commit "$test_count" main2 &&
|
|
|
|
test_create_commit "$test_count/sub proj" sub2 &&
|
|
|
|
test_create_commit "$test_count" "sub dir"/main-sub2 &&
|
2015-11-13 10:32:35 +08:00
|
|
|
(
|
2021-04-28 05:17:21 +08:00
|
|
|
cd "$test_count" &&
|
2021-04-28 05:17:20 +08:00
|
|
|
git fetch ./"sub proj" HEAD &&
|
2015-11-13 10:32:35 +08:00
|
|
|
git subtree merge --prefix="sub dir" FETCH_HEAD &&
|
|
|
|
split_hash=$(git subtree split --prefix="sub dir" --annotate="*") &&
|
|
|
|
git subtree split --prefix="sub dir" --annotate="*" --rejoin &&
|
2021-04-28 05:17:27 +08:00
|
|
|
test "$(last_commit_subject)" = "Split '\''sub dir/'\'' into commit '\''$split_hash'\''"
|
2015-11-13 10:32:35 +08:00
|
|
|
)
|
2021-04-28 05:17:22 +08:00
|
|
|
'
|
2015-11-13 10:32:34 +08:00
|
|
|
|
2016-07-26 12:14:15 +08:00
|
|
|
test_expect_success 'split sub dir/ with --rejoin from scratch' '
|
2021-04-28 05:17:21 +08:00
|
|
|
subtree_test_create_repo "$test_count" &&
|
|
|
|
test_create_commit "$test_count" main1 &&
|
2016-07-26 12:14:15 +08:00
|
|
|
(
|
2021-04-28 05:17:21 +08:00
|
|
|
cd "$test_count" &&
|
2016-07-26 12:14:15 +08:00
|
|
|
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 &&
|
2021-04-28 05:17:27 +08:00
|
|
|
test "$(last_commit_subject)" = "Split '\''sub dir/'\'' into commit '\''$split_hash'\''"
|
2016-07-26 12:14:15 +08:00
|
|
|
)
|
2021-04-28 05:17:22 +08:00
|
|
|
'
|
2016-07-26 12:14:15 +08:00
|
|
|
|
2015-11-13 10:32:34 +08:00
|
|
|
test_expect_success 'split sub dir/ with --rejoin and --message' '
|
2021-04-28 05:17:21 +08:00
|
|
|
subtree_test_create_repo "$test_count" &&
|
|
|
|
subtree_test_create_repo "$test_count/sub proj" &&
|
|
|
|
test_create_commit "$test_count" main1 &&
|
|
|
|
test_create_commit "$test_count/sub proj" sub1 &&
|
2015-11-13 10:32:35 +08:00
|
|
|
(
|
2021-04-28 05:17:21 +08:00
|
|
|
cd "$test_count" &&
|
2021-04-28 05:17:20 +08:00
|
|
|
git fetch ./"sub proj" HEAD &&
|
2015-11-13 10:32:35 +08:00
|
|
|
git subtree add --prefix="sub dir" FETCH_HEAD
|
|
|
|
) &&
|
2021-04-28 05:17:21 +08:00
|
|
|
test_create_commit "$test_count" "sub dir"/main-sub1 &&
|
|
|
|
test_create_commit "$test_count" main2 &&
|
|
|
|
test_create_commit "$test_count/sub proj" sub2 &&
|
|
|
|
test_create_commit "$test_count" "sub dir"/main-sub2 &&
|
2015-11-13 10:32:35 +08:00
|
|
|
(
|
2021-04-28 05:17:21 +08:00
|
|
|
cd "$test_count" &&
|
2021-04-28 05:17:20 +08:00
|
|
|
git fetch ./"sub proj" HEAD &&
|
2015-11-13 10:32:35 +08:00
|
|
|
git subtree merge --prefix="sub dir" FETCH_HEAD &&
|
|
|
|
git subtree split --prefix="sub dir" --message="Split & rejoin" --annotate="*" --rejoin &&
|
2021-04-28 05:17:27 +08:00
|
|
|
test "$(last_commit_subject)" = "Split & rejoin"
|
2015-11-13 10:32:35 +08:00
|
|
|
)
|
2012-01-30 06:09:58 +08:00
|
|
|
'
|
|
|
|
|
2015-11-13 10:32:35 +08:00
|
|
|
test_expect_success 'split "sub dir"/ with --branch' '
|
2021-04-28 05:17:21 +08:00
|
|
|
subtree_test_create_repo "$test_count" &&
|
|
|
|
subtree_test_create_repo "$test_count/sub proj" &&
|
|
|
|
test_create_commit "$test_count" main1 &&
|
|
|
|
test_create_commit "$test_count/sub proj" sub1 &&
|
2015-11-13 10:32:35 +08:00
|
|
|
(
|
2021-04-28 05:17:21 +08:00
|
|
|
cd "$test_count" &&
|
2021-04-28 05:17:20 +08:00
|
|
|
git fetch ./"sub proj" HEAD &&
|
2015-11-13 10:32:35 +08:00
|
|
|
git subtree add --prefix="sub dir" FETCH_HEAD
|
|
|
|
) &&
|
2021-04-28 05:17:21 +08:00
|
|
|
test_create_commit "$test_count" "sub dir"/main-sub1 &&
|
|
|
|
test_create_commit "$test_count" main2 &&
|
|
|
|
test_create_commit "$test_count/sub proj" sub2 &&
|
|
|
|
test_create_commit "$test_count" "sub dir"/main-sub2 &&
|
2015-11-13 10:32:35 +08:00
|
|
|
(
|
2021-04-28 05:17:21 +08:00
|
|
|
cd "$test_count" &&
|
2021-04-28 05:17:20 +08:00
|
|
|
git fetch ./"sub proj" HEAD &&
|
2015-11-13 10:32:35 +08:00
|
|
|
git subtree merge --prefix="sub dir" FETCH_HEAD &&
|
|
|
|
split_hash=$(git subtree split --prefix="sub dir" --annotate="*") &&
|
|
|
|
git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br &&
|
2021-04-28 05:17:24 +08:00
|
|
|
test "$(git rev-parse subproj-br)" = "$split_hash"
|
2015-11-13 10:32:35 +08:00
|
|
|
)
|
2012-01-30 06:09:58 +08:00
|
|
|
'
|
|
|
|
|
2015-11-13 10:32:35 +08:00
|
|
|
test_expect_success 'check hash of split' '
|
2021-04-28 05:17:21 +08:00
|
|
|
subtree_test_create_repo "$test_count" &&
|
|
|
|
subtree_test_create_repo "$test_count/sub proj" &&
|
|
|
|
test_create_commit "$test_count" main1 &&
|
|
|
|
test_create_commit "$test_count/sub proj" sub1 &&
|
2015-11-13 10:32:35 +08:00
|
|
|
(
|
2021-04-28 05:17:21 +08:00
|
|
|
cd "$test_count" &&
|
2021-04-28 05:17:20 +08:00
|
|
|
git fetch ./"sub proj" HEAD &&
|
2015-11-13 10:32:35 +08:00
|
|
|
git subtree add --prefix="sub dir" FETCH_HEAD
|
|
|
|
) &&
|
2021-04-28 05:17:21 +08:00
|
|
|
test_create_commit "$test_count" "sub dir"/main-sub1 &&
|
|
|
|
test_create_commit "$test_count" main2 &&
|
|
|
|
test_create_commit "$test_count/sub proj" sub2 &&
|
|
|
|
test_create_commit "$test_count" "sub dir"/main-sub2 &&
|
2015-11-13 10:32:35 +08:00
|
|
|
(
|
2021-04-28 05:17:21 +08:00
|
|
|
cd "$test_count" &&
|
2021-04-28 05:17:20 +08:00
|
|
|
git fetch ./"sub proj" HEAD &&
|
2015-11-13 10:32:35 +08:00
|
|
|
git subtree merge --prefix="sub dir" FETCH_HEAD &&
|
|
|
|
split_hash=$(git subtree split --prefix="sub dir" --annotate="*") &&
|
|
|
|
git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br &&
|
2021-04-28 05:17:24 +08:00
|
|
|
test "$(git rev-parse subproj-br)" = "$split_hash" &&
|
2015-11-13 10:32:35 +08:00
|
|
|
# Check hash of split
|
|
|
|
new_hash=$(git rev-parse subproj-br^2) &&
|
|
|
|
(
|
|
|
|
cd ./"sub proj" &&
|
|
|
|
subdir_hash=$(git rev-parse HEAD) &&
|
2021-04-28 05:17:25 +08:00
|
|
|
test "$new_hash" = "$subdir_hash"
|
2015-11-13 10:32:35 +08:00
|
|
|
)
|
|
|
|
)
|
2012-01-30 06:09:58 +08:00
|
|
|
'
|
|
|
|
|
2015-11-13 10:32:35 +08:00
|
|
|
test_expect_success 'split "sub dir"/ with --branch for an existing branch' '
|
2021-04-28 05:17:21 +08:00
|
|
|
subtree_test_create_repo "$test_count" &&
|
|
|
|
subtree_test_create_repo "$test_count/sub proj" &&
|
|
|
|
test_create_commit "$test_count" main1 &&
|
|
|
|
test_create_commit "$test_count/sub proj" sub1 &&
|
2015-11-13 10:32:35 +08:00
|
|
|
(
|
2021-04-28 05:17:21 +08:00
|
|
|
cd "$test_count" &&
|
2021-04-28 05:17:20 +08:00
|
|
|
git fetch ./"sub proj" HEAD &&
|
2015-11-13 10:32:35 +08:00
|
|
|
git branch subproj-br FETCH_HEAD &&
|
|
|
|
git subtree add --prefix="sub dir" FETCH_HEAD
|
|
|
|
) &&
|
2021-04-28 05:17:21 +08:00
|
|
|
test_create_commit "$test_count" "sub dir"/main-sub1 &&
|
|
|
|
test_create_commit "$test_count" main2 &&
|
|
|
|
test_create_commit "$test_count/sub proj" sub2 &&
|
|
|
|
test_create_commit "$test_count" "sub dir"/main-sub2 &&
|
2015-11-13 10:32:35 +08:00
|
|
|
(
|
2021-04-28 05:17:21 +08:00
|
|
|
cd "$test_count" &&
|
2021-04-28 05:17:20 +08:00
|
|
|
git fetch ./"sub proj" HEAD &&
|
2015-11-13 10:32:35 +08:00
|
|
|
git subtree merge --prefix="sub dir" FETCH_HEAD &&
|
|
|
|
split_hash=$(git subtree split --prefix="sub dir" --annotate="*") &&
|
|
|
|
git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br &&
|
2021-04-28 05:17:24 +08:00
|
|
|
test "$(git rev-parse subproj-br)" = "$split_hash"
|
2015-11-13 10:32:35 +08:00
|
|
|
)
|
2012-01-30 06:09:58 +08:00
|
|
|
'
|
|
|
|
|
2015-11-13 10:32:35 +08:00
|
|
|
test_expect_success 'split "sub dir"/ with --branch for an incompatible branch' '
|
2021-04-28 05:17:21 +08:00
|
|
|
subtree_test_create_repo "$test_count" &&
|
|
|
|
subtree_test_create_repo "$test_count/sub proj" &&
|
|
|
|
test_create_commit "$test_count" main1 &&
|
|
|
|
test_create_commit "$test_count/sub proj" sub1 &&
|
2015-11-13 10:32:35 +08:00
|
|
|
(
|
2021-04-28 05:17:21 +08:00
|
|
|
cd "$test_count" &&
|
2015-11-13 10:32:35 +08:00
|
|
|
git branch init HEAD &&
|
2021-04-28 05:17:20 +08:00
|
|
|
git fetch ./"sub proj" HEAD &&
|
2015-11-13 10:32:35 +08:00
|
|
|
git subtree add --prefix="sub dir" FETCH_HEAD
|
|
|
|
) &&
|
2021-04-28 05:17:21 +08:00
|
|
|
test_create_commit "$test_count" "sub dir"/main-sub1 &&
|
|
|
|
test_create_commit "$test_count" main2 &&
|
|
|
|
test_create_commit "$test_count/sub proj" sub2 &&
|
|
|
|
test_create_commit "$test_count" "sub dir"/main-sub2 &&
|
2015-11-13 10:32:35 +08:00
|
|
|
(
|
2021-04-28 05:17:21 +08:00
|
|
|
cd "$test_count" &&
|
2021-04-28 05:17:20 +08:00
|
|
|
git fetch ./"sub proj" HEAD &&
|
2015-11-13 10:32:35 +08:00
|
|
|
git subtree merge --prefix="sub dir" FETCH_HEAD &&
|
|
|
|
test_must_fail git subtree split --prefix="sub dir" --branch init
|
|
|
|
)
|
2012-01-30 06:09:58 +08:00
|
|
|
'
|
2009-04-25 09:35:50 +08:00
|
|
|
|
2021-04-28 05:17:29 +08:00
|
|
|
#
|
|
|
|
# Tests for 'git subtree pull'
|
|
|
|
#
|
|
|
|
|
|
|
|
test_expect_success 'pull requires option --prefix' '
|
|
|
|
subtree_test_create_repo "$test_count" &&
|
|
|
|
subtree_test_create_repo "$test_count/sub proj" &&
|
|
|
|
test_create_commit "$test_count" main1 &&
|
|
|
|
test_create_commit "$test_count/sub proj" sub1 &&
|
|
|
|
(
|
|
|
|
cd "$test_count" &&
|
|
|
|
git fetch ./"sub proj" HEAD &&
|
|
|
|
git subtree add --prefix="sub dir" FETCH_HEAD
|
|
|
|
) &&
|
|
|
|
test_create_commit "$test_count/sub proj" sub2 &&
|
|
|
|
(
|
|
|
|
cd "$test_count" &&
|
|
|
|
test_must_fail git subtree pull ./"sub proj" HEAD >out 2>err &&
|
|
|
|
|
|
|
|
echo "You must provide the --prefix option." >expected &&
|
|
|
|
test_must_be_empty out &&
|
|
|
|
test_cmp expected err
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'pull requires path given by option --prefix must exist' '
|
|
|
|
subtree_test_create_repo "$test_count" &&
|
|
|
|
subtree_test_create_repo "$test_count/sub proj" &&
|
|
|
|
test_create_commit "$test_count" main1 &&
|
|
|
|
test_create_commit "$test_count/sub proj" sub1 &&
|
|
|
|
(
|
|
|
|
test_must_fail git subtree pull --prefix="sub dir" ./"sub proj" HEAD >out 2>err &&
|
|
|
|
|
|
|
|
echo "'\''sub dir'\'' does not exist; use '\''git subtree add'\''" >expected &&
|
|
|
|
test_must_be_empty out &&
|
|
|
|
test_cmp expected err
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'pull basic operation' '
|
|
|
|
subtree_test_create_repo "$test_count" &&
|
|
|
|
subtree_test_create_repo "$test_count/sub proj" &&
|
|
|
|
test_create_commit "$test_count" main1 &&
|
|
|
|
test_create_commit "$test_count/sub proj" sub1 &&
|
|
|
|
(
|
|
|
|
cd "$test_count" &&
|
|
|
|
git fetch ./"sub proj" HEAD &&
|
|
|
|
git subtree add --prefix="sub dir" FETCH_HEAD
|
|
|
|
) &&
|
|
|
|
test_create_commit "$test_count/sub proj" sub2 &&
|
|
|
|
(
|
|
|
|
cd "$test_count" &&
|
|
|
|
exp=$(git -C "sub proj" rev-parse --verify HEAD:) &&
|
|
|
|
git subtree pull --prefix="sub dir" ./"sub proj" HEAD &&
|
|
|
|
act=$(git rev-parse --verify HEAD:"sub dir") &&
|
|
|
|
test "$act" = "$exp"
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
|
|
|
#
|
|
|
|
# Tests for 'git subtree push'
|
|
|
|
#
|
|
|
|
|
|
|
|
test_expect_success 'push requires option --prefix' '
|
|
|
|
subtree_test_create_repo "$test_count" &&
|
|
|
|
subtree_test_create_repo "$test_count/sub proj" &&
|
|
|
|
test_create_commit "$test_count" main1 &&
|
|
|
|
test_create_commit "$test_count/sub proj" sub1 &&
|
|
|
|
(
|
|
|
|
cd "$test_count" &&
|
|
|
|
git fetch ./"sub proj" HEAD &&
|
|
|
|
git subtree add --prefix="sub dir" FETCH_HEAD &&
|
|
|
|
echo "You must provide the --prefix option." >expected &&
|
|
|
|
test_must_fail git subtree push "./sub proj" from-mainline >actual 2>&1 &&
|
|
|
|
test_debug "printf '"expected: "'" &&
|
|
|
|
test_debug "cat expected" &&
|
|
|
|
test_debug "printf '"actual: "'" &&
|
|
|
|
test_debug "cat actual" &&
|
|
|
|
test_cmp expected actual
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'push requires path given by option --prefix must exist' '
|
|
|
|
subtree_test_create_repo "$test_count" &&
|
|
|
|
subtree_test_create_repo "$test_count/sub proj" &&
|
|
|
|
test_create_commit "$test_count" main1 &&
|
|
|
|
test_create_commit "$test_count/sub proj" sub1 &&
|
|
|
|
(
|
|
|
|
cd "$test_count" &&
|
|
|
|
git fetch ./"sub proj" HEAD &&
|
|
|
|
git subtree add --prefix="sub dir" FETCH_HEAD &&
|
|
|
|
echo "'\''non-existent-directory'\'' does not exist; use '\''git subtree add'\''" >expected &&
|
|
|
|
test_must_fail git subtree push --prefix=non-existent-directory "./sub proj" from-mainline >actual 2>&1 &&
|
|
|
|
test_debug "printf '"expected: "'" &&
|
|
|
|
test_debug "cat expected" &&
|
|
|
|
test_debug "printf '"actual: "'" &&
|
|
|
|
test_debug "cat actual" &&
|
|
|
|
test_cmp expected actual
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'push basic operation' '
|
|
|
|
subtree_test_create_repo "$test_count" &&
|
|
|
|
subtree_test_create_repo "$test_count/sub proj" &&
|
|
|
|
test_create_commit "$test_count" main1 &&
|
|
|
|
test_create_commit "$test_count/sub proj" sub1 &&
|
|
|
|
(
|
|
|
|
cd "$test_count" &&
|
|
|
|
git fetch ./"sub proj" HEAD &&
|
|
|
|
git subtree add --prefix="sub dir" FETCH_HEAD
|
|
|
|
) &&
|
|
|
|
test_create_commit "$test_count" "sub dir"/main-sub1 &&
|
|
|
|
test_create_commit "$test_count" main2 &&
|
|
|
|
test_create_commit "$test_count/sub proj" sub2 &&
|
|
|
|
test_create_commit "$test_count" "sub dir"/main-sub2 &&
|
|
|
|
(
|
|
|
|
cd "$test_count" &&
|
|
|
|
git fetch ./"sub proj" HEAD &&
|
|
|
|
git subtree merge --prefix="sub dir" FETCH_HEAD &&
|
|
|
|
before=$(git rev-parse --verify HEAD) &&
|
|
|
|
split_hash=$(git subtree split --prefix="sub dir") &&
|
|
|
|
git subtree push --prefix="sub dir" ./"sub proj" from-mainline &&
|
|
|
|
test "$before" = "$(git rev-parse --verify HEAD)" &&
|
|
|
|
test "$split_hash" = "$(git -C "sub proj" rev-parse --verify refs/heads/from-mainline)"
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2015-11-13 10:32:35 +08:00
|
|
|
#
|
|
|
|
# Validity checking
|
|
|
|
#
|
2015-11-13 10:32:30 +08:00
|
|
|
|
2015-11-13 10:32:35 +08:00
|
|
|
test_expect_success 'make sure exactly the right set of files ends up in the subproj' '
|
2021-04-28 05:17:21 +08:00
|
|
|
subtree_test_create_repo "$test_count" &&
|
|
|
|
subtree_test_create_repo "$test_count/sub proj" &&
|
|
|
|
test_create_commit "$test_count" main1 &&
|
|
|
|
test_create_commit "$test_count/sub proj" sub1 &&
|
2015-11-13 10:32:35 +08:00
|
|
|
(
|
2021-04-28 05:17:21 +08:00
|
|
|
cd "$test_count" &&
|
2021-04-28 05:17:20 +08:00
|
|
|
git fetch ./"sub proj" HEAD &&
|
2015-11-13 10:32:35 +08:00
|
|
|
git subtree add --prefix="sub dir" FETCH_HEAD
|
|
|
|
) &&
|
2021-04-28 05:17:21 +08:00
|
|
|
test_create_commit "$test_count" "sub dir"/main-sub1 &&
|
|
|
|
test_create_commit "$test_count" main2 &&
|
|
|
|
test_create_commit "$test_count/sub proj" sub2 &&
|
|
|
|
test_create_commit "$test_count" "sub dir"/main-sub2 &&
|
2015-11-13 10:32:35 +08:00
|
|
|
(
|
2021-04-28 05:17:21 +08:00
|
|
|
cd "$test_count" &&
|
2021-04-28 05:17:20 +08:00
|
|
|
git fetch ./"sub proj" HEAD &&
|
2015-11-13 10:32:35 +08:00
|
|
|
git subtree merge --prefix="sub dir" FETCH_HEAD &&
|
|
|
|
git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
|
|
|
|
) &&
|
2021-04-28 05:17:21 +08:00
|
|
|
test_create_commit "$test_count/sub proj" sub3 &&
|
|
|
|
test_create_commit "$test_count" "sub dir"/main-sub3 &&
|
2015-11-13 10:32:35 +08:00
|
|
|
(
|
2021-04-28 05:17:21 +08:00
|
|
|
cd "$test_count/sub proj" &&
|
2015-11-13 10:32:35 +08:00
|
|
|
git fetch .. subproj-br &&
|
|
|
|
git merge FETCH_HEAD
|
|
|
|
) &&
|
2021-04-28 05:17:21 +08:00
|
|
|
test_create_commit "$test_count/sub proj" sub4 &&
|
2015-11-13 10:32:35 +08:00
|
|
|
(
|
2021-04-28 05:17:21 +08:00
|
|
|
cd "$test_count" &&
|
2015-11-13 10:32:35 +08:00
|
|
|
git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
|
|
|
|
) &&
|
2021-04-28 05:17:21 +08:00
|
|
|
test_create_commit "$test_count" "sub dir"/main-sub4 &&
|
2015-11-13 10:32:35 +08:00
|
|
|
(
|
2021-04-28 05:17:21 +08:00
|
|
|
cd "$test_count" &&
|
2015-11-13 10:32:35 +08:00
|
|
|
git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
|
|
|
|
) &&
|
|
|
|
(
|
2021-04-28 05:17:21 +08:00
|
|
|
cd "$test_count/sub proj" &&
|
2015-11-13 10:32:35 +08:00
|
|
|
git fetch .. subproj-br &&
|
|
|
|
git merge FETCH_HEAD &&
|
|
|
|
|
2018-07-31 03:07:38 +08:00
|
|
|
test_write_lines main-sub1 main-sub2 main-sub3 main-sub4 \
|
|
|
|
sub1 sub2 sub3 sub4 >expect &&
|
|
|
|
git ls-files >actual &&
|
|
|
|
test_cmp expect actual
|
2015-11-13 10:32:35 +08:00
|
|
|
)
|
2012-01-30 06:09:58 +08:00
|
|
|
'
|
2015-11-13 10:32:30 +08:00
|
|
|
|
2015-11-13 10:32:35 +08:00
|
|
|
test_expect_success 'make sure the subproj *only* contains commits that affect the "sub dir"' '
|
2021-04-28 05:17:21 +08:00
|
|
|
subtree_test_create_repo "$test_count" &&
|
|
|
|
subtree_test_create_repo "$test_count/sub proj" &&
|
|
|
|
test_create_commit "$test_count" main1 &&
|
|
|
|
test_create_commit "$test_count/sub proj" sub1 &&
|
2015-11-13 10:32:35 +08:00
|
|
|
(
|
2021-04-28 05:17:21 +08:00
|
|
|
cd "$test_count" &&
|
2021-04-28 05:17:20 +08:00
|
|
|
git fetch ./"sub proj" HEAD &&
|
2015-11-13 10:32:35 +08:00
|
|
|
git subtree add --prefix="sub dir" FETCH_HEAD
|
|
|
|
) &&
|
2021-04-28 05:17:21 +08:00
|
|
|
test_create_commit "$test_count" "sub dir"/main-sub1 &&
|
|
|
|
test_create_commit "$test_count" main2 &&
|
|
|
|
test_create_commit "$test_count/sub proj" sub2 &&
|
|
|
|
test_create_commit "$test_count" "sub dir"/main-sub2 &&
|
2015-11-13 10:32:35 +08:00
|
|
|
(
|
2021-04-28 05:17:21 +08:00
|
|
|
cd "$test_count" &&
|
2021-04-28 05:17:20 +08:00
|
|
|
git fetch ./"sub proj" HEAD &&
|
2015-11-13 10:32:35 +08:00
|
|
|
git subtree merge --prefix="sub dir" FETCH_HEAD &&
|
|
|
|
git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
|
|
|
|
) &&
|
2021-04-28 05:17:21 +08:00
|
|
|
test_create_commit "$test_count/sub proj" sub3 &&
|
|
|
|
test_create_commit "$test_count" "sub dir"/main-sub3 &&
|
2015-11-13 10:32:35 +08:00
|
|
|
(
|
2021-04-28 05:17:21 +08:00
|
|
|
cd "$test_count/sub proj" &&
|
2015-11-13 10:32:35 +08:00
|
|
|
git fetch .. subproj-br &&
|
|
|
|
git merge FETCH_HEAD
|
|
|
|
) &&
|
2021-04-28 05:17:21 +08:00
|
|
|
test_create_commit "$test_count/sub proj" sub4 &&
|
2015-11-13 10:32:35 +08:00
|
|
|
(
|
2021-04-28 05:17:21 +08:00
|
|
|
cd "$test_count" &&
|
2015-11-13 10:32:35 +08:00
|
|
|
git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
|
|
|
|
) &&
|
2021-04-28 05:17:21 +08:00
|
|
|
test_create_commit "$test_count" "sub dir"/main-sub4 &&
|
2015-11-13 10:32:35 +08:00
|
|
|
(
|
2021-04-28 05:17:21 +08:00
|
|
|
cd "$test_count" &&
|
2015-11-13 10:32:35 +08:00
|
|
|
git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
|
|
|
|
) &&
|
|
|
|
(
|
2021-04-28 05:17:21 +08:00
|
|
|
cd "$test_count/sub proj" &&
|
2015-11-13 10:32:35 +08:00
|
|
|
git fetch .. subproj-br &&
|
|
|
|
git merge FETCH_HEAD &&
|
|
|
|
|
2018-07-31 03:07:38 +08:00
|
|
|
test_write_lines main-sub1 main-sub2 main-sub3 main-sub4 \
|
|
|
|
sub1 sub2 sub3 sub4 >expect &&
|
|
|
|
git log --name-only --pretty=format:"" >log &&
|
|
|
|
sort <log | sed "/^\$/ d" >actual &&
|
|
|
|
test_cmp expect actual
|
2015-11-13 10:32:35 +08:00
|
|
|
)
|
2012-01-30 06:09:58 +08:00
|
|
|
'
|
2009-04-27 04:28:56 +08:00
|
|
|
|
2012-01-30 06:09:58 +08:00
|
|
|
test_expect_success 'make sure exactly the right set of files ends up in the mainline' '
|
2021-04-28 05:17:21 +08:00
|
|
|
subtree_test_create_repo "$test_count" &&
|
|
|
|
subtree_test_create_repo "$test_count/sub proj" &&
|
|
|
|
test_create_commit "$test_count" main1 &&
|
|
|
|
test_create_commit "$test_count/sub proj" sub1 &&
|
2015-11-13 10:32:35 +08:00
|
|
|
(
|
2021-04-28 05:17:21 +08:00
|
|
|
cd "$test_count" &&
|
2021-04-28 05:17:20 +08:00
|
|
|
git fetch ./"sub proj" HEAD &&
|
2015-11-13 10:32:35 +08:00
|
|
|
git subtree add --prefix="sub dir" FETCH_HEAD
|
|
|
|
) &&
|
2021-04-28 05:17:21 +08:00
|
|
|
test_create_commit "$test_count" "sub dir"/main-sub1 &&
|
|
|
|
test_create_commit "$test_count" main2 &&
|
|
|
|
test_create_commit "$test_count/sub proj" sub2 &&
|
|
|
|
test_create_commit "$test_count" "sub dir"/main-sub2 &&
|
2015-11-13 10:32:35 +08:00
|
|
|
(
|
2021-04-28 05:17:21 +08:00
|
|
|
cd "$test_count" &&
|
2021-04-28 05:17:20 +08:00
|
|
|
git fetch ./"sub proj" HEAD &&
|
2015-11-13 10:32:35 +08:00
|
|
|
git subtree merge --prefix="sub dir" FETCH_HEAD &&
|
|
|
|
git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
|
|
|
|
) &&
|
2021-04-28 05:17:21 +08:00
|
|
|
test_create_commit "$test_count/sub proj" sub3 &&
|
|
|
|
test_create_commit "$test_count" "sub dir"/main-sub3 &&
|
2015-11-13 10:32:35 +08:00
|
|
|
(
|
2021-04-28 05:17:21 +08:00
|
|
|
cd "$test_count/sub proj" &&
|
2015-11-13 10:32:35 +08:00
|
|
|
git fetch .. subproj-br &&
|
|
|
|
git merge FETCH_HEAD
|
|
|
|
) &&
|
2021-04-28 05:17:21 +08:00
|
|
|
test_create_commit "$test_count/sub proj" sub4 &&
|
2015-11-13 10:32:35 +08:00
|
|
|
(
|
2021-04-28 05:17:21 +08:00
|
|
|
cd "$test_count" &&
|
2015-11-13 10:32:35 +08:00
|
|
|
git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
|
|
|
|
) &&
|
2021-04-28 05:17:21 +08:00
|
|
|
test_create_commit "$test_count" "sub dir"/main-sub4 &&
|
2015-11-13 10:32:35 +08:00
|
|
|
(
|
2021-04-28 05:17:21 +08:00
|
|
|
cd "$test_count" &&
|
2015-11-13 10:32:35 +08:00
|
|
|
git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
|
|
|
|
) &&
|
|
|
|
(
|
2021-04-28 05:17:21 +08:00
|
|
|
cd "$test_count/sub proj" &&
|
2015-11-13 10:32:35 +08:00
|
|
|
git fetch .. subproj-br &&
|
|
|
|
git merge FETCH_HEAD
|
|
|
|
) &&
|
|
|
|
(
|
2021-04-28 05:17:21 +08:00
|
|
|
cd "$test_count" &&
|
2021-04-28 05:17:20 +08:00
|
|
|
git subtree pull --prefix="sub dir" ./"sub proj" HEAD &&
|
2015-11-13 10:32:35 +08:00
|
|
|
|
2018-07-31 03:07:38 +08:00
|
|
|
test_write_lines main1 main2 >chkm &&
|
|
|
|
test_write_lines main-sub1 main-sub2 main-sub3 main-sub4 >chkms &&
|
|
|
|
sed "s,^,sub dir/," chkms >chkms_sub &&
|
|
|
|
test_write_lines sub1 sub2 sub3 sub4 >chks &&
|
|
|
|
sed "s,^,sub dir/," chks >chks_sub &&
|
|
|
|
|
|
|
|
cat chkm chkms_sub chks_sub >expect &&
|
|
|
|
git ls-files >actual &&
|
|
|
|
test_cmp expect actual
|
|
|
|
)
|
2012-01-30 06:09:58 +08:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'make sure each filename changed exactly once in the entire history' '
|
2021-04-28 05:17:21 +08:00
|
|
|
subtree_test_create_repo "$test_count" &&
|
|
|
|
subtree_test_create_repo "$test_count/sub proj" &&
|
|
|
|
test_create_commit "$test_count" main1 &&
|
|
|
|
test_create_commit "$test_count/sub proj" sub1 &&
|
2015-11-13 10:32:35 +08:00
|
|
|
(
|
2021-04-28 05:17:21 +08:00
|
|
|
cd "$test_count" &&
|
2018-07-31 03:07:02 +08:00
|
|
|
git config log.date relative &&
|
2021-04-28 05:17:20 +08:00
|
|
|
git fetch ./"sub proj" HEAD &&
|
2015-11-13 10:32:35 +08:00
|
|
|
git subtree add --prefix="sub dir" FETCH_HEAD
|
|
|
|
) &&
|
2021-04-28 05:17:21 +08:00
|
|
|
test_create_commit "$test_count" "sub dir"/main-sub1 &&
|
|
|
|
test_create_commit "$test_count" main2 &&
|
|
|
|
test_create_commit "$test_count/sub proj" sub2 &&
|
|
|
|
test_create_commit "$test_count" "sub dir"/main-sub2 &&
|
2015-11-13 10:32:35 +08:00
|
|
|
(
|
2021-04-28 05:17:21 +08:00
|
|
|
cd "$test_count" &&
|
2021-04-28 05:17:20 +08:00
|
|
|
git fetch ./"sub proj" HEAD &&
|
2015-11-13 10:32:35 +08:00
|
|
|
git subtree merge --prefix="sub dir" FETCH_HEAD &&
|
|
|
|
git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
|
|
|
|
) &&
|
2021-04-28 05:17:21 +08:00
|
|
|
test_create_commit "$test_count/sub proj" sub3 &&
|
|
|
|
test_create_commit "$test_count" "sub dir"/main-sub3 &&
|
2015-11-13 10:32:35 +08:00
|
|
|
(
|
2021-04-28 05:17:21 +08:00
|
|
|
cd "$test_count/sub proj" &&
|
2015-11-13 10:32:35 +08:00
|
|
|
git fetch .. subproj-br &&
|
|
|
|
git merge FETCH_HEAD
|
|
|
|
) &&
|
2021-04-28 05:17:21 +08:00
|
|
|
test_create_commit "$test_count/sub proj" sub4 &&
|
2015-11-13 10:32:35 +08:00
|
|
|
(
|
2021-04-28 05:17:21 +08:00
|
|
|
cd "$test_count" &&
|
2015-11-13 10:32:35 +08:00
|
|
|
git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
|
|
|
|
) &&
|
2021-04-28 05:17:21 +08:00
|
|
|
test_create_commit "$test_count" "sub dir"/main-sub4 &&
|
2015-11-13 10:32:35 +08:00
|
|
|
(
|
2021-04-28 05:17:21 +08:00
|
|
|
cd "$test_count" &&
|
2015-11-13 10:32:35 +08:00
|
|
|
git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
|
|
|
|
) &&
|
|
|
|
(
|
2021-04-28 05:17:21 +08:00
|
|
|
cd "$test_count/sub proj" &&
|
2015-11-13 10:32:35 +08:00
|
|
|
git fetch .. subproj-br &&
|
|
|
|
git merge FETCH_HEAD
|
|
|
|
) &&
|
|
|
|
(
|
2021-04-28 05:17:21 +08:00
|
|
|
cd "$test_count" &&
|
2021-04-28 05:17:20 +08:00
|
|
|
git subtree pull --prefix="sub dir" ./"sub proj" HEAD &&
|
2015-11-13 10:32:35 +08:00
|
|
|
|
2018-07-31 03:07:38 +08:00
|
|
|
test_write_lines main1 main2 >chkm &&
|
|
|
|
test_write_lines sub1 sub2 sub3 sub4 >chks &&
|
|
|
|
test_write_lines main-sub1 main-sub2 main-sub3 main-sub4 >chkms &&
|
|
|
|
sed "s,^,sub dir/," chkms >chkms_sub &&
|
2015-11-13 10:32:35 +08:00
|
|
|
|
|
|
|
# main-sub?? and /"sub dir"/main-sub?? both change, because those are the
|
|
|
|
# changes that were split into their own history. And "sub dir"/sub?? never
|
|
|
|
# change, since they were *only* changed in the subtree branch.
|
2018-07-31 03:07:38 +08:00
|
|
|
git log --name-only --pretty=format:"" >log &&
|
|
|
|
sort <log >sorted-log &&
|
|
|
|
sed "/^$/ d" sorted-log >actual &&
|
|
|
|
|
|
|
|
cat chkms chkm chks chkms_sub >expect-unsorted &&
|
|
|
|
sort expect-unsorted >expect &&
|
|
|
|
test_cmp expect actual
|
2015-11-13 10:32:35 +08:00
|
|
|
)
|
2012-01-30 06:09:58 +08:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'make sure the --rejoin commits never make it into subproj' '
|
2021-04-28 05:17:21 +08:00
|
|
|
subtree_test_create_repo "$test_count" &&
|
|
|
|
subtree_test_create_repo "$test_count/sub proj" &&
|
|
|
|
test_create_commit "$test_count" main1 &&
|
|
|
|
test_create_commit "$test_count/sub proj" sub1 &&
|
2015-11-13 10:32:35 +08:00
|
|
|
(
|
2021-04-28 05:17:21 +08:00
|
|
|
cd "$test_count" &&
|
2021-04-28 05:17:20 +08:00
|
|
|
git fetch ./"sub proj" HEAD &&
|
2015-11-13 10:32:35 +08:00
|
|
|
git subtree add --prefix="sub dir" FETCH_HEAD
|
|
|
|
) &&
|
2021-04-28 05:17:21 +08:00
|
|
|
test_create_commit "$test_count" "sub dir"/main-sub1 &&
|
|
|
|
test_create_commit "$test_count" main2 &&
|
|
|
|
test_create_commit "$test_count/sub proj" sub2 &&
|
|
|
|
test_create_commit "$test_count" "sub dir"/main-sub2 &&
|
2015-11-13 10:32:35 +08:00
|
|
|
(
|
2021-04-28 05:17:21 +08:00
|
|
|
cd "$test_count" &&
|
2021-04-28 05:17:20 +08:00
|
|
|
git fetch ./"sub proj" HEAD &&
|
2015-11-13 10:32:35 +08:00
|
|
|
git subtree merge --prefix="sub dir" FETCH_HEAD &&
|
|
|
|
git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
|
|
|
|
) &&
|
2021-04-28 05:17:21 +08:00
|
|
|
test_create_commit "$test_count/sub proj" sub3 &&
|
|
|
|
test_create_commit "$test_count" "sub dir"/main-sub3 &&
|
2015-11-13 10:32:35 +08:00
|
|
|
(
|
2021-04-28 05:17:21 +08:00
|
|
|
cd "$test_count/sub proj" &&
|
2015-11-13 10:32:35 +08:00
|
|
|
git fetch .. subproj-br &&
|
|
|
|
git merge FETCH_HEAD
|
|
|
|
) &&
|
2021-04-28 05:17:21 +08:00
|
|
|
test_create_commit "$test_count/sub proj" sub4 &&
|
2015-11-13 10:32:35 +08:00
|
|
|
(
|
2021-04-28 05:17:21 +08:00
|
|
|
cd "$test_count" &&
|
2015-11-13 10:32:35 +08:00
|
|
|
git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
|
|
|
|
) &&
|
2021-04-28 05:17:21 +08:00
|
|
|
test_create_commit "$test_count" "sub dir"/main-sub4 &&
|
2015-11-13 10:32:35 +08:00
|
|
|
(
|
2021-04-28 05:17:21 +08:00
|
|
|
cd "$test_count" &&
|
2015-11-13 10:32:35 +08:00
|
|
|
git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
|
|
|
|
) &&
|
|
|
|
(
|
2021-04-28 05:17:21 +08:00
|
|
|
cd "$test_count/sub proj" &&
|
2015-11-13 10:32:35 +08:00
|
|
|
git fetch .. subproj-br &&
|
|
|
|
git merge FETCH_HEAD
|
|
|
|
) &&
|
|
|
|
(
|
2021-04-28 05:17:21 +08:00
|
|
|
cd "$test_count" &&
|
2021-04-28 05:17:20 +08:00
|
|
|
git subtree pull --prefix="sub dir" ./"sub proj" HEAD &&
|
2021-04-28 05:17:24 +08:00
|
|
|
test "$(git log --pretty=format:"%s" HEAD^2 | grep -i split)" = ""
|
2015-11-13 10:32:35 +08:00
|
|
|
)
|
2012-01-30 06:09:58 +08:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'make sure no "git subtree" tagged commits make it into subproj' '
|
2021-04-28 05:17:21 +08:00
|
|
|
subtree_test_create_repo "$test_count" &&
|
|
|
|
subtree_test_create_repo "$test_count/sub proj" &&
|
|
|
|
test_create_commit "$test_count" main1 &&
|
|
|
|
test_create_commit "$test_count/sub proj" sub1 &&
|
2015-11-13 10:32:35 +08:00
|
|
|
(
|
2021-04-28 05:17:21 +08:00
|
|
|
cd "$test_count" &&
|
2021-04-28 05:17:20 +08:00
|
|
|
git fetch ./"sub proj" HEAD &&
|
2015-11-13 10:32:35 +08:00
|
|
|
git subtree add --prefix="sub dir" FETCH_HEAD
|
|
|
|
) &&
|
2021-04-28 05:17:21 +08:00
|
|
|
test_create_commit "$test_count" "sub dir"/main-sub1 &&
|
|
|
|
test_create_commit "$test_count" main2 &&
|
|
|
|
test_create_commit "$test_count/sub proj" sub2 &&
|
|
|
|
test_create_commit "$test_count" "sub dir"/main-sub2 &&
|
2015-11-13 10:32:35 +08:00
|
|
|
(
|
2021-04-28 05:17:21 +08:00
|
|
|
cd "$test_count" &&
|
2021-04-28 05:17:20 +08:00
|
|
|
git fetch ./"sub proj" HEAD &&
|
2015-11-13 10:32:35 +08:00
|
|
|
git subtree merge --prefix="sub dir" FETCH_HEAD &&
|
|
|
|
git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
|
|
|
|
) &&
|
2021-04-28 05:17:21 +08:00
|
|
|
test_create_commit "$test_count/sub proj" sub3 &&
|
|
|
|
test_create_commit "$test_count" "sub dir"/main-sub3 &&
|
2015-11-13 10:32:35 +08:00
|
|
|
(
|
2021-04-28 05:17:21 +08:00
|
|
|
cd "$test_count/sub proj" &&
|
2015-11-13 10:32:35 +08:00
|
|
|
git fetch .. subproj-br &&
|
|
|
|
git merge FETCH_HEAD
|
|
|
|
) &&
|
2021-04-28 05:17:21 +08:00
|
|
|
test_create_commit "$test_count/sub proj" sub4 &&
|
2015-11-13 10:32:35 +08:00
|
|
|
(
|
2021-04-28 05:17:21 +08:00
|
|
|
cd "$test_count" &&
|
2015-11-13 10:32:35 +08:00
|
|
|
git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
|
|
|
|
) &&
|
2021-04-28 05:17:21 +08:00
|
|
|
test_create_commit "$test_count" "sub dir"/main-sub4 &&
|
2015-11-13 10:32:35 +08:00
|
|
|
(
|
2021-04-28 05:17:21 +08:00
|
|
|
cd "$test_count" &&
|
2015-11-13 10:32:35 +08:00
|
|
|
git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
|
|
|
|
) &&
|
|
|
|
(
|
2021-04-28 05:17:21 +08:00
|
|
|
cd "$test_count/sub proj" &&
|
2015-11-13 10:32:35 +08:00
|
|
|
git fetch .. subproj-br &&
|
|
|
|
git merge FETCH_HEAD
|
|
|
|
) &&
|
|
|
|
(
|
2021-04-28 05:17:21 +08:00
|
|
|
cd "$test_count" &&
|
2021-04-28 05:17:20 +08:00
|
|
|
git subtree pull --prefix="sub dir" ./"sub proj" HEAD &&
|
2015-11-13 10:32:35 +08:00
|
|
|
|
|
|
|
# They are meaningless to subproj since one side of the merge refers to the mainline
|
2021-04-28 05:17:24 +08:00
|
|
|
test "$(git log --pretty=format:"%s%n%b" HEAD^2 | grep "git-subtree.*:")" = ""
|
2015-11-13 10:32:35 +08:00
|
|
|
)
|
2012-01-30 06:09:58 +08:00
|
|
|
'
|
|
|
|
|
2015-11-13 10:32:35 +08:00
|
|
|
#
|
|
|
|
# A new set of tests
|
|
|
|
#
|
2012-01-30 06:09:58 +08:00
|
|
|
|
2015-11-13 10:32:35 +08:00
|
|
|
test_expect_success 'make sure "git subtree split" find the correct parent' '
|
2021-04-28 05:17:21 +08:00
|
|
|
subtree_test_create_repo "$test_count" &&
|
|
|
|
subtree_test_create_repo "$test_count/sub proj" &&
|
|
|
|
test_create_commit "$test_count" main1 &&
|
|
|
|
test_create_commit "$test_count/sub proj" sub1 &&
|
2015-11-13 10:32:35 +08:00
|
|
|
(
|
2021-04-28 05:17:21 +08:00
|
|
|
cd "$test_count" &&
|
2021-04-28 05:17:20 +08:00
|
|
|
git fetch ./"sub proj" HEAD &&
|
2015-11-13 10:32:35 +08:00
|
|
|
git subtree add --prefix="sub dir" FETCH_HEAD
|
|
|
|
) &&
|
2021-04-28 05:17:21 +08:00
|
|
|
test_create_commit "$test_count/sub proj" sub2 &&
|
2015-11-13 10:32:35 +08:00
|
|
|
(
|
2021-04-28 05:17:21 +08:00
|
|
|
cd "$test_count" &&
|
2021-04-28 05:17:20 +08:00
|
|
|
git fetch ./"sub proj" HEAD &&
|
2015-11-13 10:32:35 +08:00
|
|
|
git branch subproj-ref FETCH_HEAD &&
|
|
|
|
git subtree merge --prefix="sub dir" FETCH_HEAD
|
|
|
|
) &&
|
2021-04-28 05:17:21 +08:00
|
|
|
test_create_commit "$test_count" "sub dir"/main-sub1 &&
|
2015-11-13 10:32:35 +08:00
|
|
|
(
|
2021-04-28 05:17:21 +08:00
|
|
|
cd "$test_count" &&
|
2015-11-13 10:32:35 +08:00
|
|
|
git subtree split --prefix="sub dir" --branch subproj-br &&
|
|
|
|
|
|
|
|
# at this point, the new commit parent should be subproj-ref, if it is
|
2021-04-28 05:17:20 +08:00
|
|
|
# not, something went wrong (the "newparent" of "HEAD~" commit should
|
2015-11-13 10:32:35 +08:00
|
|
|
# have been sub2, but it was not, because its cache was not set to
|
|
|
|
# itself)
|
2021-04-28 05:17:24 +08:00
|
|
|
test "$(git log --pretty=format:%P -1 subproj-br)" = "$(git rev-parse subproj-ref)"
|
2015-11-13 10:32:35 +08:00
|
|
|
)
|
2012-01-30 06:09:58 +08:00
|
|
|
'
|
|
|
|
|
2015-11-13 10:32:35 +08:00
|
|
|
test_expect_success 'split a new subtree without --onto option' '
|
2021-04-28 05:17:21 +08:00
|
|
|
subtree_test_create_repo "$test_count" &&
|
|
|
|
subtree_test_create_repo "$test_count/sub proj" &&
|
|
|
|
test_create_commit "$test_count" main1 &&
|
|
|
|
test_create_commit "$test_count/sub proj" sub1 &&
|
2015-11-13 10:32:35 +08:00
|
|
|
(
|
2021-04-28 05:17:21 +08:00
|
|
|
cd "$test_count" &&
|
2021-04-28 05:17:20 +08:00
|
|
|
git fetch ./"sub proj" HEAD &&
|
2015-11-13 10:32:35 +08:00
|
|
|
git subtree add --prefix="sub dir" FETCH_HEAD
|
|
|
|
) &&
|
2021-04-28 05:17:21 +08:00
|
|
|
test_create_commit "$test_count/sub proj" sub2 &&
|
2015-11-13 10:32:35 +08:00
|
|
|
(
|
2021-04-28 05:17:21 +08:00
|
|
|
cd "$test_count" &&
|
2021-04-28 05:17:20 +08:00
|
|
|
git fetch ./"sub proj" HEAD &&
|
2015-11-13 10:32:35 +08:00
|
|
|
git subtree merge --prefix="sub dir" FETCH_HEAD
|
|
|
|
) &&
|
2021-04-28 05:17:21 +08:00
|
|
|
test_create_commit "$test_count" "sub dir"/main-sub1 &&
|
2015-11-13 10:32:35 +08:00
|
|
|
(
|
2021-04-28 05:17:21 +08:00
|
|
|
cd "$test_count" &&
|
2015-11-13 10:32:35 +08:00
|
|
|
git subtree split --prefix="sub dir" --branch subproj-br
|
|
|
|
) &&
|
2021-04-28 05:17:21 +08:00
|
|
|
mkdir "$test_count"/"sub dir2" &&
|
|
|
|
test_create_commit "$test_count" "sub dir2"/main-sub2 &&
|
2015-11-13 10:32:35 +08:00
|
|
|
(
|
2021-04-28 05:17:21 +08:00
|
|
|
cd "$test_count" &&
|
2015-11-13 10:32:35 +08:00
|
|
|
|
|
|
|
# also test that we still can split out an entirely new subtree
|
|
|
|
# if the parent of the first commit in the tree is not empty,
|
2016-08-09 16:53:38 +08:00
|
|
|
# then the new subtree has accidentally been attached to something
|
2015-11-13 10:32:35 +08:00
|
|
|
git subtree split --prefix="sub dir2" --branch subproj2-br &&
|
2021-04-28 05:17:24 +08:00
|
|
|
test "$(git log --pretty=format:%P -1 subproj2-br)" = ""
|
2015-11-13 10:32:35 +08:00
|
|
|
)
|
2012-01-30 06:09:58 +08:00
|
|
|
'
|
2010-01-13 06:04:25 +08:00
|
|
|
|
2012-01-30 06:09:58 +08:00
|
|
|
test_expect_success 'verify one file change per commit' '
|
2021-04-28 05:17:21 +08:00
|
|
|
subtree_test_create_repo "$test_count" &&
|
|
|
|
subtree_test_create_repo "$test_count/sub proj" &&
|
|
|
|
test_create_commit "$test_count" main1 &&
|
|
|
|
test_create_commit "$test_count/sub proj" sub1 &&
|
2015-11-13 10:32:35 +08:00
|
|
|
(
|
2021-04-28 05:17:21 +08:00
|
|
|
cd "$test_count" &&
|
2021-04-28 05:17:20 +08:00
|
|
|
git fetch ./"sub proj" HEAD &&
|
2015-11-13 10:32:35 +08:00
|
|
|
git branch sub1 FETCH_HEAD &&
|
|
|
|
git subtree add --prefix="sub dir" sub1
|
|
|
|
) &&
|
2021-04-28 05:17:21 +08:00
|
|
|
test_create_commit "$test_count/sub proj" sub2 &&
|
2015-11-13 10:32:35 +08:00
|
|
|
(
|
2021-04-28 05:17:21 +08:00
|
|
|
cd "$test_count" &&
|
2021-04-28 05:17:20 +08:00
|
|
|
git fetch ./"sub proj" HEAD &&
|
2015-11-13 10:32:35 +08:00
|
|
|
git subtree merge --prefix="sub dir" FETCH_HEAD
|
|
|
|
) &&
|
2021-04-28 05:17:21 +08:00
|
|
|
test_create_commit "$test_count" "sub dir"/main-sub1 &&
|
2015-11-13 10:32:35 +08:00
|
|
|
(
|
2021-04-28 05:17:21 +08:00
|
|
|
cd "$test_count" &&
|
2015-11-13 10:32:35 +08:00
|
|
|
git subtree split --prefix="sub dir" --branch subproj-br
|
|
|
|
) &&
|
2021-04-28 05:17:21 +08:00
|
|
|
mkdir "$test_count"/"sub dir2" &&
|
|
|
|
test_create_commit "$test_count" "sub dir2"/main-sub2 &&
|
2015-11-13 10:32:35 +08:00
|
|
|
(
|
2021-04-28 05:17:21 +08:00
|
|
|
cd "$test_count" &&
|
2015-11-13 10:32:35 +08:00
|
|
|
git subtree split --prefix="sub dir2" --branch subproj2-br &&
|
|
|
|
|
2021-04-28 05:17:26 +08:00
|
|
|
git log --format="%H" >commit-list &&
|
|
|
|
while read commit
|
|
|
|
do
|
|
|
|
git log -n1 --format="" --name-only "$commit" >file-list &&
|
|
|
|
test_line_count -le 1 file-list || return 1
|
|
|
|
done <commit-list
|
2015-11-13 10:32:30 +08:00
|
|
|
)
|
2012-01-30 06:09:58 +08:00
|
|
|
'
|
|
|
|
|
2015-11-13 10:32:35 +08:00
|
|
|
test_expect_success 'push split to subproj' '
|
2021-04-28 05:17:21 +08:00
|
|
|
subtree_test_create_repo "$test_count" &&
|
|
|
|
subtree_test_create_repo "$test_count/sub proj" &&
|
|
|
|
test_create_commit "$test_count" main1 &&
|
|
|
|
test_create_commit "$test_count/sub proj" sub1 &&
|
2015-11-13 10:32:35 +08:00
|
|
|
(
|
2021-04-28 05:17:21 +08:00
|
|
|
cd "$test_count" &&
|
2021-04-28 05:17:20 +08:00
|
|
|
git fetch ./"sub proj" HEAD &&
|
2015-11-13 10:32:35 +08:00
|
|
|
git subtree add --prefix="sub dir" FETCH_HEAD
|
|
|
|
) &&
|
2021-04-28 05:17:21 +08:00
|
|
|
test_create_commit "$test_count" "sub dir"/main-sub1 &&
|
|
|
|
test_create_commit "$test_count" main2 &&
|
|
|
|
test_create_commit "$test_count/sub proj" sub2 &&
|
|
|
|
test_create_commit "$test_count" "sub dir"/main-sub2 &&
|
2015-11-13 10:32:35 +08:00
|
|
|
(
|
2021-04-28 05:17:21 +08:00
|
|
|
cd $test_count/"sub proj" &&
|
2021-04-28 05:17:22 +08:00
|
|
|
git branch sub-branch-1 &&
|
|
|
|
cd .. &&
|
2021-04-28 05:17:20 +08:00
|
|
|
git fetch ./"sub proj" HEAD &&
|
2015-11-13 10:32:35 +08:00
|
|
|
git subtree merge --prefix="sub dir" FETCH_HEAD
|
|
|
|
) &&
|
2021-04-28 05:17:21 +08:00
|
|
|
test_create_commit "$test_count" "sub dir"/main-sub3 &&
|
2021-04-28 05:17:22 +08:00
|
|
|
(
|
2021-04-28 05:17:21 +08:00
|
|
|
cd "$test_count" &&
|
2021-04-28 05:17:22 +08:00
|
|
|
git subtree push ./"sub proj" --prefix "sub dir" sub-branch-1 &&
|
|
|
|
cd ./"sub proj" &&
|
|
|
|
git checkout sub-branch-1 &&
|
2021-04-28 05:17:27 +08:00
|
|
|
test "$(last_commit_subject)" = "sub dir/main-sub3"
|
2015-11-13 10:32:35 +08:00
|
|
|
)
|
2015-09-05 06:24:11 +08:00
|
|
|
'
|
|
|
|
|
2016-01-15 08:41:43 +08:00
|
|
|
#
|
|
|
|
# This test covers 2 cases in subtree split copy_or_skip code
|
|
|
|
# 1) Merges where one parent is a superset of the changes of the other
|
|
|
|
# parent regarding changes to the subtree, in this case the merge
|
|
|
|
# commit should be copied
|
|
|
|
# 2) Merges where only one parent operate on the subtree, and the merge
|
|
|
|
# commit should be skipped
|
|
|
|
#
|
|
|
|
# (1) is checked by ensuring subtree_tip is a descendent of subtree_branch
|
|
|
|
# (2) should have a check added (not_a_subtree_change shouldn't be present
|
|
|
|
# on the produced subtree)
|
|
|
|
#
|
|
|
|
# Other related cases which are not tested (or currently handled correctly)
|
|
|
|
# - Case (1) where there are more than 2 parents, it will sometimes correctly copy
|
|
|
|
# the merge, and sometimes not
|
|
|
|
# - Merge commit where both parents have same tree as the merge, currently
|
|
|
|
# will always be skipped, even if they reached that state via different
|
|
|
|
# set of commits.
|
|
|
|
#
|
|
|
|
|
|
|
|
test_expect_success 'subtree descendant check' '
|
2021-04-28 05:17:21 +08:00
|
|
|
subtree_test_create_repo "$test_count" &&
|
|
|
|
defaultBranch=$(sed "s,ref: refs/heads/,," "$test_count/.git/HEAD") &&
|
|
|
|
test_create_commit "$test_count" folder_subtree/a &&
|
2016-01-15 08:41:43 +08:00
|
|
|
(
|
2021-04-28 05:17:21 +08:00
|
|
|
cd "$test_count" &&
|
2016-01-15 08:41:43 +08:00
|
|
|
git branch branch
|
|
|
|
) &&
|
2021-04-28 05:17:21 +08:00
|
|
|
test_create_commit "$test_count" folder_subtree/0 &&
|
|
|
|
test_create_commit "$test_count" folder_subtree/b &&
|
|
|
|
cherry=$(cd "$test_count"; git rev-parse HEAD) &&
|
2016-01-15 08:41:43 +08:00
|
|
|
(
|
2021-04-28 05:17:21 +08:00
|
|
|
cd "$test_count" &&
|
2016-01-15 08:41:43 +08:00
|
|
|
git checkout branch
|
|
|
|
) &&
|
2021-04-28 05:17:21 +08:00
|
|
|
test_create_commit "$test_count" commit_on_branch &&
|
2016-01-15 08:41:43 +08:00
|
|
|
(
|
2021-04-28 05:17:21 +08:00
|
|
|
cd "$test_count" &&
|
2016-01-15 08:41:43 +08:00
|
|
|
git cherry-pick $cherry &&
|
2021-04-28 05:17:20 +08:00
|
|
|
git checkout $defaultBranch &&
|
2016-01-15 08:41:43 +08:00
|
|
|
git merge -m "merge should be kept on subtree" branch &&
|
|
|
|
git branch no_subtree_work_branch
|
|
|
|
) &&
|
2021-04-28 05:17:21 +08:00
|
|
|
test_create_commit "$test_count" folder_subtree/d &&
|
2016-01-15 08:41:43 +08:00
|
|
|
(
|
2021-04-28 05:17:21 +08:00
|
|
|
cd "$test_count" &&
|
2016-01-15 08:41:43 +08:00
|
|
|
git checkout no_subtree_work_branch
|
|
|
|
) &&
|
2021-04-28 05:17:21 +08:00
|
|
|
test_create_commit "$test_count" not_a_subtree_change &&
|
2016-01-15 08:41:43 +08:00
|
|
|
(
|
2021-04-28 05:17:21 +08:00
|
|
|
cd "$test_count" &&
|
2021-04-28 05:17:20 +08:00
|
|
|
git checkout $defaultBranch &&
|
2016-01-15 08:41:43 +08:00
|
|
|
git merge -m "merge should be skipped on subtree" no_subtree_work_branch &&
|
|
|
|
|
2021-04-28 05:17:20 +08:00
|
|
|
git subtree split --prefix folder_subtree/ --branch subtree_tip $defaultBranch &&
|
2016-01-15 08:41:43 +08:00
|
|
|
git subtree split --prefix folder_subtree/ --branch subtree_branch branch &&
|
2021-04-28 05:17:24 +08:00
|
|
|
test $(git rev-list --count subtree_tip..subtree_branch) = 0
|
2016-01-15 08:41:43 +08:00
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2012-01-30 06:09:58 +08:00
|
|
|
test_done
|