]>
Commit | Line | Data |
---|---|---|
5f359008 DG |
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 | ' | |
7 | . ./test-lib.sh | |
8 | . "$TEST_DIRECTORY"/lib-rebase.sh | |
9 | ||
10 | commit_message() { | |
11 | git log --pretty=format:%s -1 "$1" | |
12 | } | |
13 | ||
8c1e2404 JS |
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): | |
17 | # | |
b6211b89 | 18 | # topic_1 - topic_2 - topic_3 |
8c1e2404 | 19 | # \ |
b6211b89 | 20 | # README ---------------------- Add subproject master - topic_4 - files_subtree/topic_5 |
8c1e2404 JS |
21 | # |
22 | # Where the merge moves the files master[123].t into the subdirectory | |
b6211b89 | 23 | # files_subtree/ and topic_4 as well as files_subtree/topic_5 add files to that |
8c1e2404 JS |
24 | # directory directly. |
25 | # | |
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 | |
29 | # this: | |
30 | # | |
b6211b89 | 31 | # Add subproject master - topic_4 - files_subtree/topic_5 - Empty commit |
8c1e2404 | 32 | # |
b6211b89 | 33 | # where the root commit adds three files: topic_1.t, topic_2.t and topic_3.t. |
8c1e2404 | 34 | # |
b6211b89 | 35 | # This commit history is then rebased onto `topic_3` with the |
8c1e2404 JS |
36 | # `-Xsubtree=files_subtree` option in three different ways: |
37 | # | |
38 | # 1. using `--preserve-merges` | |
39 | # 2. using `--preserve-merges` and --keep-empty | |
40 | # 3. without specifying a rebase backend | |
41 | ||
5f359008 DG |
42 | test_expect_success 'setup' ' |
43 | test_commit README && | |
c248d32c JS |
44 | |
45 | git init files && | |
b6211b89 JS |
46 | test_commit -C files topic_1 && |
47 | test_commit -C files topic_2 && | |
48 | test_commit -C files topic_3 && | |
c248d32c JS |
49 | |
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 \ | |
53 | files-master && | |
54 | git read-tree --prefix=files_subtree -u files-master && | |
55 | git commit -m "Add subproject master" && | |
56 | ||
57 | : add two extra commits to rebase && | |
b6211b89 JS |
58 | test_commit -C files_subtree topic_4 && |
59 | test_commit files_subtree/topic_5 && | |
d51b771d JS |
60 | |
61 | git checkout -b to-rebase && | |
476998d0 EN |
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 && | |
65 | git reset --hard && | |
d51b771d | 66 | git commit -m "Empty commit" --allow-empty |
5f359008 DG |
67 | ' |
68 | ||
b6211b89 | 69 | # FAILURE: Does not preserve topic_4. |
b8c6f242 | 70 | test_expect_failure REBASE_P 'Rebase -Xsubtree --preserve-merges --onto commit' ' |
5f359008 | 71 | reset_rebase && |
b8c6f242 | 72 | git checkout -b rebase-preserve-merges to-rebase && |
5f359008 | 73 | git rebase -Xsubtree=files_subtree --preserve-merges --onto files-master master && |
b6211b89 JS |
74 | verbose test "$(commit_message HEAD~)" = "topic_4" && |
75 | verbose test "$(commit_message HEAD)" = "files_subtree/topic_5" | |
5f359008 DG |
76 | ' |
77 | ||
b6211b89 | 78 | # FAILURE: Does not preserve topic_4. |
b8c6f242 | 79 | test_expect_failure REBASE_P 'Rebase -Xsubtree --keep-empty --preserve-merges --onto commit' ' |
5f359008 | 80 | reset_rebase && |
b8c6f242 | 81 | git checkout -b rebase-keep-empty to-rebase && |
5f359008 | 82 | git rebase -Xsubtree=files_subtree --keep-empty --preserve-merges --onto files-master master && |
b6211b89 JS |
83 | verbose test "$(commit_message HEAD~2)" = "topic_4" && |
84 | verbose test "$(commit_message HEAD~)" = "files_subtree/topic_5" && | |
5f359008 DG |
85 | verbose test "$(commit_message HEAD)" = "Empty commit" |
86 | ' | |
87 | ||
e98c4269 | 88 | test_expect_success 'Rebase -Xsubtree --empty=ask --onto commit' ' |
5f359008 | 89 | reset_rebase && |
b8c6f242 | 90 | git checkout -b rebase-onto to-rebase && |
e98c4269 | 91 | test_must_fail git rebase -Xsubtree=files_subtree --empty=ask --onto files-master master && |
4e6023b1 | 92 | : first pick results in no changes && |
d48e5e21 | 93 | git rebase --skip && |
b6211b89 JS |
94 | verbose test "$(commit_message HEAD~2)" = "topic_4" && |
95 | verbose test "$(commit_message HEAD~)" = "files_subtree/topic_5" && | |
5f359008 DG |
96 | verbose test "$(commit_message HEAD)" = "Empty commit" |
97 | ' | |
98 | ||
e98c4269 | 99 | test_expect_success 'Rebase -Xsubtree --empty=ask --rebase-merges --onto commit' ' |
e1fac531 JS |
100 | reset_rebase && |
101 | git checkout -b rebase-merges-onto to-rebase && | |
e98c4269 | 102 | test_must_fail git rebase -Xsubtree=files_subtree --empty=ask --rebase-merges --onto files-master --root && |
e1fac531 | 103 | : first pick results in no changes && |
d48e5e21 | 104 | git rebase --skip && |
b6211b89 JS |
105 | verbose test "$(commit_message HEAD~2)" = "topic_4" && |
106 | verbose test "$(commit_message HEAD~)" = "files_subtree/topic_5" && | |
e1fac531 JS |
107 | verbose test "$(commit_message HEAD)" = "Empty commit" |
108 | ' | |
109 | ||
5f359008 | 110 | test_done |