3 test_description='git rebase tests for -Xsubtree
5 This test runs git rebase and tests the subtree strategy.
8 . "$TEST_DIRECTORY"/lib-rebase.sh
11 git log --pretty=format:%s -1 "$1"
14 # There are a few bugs in the rebase with regards to the subtree strategy, and
15 # this test script tries to document them. First, the following commit history
16 # is generated (the onelines are shown, time flows from left to right):
18 # topic_1 - topic_2 - topic_3
20 # README ---------------------- Add subproject master - topic_4 - files_subtree/topic_5
22 # Where the merge moves the files master[123].t into the subdirectory
23 # files_subtree/ and topic_4 as well as files_subtree/topic_5 add files to that
26 # Then, in subsequent test cases, `git filter-branch` is used to distill just
27 # the commits that touch files_subtree/. To give it a final pre-rebase touch,
28 # an empty commit is added on top. The pre-rebase commit history looks like
31 # Add subproject master - topic_4 - files_subtree/topic_5 - Empty commit
33 # where the root commit adds three files: topic_1.t, topic_2.t and topic_3.t.
35 # This commit history is then rebased onto `topic_3` with the
36 # `-Xsubtree=files_subtree` option in three different ways:
38 # 1. using `--preserve-merges`
39 # 2. using `--preserve-merges` and --keep-empty
40 # 3. without specifying a rebase backend
42 test_expect_success 'setup' '
46 test_commit -C files topic_1 &&
47 test_commit -C files topic_2 &&
48 test_commit -C files topic_3 &&
50 : perform subtree merge into files_subtree/ &&
51 git fetch files refs/heads/master:refs/heads/files-master &&
52 git merge -s ours --no-commit --allow-unrelated-histories \
54 git read-tree --prefix=files_subtree -u files-master &&
55 git commit -m "Add subproject master" &&
57 : add two extra commits to rebase &&
58 test_commit -C files_subtree topic_4 &&
59 test_commit files_subtree/topic_5 &&
61 git checkout -b to-rebase &&
62 git fast-export --no-data HEAD -- files_subtree/ |
63 sed -e "s%\([0-9a-f]\{40\} \)files_subtree/%\1%" |
64 git fast-import --force --quiet &&
66 git commit -m "Empty commit" --allow-empty
69 # FAILURE: Does not preserve topic_4.
70 test_expect_failure REBASE_P 'Rebase -Xsubtree --preserve-merges --onto commit' '
72 git checkout -b rebase-preserve-merges to-rebase &&
73 git rebase -Xsubtree=files_subtree --preserve-merges --onto files-master master &&
74 verbose test "$(commit_message HEAD~)" = "topic_4" &&
75 verbose test "$(commit_message HEAD)" = "files_subtree/topic_5"
78 # FAILURE: Does not preserve topic_4.
79 test_expect_failure REBASE_P 'Rebase -Xsubtree --keep-empty --preserve-merges --onto commit' '
81 git checkout -b rebase-keep-empty to-rebase &&
82 git rebase -Xsubtree=files_subtree --keep-empty --preserve-merges --onto files-master master &&
83 verbose test "$(commit_message HEAD~2)" = "topic_4" &&
84 verbose test "$(commit_message HEAD~)" = "files_subtree/topic_5" &&
85 verbose test "$(commit_message HEAD)" = "Empty commit"
88 test_expect_success 'Rebase -Xsubtree --empty=ask --onto commit' '
90 git checkout -b rebase-onto to-rebase &&
91 test_must_fail git rebase -Xsubtree=files_subtree --empty=ask --onto files-master master &&
92 : first pick results in no changes &&
94 verbose test "$(commit_message HEAD~2)" = "topic_4" &&
95 verbose test "$(commit_message HEAD~)" = "files_subtree/topic_5" &&
96 verbose test "$(commit_message HEAD)" = "Empty commit"
99 test_expect_success 'Rebase -Xsubtree --empty=ask --rebase-merges --onto commit' '
101 git checkout -b rebase-merges-onto to-rebase &&
102 test_must_fail git rebase -Xsubtree=files_subtree --empty=ask --rebase-merges --onto files-master --root &&
103 : first pick results in no changes &&
105 verbose test "$(commit_message HEAD~2)" = "topic_4" &&
106 verbose test "$(commit_message HEAD~)" = "files_subtree/topic_5" &&
107 verbose test "$(commit_message HEAD)" = "Empty commit"