]> git.ipfire.org Git - thirdparty/git.git/blame - t/t3427-rebase-subtree.sh
Start the 2.46 cycle
[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
aa4df107 39# `-Xsubtree=files_subtree` option in two different ways:
8c1e2404 40#
aa4df107
JS
41# 1. without specifying a rebase backend
42# 2. using the `--rebase-merges` backend
8c1e2404 43
5f359008
DG
44test_expect_success 'setup' '
45 test_commit README &&
c248d32c
JS
46
47 git init files &&
b6211b89
JS
48 test_commit -C files topic_1 &&
49 test_commit -C files topic_2 &&
50 test_commit -C files topic_3 &&
c248d32c
JS
51
52 : perform subtree merge into files_subtree/ &&
d1c02d93 53 git fetch files refs/heads/main:refs/heads/files-main &&
c248d32c 54 git merge -s ours --no-commit --allow-unrelated-histories \
d1c02d93
JS
55 files-main &&
56 git read-tree --prefix=files_subtree -u files-main &&
57 git commit -m "Add subproject main" &&
c248d32c
JS
58
59 : add two extra commits to rebase &&
b6211b89
JS
60 test_commit -C files_subtree topic_4 &&
61 test_commit files_subtree/topic_5 &&
d51b771d
JS
62
63 git checkout -b to-rebase &&
476998d0
EN
64 git fast-export --no-data HEAD -- files_subtree/ |
65 sed -e "s%\([0-9a-f]\{40\} \)files_subtree/%\1%" |
66 git fast-import --force --quiet &&
67 git reset --hard &&
d51b771d 68 git commit -m "Empty commit" --allow-empty
5f359008
DG
69'
70
e98c4269 71test_expect_success 'Rebase -Xsubtree --empty=ask --onto commit' '
5f359008 72 reset_rebase &&
b8c6f242 73 git checkout -b rebase-onto to-rebase &&
d1c02d93 74 test_must_fail git rebase -Xsubtree=files_subtree --empty=ask --onto files-main main &&
4e6023b1 75 : first pick results in no changes &&
d48e5e21 76 git rebase --skip &&
8ddfce71
JK
77 test "$(commit_message HEAD~2)" = "topic_4" &&
78 test "$(commit_message HEAD~)" = "files_subtree/topic_5" &&
79 test "$(commit_message HEAD)" = "Empty commit"
5f359008
DG
80'
81
e98c4269 82test_expect_success 'Rebase -Xsubtree --empty=ask --rebase-merges --onto commit' '
e1fac531
JS
83 reset_rebase &&
84 git checkout -b rebase-merges-onto to-rebase &&
d1c02d93 85 test_must_fail git rebase -Xsubtree=files_subtree --empty=ask --rebase-merges --onto files-main --root &&
e1fac531 86 : first pick results in no changes &&
d48e5e21 87 git rebase --skip &&
8ddfce71
JK
88 test "$(commit_message HEAD~2)" = "topic_4" &&
89 test "$(commit_message HEAD~)" = "files_subtree/topic_5" &&
90 test "$(commit_message HEAD)" = "Empty commit"
e1fac531
JS
91'
92
5f359008 93test_done