Start the 2.46 cycle
[git.git] / t / t3427-rebase-subtree.sh
blob1b3e97c8755f3d8b41549e70cf67529298118182
1 #!/bin/sh
3 test_description='git rebase tests for -Xsubtree
5 This test runs git rebase and tests the subtree strategy.
7 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
8 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
10 . ./test-lib.sh
11 . "$TEST_DIRECTORY"/lib-rebase.sh
13 commit_message() {
14 git log --pretty=format:%s -1 "$1"
17 # There are a few bugs in the rebase with regards to the subtree strategy, and
18 # this test script tries to document them. First, the following commit history
19 # is generated (the onelines are shown, time flows from left to right):
21 # topic_1 - topic_2 - topic_3
22 # \
23 # README ---------------------- Add subproject main - topic_4 - files_subtree/topic_5
25 # Where the merge moves the files topic_[123].t into the subdirectory
26 # files_subtree/ and topic_4 as well as files_subtree/topic_5 add files to that
27 # directory directly.
29 # Then, in subsequent test cases, `git filter-branch` is used to distill just
30 # the commits that touch files_subtree/. To give it a final pre-rebase touch,
31 # an empty commit is added on top. The pre-rebase commit history looks like
32 # this:
34 # Add subproject main - topic_4 - files_subtree/topic_5 - Empty commit
36 # where the root commit adds three files: topic_1.t, topic_2.t and topic_3.t.
38 # This commit history is then rebased onto `topic_3` with the
39 # `-Xsubtree=files_subtree` option in two different ways:
41 # 1. without specifying a rebase backend
42 # 2. using the `--rebase-merges` backend
44 test_expect_success 'setup' '
45 test_commit README &&
47 git init files &&
48 test_commit -C files topic_1 &&
49 test_commit -C files topic_2 &&
50 test_commit -C files topic_3 &&
52 : perform subtree merge into files_subtree/ &&
53 git fetch files refs/heads/main:refs/heads/files-main &&
54 git merge -s ours --no-commit --allow-unrelated-histories \
55 files-main &&
56 git read-tree --prefix=files_subtree -u files-main &&
57 git commit -m "Add subproject main" &&
59 : add two extra commits to rebase &&
60 test_commit -C files_subtree topic_4 &&
61 test_commit files_subtree/topic_5 &&
63 git checkout -b to-rebase &&
64 git fast-export --no-data HEAD -- files_subtree/ |
65 sed -e "s%\([0-9a-f]\{40\} \)files_subtree/%\1%" |
66 git fast-import --force --quiet &&
67 git reset --hard &&
68 git commit -m "Empty commit" --allow-empty
71 test_expect_success 'Rebase -Xsubtree --empty=ask --onto commit' '
72 reset_rebase &&
73 git checkout -b rebase-onto to-rebase &&
74 test_must_fail git rebase -Xsubtree=files_subtree --empty=ask --onto files-main main &&
75 : first pick results in no changes &&
76 git rebase --skip &&
77 test "$(commit_message HEAD~2)" = "topic_4" &&
78 test "$(commit_message HEAD~)" = "files_subtree/topic_5" &&
79 test "$(commit_message HEAD)" = "Empty commit"
82 test_expect_success 'Rebase -Xsubtree --empty=ask --rebase-merges --onto commit' '
83 reset_rebase &&
84 git checkout -b rebase-merges-onto to-rebase &&
85 test_must_fail git rebase -Xsubtree=files_subtree --empty=ask --rebase-merges --onto files-main --root &&
86 : first pick results in no changes &&
87 git rebase --skip &&
88 test "$(commit_message HEAD~2)" = "topic_4" &&
89 test "$(commit_message HEAD~)" = "files_subtree/topic_5" &&
90 test "$(commit_message HEAD)" = "Empty commit"
93 test_done