]> git.ipfire.org Git - thirdparty/git.git/blame - t/t3427-rebase-subtree.sh
Merge branch 'js/range-diff-wo-dotdot'
[thirdparty/git.git] / t / t3427-rebase-subtree.sh
CommitLineData
5f359008
DG
1#!/bin/sh
2
3test_description='git rebase tests for -Xsubtree
4
5This test runs git rebase and tests the subtree strategy.
6'
d1c02d93 7GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
334afbc7
JS
8export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
9
5f359008
DG
10. ./test-lib.sh
11. "$TEST_DIRECTORY"/lib-rebase.sh
12
13commit_message() {
14 git log --pretty=format:%s -1 "$1"
15}
16
8c1e2404
JS
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#
b6211b89 21# topic_1 - topic_2 - topic_3
8c1e2404 22# \
d1c02d93 23# README ---------------------- Add subproject main - topic_4 - files_subtree/topic_5
8c1e2404 24#
adbcf53e 25# Where the merge moves the files topic_[123].t into the subdirectory
b6211b89 26# files_subtree/ and topic_4 as well as files_subtree/topic_5 add files to that
8c1e2404
JS
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#
d1c02d93 34# Add subproject main - topic_4 - files_subtree/topic_5 - Empty commit
8c1e2404 35#
b6211b89 36# where the root commit adds three files: topic_1.t, topic_2.t and topic_3.t.
8c1e2404 37#
b6211b89 38# This commit history is then rebased onto `topic_3` with the
8c1e2404
JS
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
5f359008
DG
45test_expect_success 'setup' '
46 test_commit README &&
c248d32c
JS
47
48 git init files &&
b6211b89
JS
49 test_commit -C files topic_1 &&
50 test_commit -C files topic_2 &&
51 test_commit -C files topic_3 &&
c248d32c
JS
52
53 : perform subtree merge into files_subtree/ &&
d1c02d93 54 git fetch files refs/heads/main:refs/heads/files-main &&
c248d32c 55 git merge -s ours --no-commit --allow-unrelated-histories \
d1c02d93
JS
56 files-main &&
57 git read-tree --prefix=files_subtree -u files-main &&
58 git commit -m "Add subproject main" &&
c248d32c
JS
59
60 : add two extra commits to rebase &&
b6211b89
JS
61 test_commit -C files_subtree topic_4 &&
62 test_commit files_subtree/topic_5 &&
d51b771d
JS
63
64 git checkout -b to-rebase &&
476998d0
EN
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 &&
d51b771d 69 git commit -m "Empty commit" --allow-empty
5f359008
DG
70'
71
b6211b89 72# FAILURE: Does not preserve topic_4.
b8c6f242 73test_expect_failure REBASE_P 'Rebase -Xsubtree --preserve-merges --onto commit' '
5f359008 74 reset_rebase &&
b8c6f242 75 git checkout -b rebase-preserve-merges to-rebase &&
d1c02d93 76 git rebase -Xsubtree=files_subtree --preserve-merges --onto files-main main &&
b6211b89
JS
77 verbose test "$(commit_message HEAD~)" = "topic_4" &&
78 verbose test "$(commit_message HEAD)" = "files_subtree/topic_5"
5f359008
DG
79'
80
b6211b89 81# FAILURE: Does not preserve topic_4.
b8c6f242 82test_expect_failure REBASE_P 'Rebase -Xsubtree --keep-empty --preserve-merges --onto commit' '
5f359008 83 reset_rebase &&
b8c6f242 84 git checkout -b rebase-keep-empty to-rebase &&
d1c02d93 85 git rebase -Xsubtree=files_subtree --keep-empty --preserve-merges --onto files-main main &&
b6211b89
JS
86 verbose test "$(commit_message HEAD~2)" = "topic_4" &&
87 verbose test "$(commit_message HEAD~)" = "files_subtree/topic_5" &&
5f359008
DG
88 verbose test "$(commit_message HEAD)" = "Empty commit"
89'
90
e98c4269 91test_expect_success 'Rebase -Xsubtree --empty=ask --onto commit' '
5f359008 92 reset_rebase &&
b8c6f242 93 git checkout -b rebase-onto to-rebase &&
d1c02d93 94 test_must_fail git rebase -Xsubtree=files_subtree --empty=ask --onto files-main main &&
4e6023b1 95 : first pick results in no changes &&
d48e5e21 96 git rebase --skip &&
b6211b89
JS
97 verbose test "$(commit_message HEAD~2)" = "topic_4" &&
98 verbose test "$(commit_message HEAD~)" = "files_subtree/topic_5" &&
5f359008
DG
99 verbose test "$(commit_message HEAD)" = "Empty commit"
100'
101
e98c4269 102test_expect_success 'Rebase -Xsubtree --empty=ask --rebase-merges --onto commit' '
e1fac531
JS
103 reset_rebase &&
104 git checkout -b rebase-merges-onto to-rebase &&
d1c02d93 105 test_must_fail git rebase -Xsubtree=files_subtree --empty=ask --rebase-merges --onto files-main --root &&
e1fac531 106 : first pick results in no changes &&
d48e5e21 107 git rebase --skip &&
b6211b89
JS
108 verbose test "$(commit_message HEAD~2)" = "topic_4" &&
109 verbose test "$(commit_message HEAD~)" = "files_subtree/topic_5" &&
e1fac531
JS
110 verbose test "$(commit_message HEAD)" = "Empty commit"
111'
112
5f359008 113test_done