completion: fix incorrect bash/zsh string equality check
[git/debian.git] / t / t3427-rebase-subtree.sh
blobe78c7e37969ab3d7caabcd3f39131e134670cf06
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 three different ways:
41 # 1. using `--preserve-merges`
42 # 2. using `--preserve-merges` and --keep-empty
43 # 3. without specifying a rebase backend
45 test_expect_success 'setup' '
46 test_commit README &&
48 git init files &&
49 test_commit -C files topic_1 &&
50 test_commit -C files topic_2 &&
51 test_commit -C files topic_3 &&
53 : perform subtree merge into files_subtree/ &&
54 git fetch files refs/heads/main:refs/heads/files-main &&
55 git merge -s ours --no-commit --allow-unrelated-histories \
56 files-main &&
57 git read-tree --prefix=files_subtree -u files-main &&
58 git commit -m "Add subproject main" &&
60 : add two extra commits to rebase &&
61 test_commit -C files_subtree topic_4 &&
62 test_commit files_subtree/topic_5 &&
64 git checkout -b to-rebase &&
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 &&
69 git commit -m "Empty commit" --allow-empty
72 # FAILURE: Does not preserve topic_4.
73 test_expect_failure REBASE_P 'Rebase -Xsubtree --preserve-merges --onto commit' '
74 reset_rebase &&
75 git checkout -b rebase-preserve-merges to-rebase &&
76 git rebase -Xsubtree=files_subtree --preserve-merges --onto files-main main &&
77 verbose test "$(commit_message HEAD~)" = "topic_4" &&
78 verbose test "$(commit_message HEAD)" = "files_subtree/topic_5"
81 # FAILURE: Does not preserve topic_4.
82 test_expect_failure REBASE_P 'Rebase -Xsubtree --keep-empty --preserve-merges --onto commit' '
83 reset_rebase &&
84 git checkout -b rebase-keep-empty to-rebase &&
85 git rebase -Xsubtree=files_subtree --keep-empty --preserve-merges --onto files-main main &&
86 verbose test "$(commit_message HEAD~2)" = "topic_4" &&
87 verbose test "$(commit_message HEAD~)" = "files_subtree/topic_5" &&
88 verbose test "$(commit_message HEAD)" = "Empty commit"
91 test_expect_success 'Rebase -Xsubtree --empty=ask --onto commit' '
92 reset_rebase &&
93 git checkout -b rebase-onto to-rebase &&
94 test_must_fail git rebase -Xsubtree=files_subtree --empty=ask --onto files-main main &&
95 : first pick results in no changes &&
96 git rebase --skip &&
97 verbose test "$(commit_message HEAD~2)" = "topic_4" &&
98 verbose test "$(commit_message HEAD~)" = "files_subtree/topic_5" &&
99 verbose test "$(commit_message HEAD)" = "Empty commit"
102 test_expect_success 'Rebase -Xsubtree --empty=ask --rebase-merges --onto commit' '
103 reset_rebase &&
104 git checkout -b rebase-merges-onto to-rebase &&
105 test_must_fail git rebase -Xsubtree=files_subtree --empty=ask --rebase-merges --onto files-main --root &&
106 : first pick results in no changes &&
107 git rebase --skip &&
108 verbose test "$(commit_message HEAD~2)" = "topic_4" &&
109 verbose test "$(commit_message HEAD~)" = "files_subtree/topic_5" &&
110 verbose test "$(commit_message HEAD)" = "Empty commit"
113 test_done