interplane.Get Omega
Read in your language

git

[Ported from github.com/git/git] Sync with Git 2.56.1

Brought by drakestapleton

branch master Branches Tags History

git / t / t3427-rebase-subtree.sh

93 lines · 3207 bytes Raw Blame History
1#!/bin/sh
2
3test_description='git rebase tests for -Xsubtree
4
5This test runs git rebase and tests the subtree strategy.
6'
7GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
8export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
9
10. ./test-lib.sh
11. "$TEST_DIRECTORY"/lib-rebase.sh
12
13commit_message() {
14 git log --pretty=format:%s -1 "$1"
15}
16
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#
21# topic_1 - topic_2 - topic_3
22# \
23# README ---------------------- Add subproject main - topic_4 - files_subtree/topic_5
24#
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.
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#
34# Add subproject main - topic_4 - files_subtree/topic_5 - Empty commit
35#
36# where the root commit adds three files: topic_1.t, topic_2.t and topic_3.t.
37#
38# This commit history is then rebased onto `topic_3` with the
39# `-Xsubtree=files_subtree` option in two different ways:
40#
41# 1. without specifying a rebase backend
42# 2. using the `--rebase-merges` backend
43
44test_expect_success 'setup' '
45 test_commit README &&
46
47 git init files &&
48 test_commit -C files topic_1 &&
49 test_commit -C files topic_2 &&
50 test_commit -C files topic_3 &&
51
52 : perform subtree merge into files_subtree/ &&
53 git fetch files refs/heads/main:refs/heads/files-main &&
54 git merge -s ours --no-commit --allow-unrelated-histories \
55 files-main &&
56 git read-tree --prefix=files_subtree -u files-main &&
57 git commit -m "Add subproject main" &&
58
59 : add two extra commits to rebase &&
60 test_commit -C files_subtree topic_4 &&
61 test_commit files_subtree/topic_5 &&
62
63 git checkout -b to-rebase &&
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 &&
68 git commit -m "Empty commit" --allow-empty
69'
70
71test_expect_success 'Rebase -Xsubtree --empty=ask --onto commit' '
72 reset_rebase &&
73 git checkout -b rebase-onto to-rebase &&
74 test_must_fail git rebase -Xsubtree=files_subtree --empty=ask --onto files-main main &&
75 : first pick results in no changes &&
76 git rebase --skip &&
77 test "$(commit_message HEAD~2)" = "topic_4" &&
78 test "$(commit_message HEAD~)" = "files_subtree/topic_5" &&
79 test "$(commit_message HEAD)" = "Empty commit"
80'
81
82test_expect_success 'Rebase -Xsubtree --empty=ask --rebase-merges --onto commit' '
83 reset_rebase &&
84 git checkout -b rebase-merges-onto to-rebase &&
85 test_must_fail git rebase -Xsubtree=files_subtree --empty=ask --rebase-merges --onto files-main --root &&
86 : first pick results in no changes &&
87 git rebase --skip &&
88 test "$(commit_message HEAD~2)" = "topic_4" &&
89 test "$(commit_message HEAD~)" = "files_subtree/topic_5" &&
90 test "$(commit_message HEAD)" = "Empty commit"
91'
92
93test_done