David A. Greene | 5f35900 | 2016-06-28 05:54:02 -0500 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='git rebase tests for -Xsubtree |
| 4 | |
| 5 | This test runs git rebase and tests the subtree strategy. |
| 6 | ' |
Johannes Schindelin | d1c02d9 | 2020-11-18 23:44:25 +0000 | [diff] [blame] | 7 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
Johannes Schindelin | 334afbc | 2020-11-18 23:44:19 +0000 | [diff] [blame] | 8 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
| 9 | |
David A. Greene | 5f35900 | 2016-06-28 05:54:02 -0500 | [diff] [blame] | 10 | . ./test-lib.sh |
| 11 | . "$TEST_DIRECTORY"/lib-rebase.sh |
| 12 | |
| 13 | commit_message() { |
| 14 | git log --pretty=format:%s -1 "$1" |
| 15 | } |
| 16 | |
Johannes Schindelin | 8c1e240 | 2019-07-31 08:18:42 -0700 | [diff] [blame] | 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): |
| 20 | # |
Johannes Schindelin | b6211b8 | 2020-09-26 21:04:21 +0000 | [diff] [blame] | 21 | # topic_1 - topic_2 - topic_3 |
Johannes Schindelin | 8c1e240 | 2019-07-31 08:18:42 -0700 | [diff] [blame] | 22 | # \ |
Johannes Schindelin | d1c02d9 | 2020-11-18 23:44:25 +0000 | [diff] [blame] | 23 | # README ---------------------- Add subproject main - topic_4 - files_subtree/topic_5 |
Johannes Schindelin | 8c1e240 | 2019-07-31 08:18:42 -0700 | [diff] [blame] | 24 | # |
Johannes Schindelin | adbcf53 | 2020-11-09 00:09:22 +0000 | [diff] [blame] | 25 | # Where the merge moves the files topic_[123].t into the subdirectory |
Johannes Schindelin | b6211b8 | 2020-09-26 21:04:21 +0000 | [diff] [blame] | 26 | # files_subtree/ and topic_4 as well as files_subtree/topic_5 add files to that |
Johannes Schindelin | 8c1e240 | 2019-07-31 08:18:42 -0700 | [diff] [blame] | 27 | # directory directly. |
| 28 | # |
| 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: |
| 33 | # |
Johannes Schindelin | d1c02d9 | 2020-11-18 23:44:25 +0000 | [diff] [blame] | 34 | # Add subproject main - topic_4 - files_subtree/topic_5 - Empty commit |
Johannes Schindelin | 8c1e240 | 2019-07-31 08:18:42 -0700 | [diff] [blame] | 35 | # |
Johannes Schindelin | b6211b8 | 2020-09-26 21:04:21 +0000 | [diff] [blame] | 36 | # where the root commit adds three files: topic_1.t, topic_2.t and topic_3.t. |
Johannes Schindelin | 8c1e240 | 2019-07-31 08:18:42 -0700 | [diff] [blame] | 37 | # |
Johannes Schindelin | b6211b8 | 2020-09-26 21:04:21 +0000 | [diff] [blame] | 38 | # This commit history is then rebased onto `topic_3` with the |
Johannes Schindelin | 8c1e240 | 2019-07-31 08:18:42 -0700 | [diff] [blame] | 39 | # `-Xsubtree=files_subtree` option in three different ways: |
| 40 | # |
| 41 | # 1. using `--preserve-merges` |
| 42 | # 2. using `--preserve-merges` and --keep-empty |
| 43 | # 3. without specifying a rebase backend |
| 44 | |
David A. Greene | 5f35900 | 2016-06-28 05:54:02 -0500 | [diff] [blame] | 45 | test_expect_success 'setup' ' |
| 46 | test_commit README && |
Johannes Schindelin | c248d32 | 2019-07-31 08:18:42 -0700 | [diff] [blame] | 47 | |
| 48 | git init files && |
Johannes Schindelin | b6211b8 | 2020-09-26 21:04:21 +0000 | [diff] [blame] | 49 | test_commit -C files topic_1 && |
| 50 | test_commit -C files topic_2 && |
| 51 | test_commit -C files topic_3 && |
Johannes Schindelin | c248d32 | 2019-07-31 08:18:42 -0700 | [diff] [blame] | 52 | |
| 53 | : perform subtree merge into files_subtree/ && |
Johannes Schindelin | d1c02d9 | 2020-11-18 23:44:25 +0000 | [diff] [blame] | 54 | git fetch files refs/heads/main:refs/heads/files-main && |
Johannes Schindelin | c248d32 | 2019-07-31 08:18:42 -0700 | [diff] [blame] | 55 | git merge -s ours --no-commit --allow-unrelated-histories \ |
Johannes Schindelin | d1c02d9 | 2020-11-18 23:44:25 +0000 | [diff] [blame] | 56 | files-main && |
| 57 | git read-tree --prefix=files_subtree -u files-main && |
| 58 | git commit -m "Add subproject main" && |
Johannes Schindelin | c248d32 | 2019-07-31 08:18:42 -0700 | [diff] [blame] | 59 | |
| 60 | : add two extra commits to rebase && |
Johannes Schindelin | b6211b8 | 2020-09-26 21:04:21 +0000 | [diff] [blame] | 61 | test_commit -C files_subtree topic_4 && |
| 62 | test_commit files_subtree/topic_5 && |
Johannes Schindelin | d51b771 | 2019-07-31 08:18:43 -0700 | [diff] [blame] | 63 | |
| 64 | git checkout -b to-rebase && |
Elijah Newren | 476998d | 2019-09-04 14:40:48 -0700 | [diff] [blame] | 65 | git fast-export --no-data HEAD -- files_subtree/ | |
| 66 | sed -e "s%\([0-9a-f]\{40\} \)files_subtree/%\1%" | |
| 67 | git fast-import --force --quiet && |
| 68 | git reset --hard && |
Johannes Schindelin | d51b771 | 2019-07-31 08:18:43 -0700 | [diff] [blame] | 69 | git commit -m "Empty commit" --allow-empty |
David A. Greene | 5f35900 | 2016-06-28 05:54:02 -0500 | [diff] [blame] | 70 | ' |
| 71 | |
Johannes Schindelin | b6211b8 | 2020-09-26 21:04:21 +0000 | [diff] [blame] | 72 | # FAILURE: Does not preserve topic_4. |
Johannes Schindelin | b8c6f24 | 2019-07-31 08:18:44 -0700 | [diff] [blame] | 73 | test_expect_failure REBASE_P 'Rebase -Xsubtree --preserve-merges --onto commit' ' |
David A. Greene | 5f35900 | 2016-06-28 05:54:02 -0500 | [diff] [blame] | 74 | reset_rebase && |
Johannes Schindelin | b8c6f24 | 2019-07-31 08:18:44 -0700 | [diff] [blame] | 75 | git checkout -b rebase-preserve-merges to-rebase && |
Johannes Schindelin | d1c02d9 | 2020-11-18 23:44:25 +0000 | [diff] [blame] | 76 | git rebase -Xsubtree=files_subtree --preserve-merges --onto files-main main && |
Johannes Schindelin | b6211b8 | 2020-09-26 21:04:21 +0000 | [diff] [blame] | 77 | verbose test "$(commit_message HEAD~)" = "topic_4" && |
| 78 | verbose test "$(commit_message HEAD)" = "files_subtree/topic_5" |
David A. Greene | 5f35900 | 2016-06-28 05:54:02 -0500 | [diff] [blame] | 79 | ' |
| 80 | |
Johannes Schindelin | b6211b8 | 2020-09-26 21:04:21 +0000 | [diff] [blame] | 81 | # FAILURE: Does not preserve topic_4. |
Johannes Schindelin | b8c6f24 | 2019-07-31 08:18:44 -0700 | [diff] [blame] | 82 | test_expect_failure REBASE_P 'Rebase -Xsubtree --keep-empty --preserve-merges --onto commit' ' |
David A. Greene | 5f35900 | 2016-06-28 05:54:02 -0500 | [diff] [blame] | 83 | reset_rebase && |
Johannes Schindelin | b8c6f24 | 2019-07-31 08:18:44 -0700 | [diff] [blame] | 84 | git checkout -b rebase-keep-empty to-rebase && |
Johannes Schindelin | d1c02d9 | 2020-11-18 23:44:25 +0000 | [diff] [blame] | 85 | git rebase -Xsubtree=files_subtree --keep-empty --preserve-merges --onto files-main main && |
Johannes Schindelin | b6211b8 | 2020-09-26 21:04:21 +0000 | [diff] [blame] | 86 | verbose test "$(commit_message HEAD~2)" = "topic_4" && |
| 87 | verbose test "$(commit_message HEAD~)" = "files_subtree/topic_5" && |
David A. Greene | 5f35900 | 2016-06-28 05:54:02 -0500 | [diff] [blame] | 88 | verbose test "$(commit_message HEAD)" = "Empty commit" |
| 89 | ' |
| 90 | |
Elijah Newren | e98c426 | 2020-02-15 21:36:25 +0000 | [diff] [blame] | 91 | test_expect_success 'Rebase -Xsubtree --empty=ask --onto commit' ' |
David A. Greene | 5f35900 | 2016-06-28 05:54:02 -0500 | [diff] [blame] | 92 | reset_rebase && |
Johannes Schindelin | b8c6f24 | 2019-07-31 08:18:44 -0700 | [diff] [blame] | 93 | git checkout -b rebase-onto to-rebase && |
Johannes Schindelin | d1c02d9 | 2020-11-18 23:44:25 +0000 | [diff] [blame] | 94 | test_must_fail git rebase -Xsubtree=files_subtree --empty=ask --onto files-main main && |
Johannes Schindelin | 4e6023b | 2019-07-31 08:18:46 -0700 | [diff] [blame] | 95 | : first pick results in no changes && |
Elijah Newren | d48e5e2 | 2020-02-15 21:36:24 +0000 | [diff] [blame] | 96 | git rebase --skip && |
Johannes Schindelin | b6211b8 | 2020-09-26 21:04:21 +0000 | [diff] [blame] | 97 | verbose test "$(commit_message HEAD~2)" = "topic_4" && |
| 98 | verbose test "$(commit_message HEAD~)" = "files_subtree/topic_5" && |
David A. Greene | 5f35900 | 2016-06-28 05:54:02 -0500 | [diff] [blame] | 99 | verbose test "$(commit_message HEAD)" = "Empty commit" |
| 100 | ' |
| 101 | |
Elijah Newren | e98c426 | 2020-02-15 21:36:25 +0000 | [diff] [blame] | 102 | test_expect_success 'Rebase -Xsubtree --empty=ask --rebase-merges --onto commit' ' |
Johannes Schindelin | e1fac53 | 2019-07-31 08:18:49 -0700 | [diff] [blame] | 103 | reset_rebase && |
| 104 | git checkout -b rebase-merges-onto to-rebase && |
Johannes Schindelin | d1c02d9 | 2020-11-18 23:44:25 +0000 | [diff] [blame] | 105 | test_must_fail git rebase -Xsubtree=files_subtree --empty=ask --rebase-merges --onto files-main --root && |
Johannes Schindelin | e1fac53 | 2019-07-31 08:18:49 -0700 | [diff] [blame] | 106 | : first pick results in no changes && |
Elijah Newren | d48e5e2 | 2020-02-15 21:36:24 +0000 | [diff] [blame] | 107 | git rebase --skip && |
Johannes Schindelin | b6211b8 | 2020-09-26 21:04:21 +0000 | [diff] [blame] | 108 | verbose test "$(commit_message HEAD~2)" = "topic_4" && |
| 109 | verbose test "$(commit_message HEAD~)" = "files_subtree/topic_5" && |
Johannes Schindelin | e1fac53 | 2019-07-31 08:18:49 -0700 | [diff] [blame] | 110 | verbose test "$(commit_message HEAD)" = "Empty commit" |
| 111 | ' |
| 112 | |
David A. Greene | 5f35900 | 2016-06-28 05:54:02 -0500 | [diff] [blame] | 113 | test_done |