1#!/bin/sh
2
3test_description='git rebase tests for -Xsubtree
4
5This test runs git rebase and tests the subtree strategy.
6'
7. ./test-lib.sh
8. "$TEST_DIRECTORY"/lib-rebase.sh
9
10commit_message() {
11 git log --pretty=format:%s -1 "$1"
12}
13
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#
18# master1 - master2 - master3
19# \
20# README ---------------------- Add subproject master - master4 - files_subtree/master5
21#
22# Where the merge moves the files master[123].t into the subdirectory
23# files_subtree/ and master4 as well as files_subtree/master5 add files to that
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#
31# Add subproject master - master4 - files_subtree/master5 - Empty commit
32#
33# where the root commit adds three files: master1.t, master2.t and master3.t.
34#
35# This commit history is then rebased onto `master3` with the
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
42test_expect_success 'setup' '
43 test_commit README &&
44
45 git init files &&
46 test_commit -C files master1 &&
47 test_commit -C files master2 &&
48 test_commit -C files master3 &&
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 &&
58 test_commit -C files_subtree master4 &&
59 test_commit files_subtree/master5 &&
60
61 git checkout -b to-rebase &&
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 &&
66 git commit -m "Empty commit" --allow-empty
67'
68
69# FAILURE: Does not preserve master4.
70test_expect_failure REBASE_P 'Rebase -Xsubtree --preserve-merges --onto commit' '
71 reset_rebase &&
72 git checkout -b rebase-preserve-merges to-rebase &&
73 git rebase -Xsubtree=files_subtree --preserve-merges --onto files-master master &&
74 verbose test "$(commit_message HEAD~)" = "master4" &&
75 verbose test "$(commit_message HEAD)" = "files_subtree/master5"
76'
77
78# FAILURE: Does not preserve master4.
79test_expect_failure REBASE_P 'Rebase -Xsubtree --keep-empty --preserve-merges --onto commit' '
80 reset_rebase &&
81 git checkout -b rebase-keep-empty to-rebase &&
82 git rebase -Xsubtree=files_subtree --keep-empty --preserve-merges --onto files-master master &&
83 verbose test "$(commit_message HEAD~2)" = "master4" &&
84 verbose test "$(commit_message HEAD~)" = "files_subtree/master5" &&
85 verbose test "$(commit_message HEAD)" = "Empty commit"
86'
87
88test_expect_success 'Rebase -Xsubtree --keep-empty --onto commit' '
89 reset_rebase &&
90 git checkout -b rebase-onto to-rebase &&
91 test_must_fail git rebase -Xsubtree=files_subtree --keep-empty --onto files-master master &&
92 : first pick results in no changes &&
93 git rebase --continue &&
94 verbose test "$(commit_message HEAD~2)" = "master4" &&
95 verbose test "$(commit_message HEAD~)" = "files_subtree/master5" &&
96 verbose test "$(commit_message HEAD)" = "Empty commit"
97'
98
99test_expect_success 'Rebase -Xsubtree --keep-empty --rebase-merges --onto commit' '
100 reset_rebase &&
101 git checkout -b rebase-merges-onto to-rebase &&
102 test_must_fail git rebase -Xsubtree=files_subtree --keep-empty --rebase-merges --onto files-master --root &&
103 : first pick results in no changes &&
104 git rebase --continue &&
105 verbose test "$(commit_message HEAD~2)" = "master4" &&
106 verbose test "$(commit_message HEAD~)" = "files_subtree/master5" &&
107 verbose test "$(commit_message HEAD)" = "Empty commit"
108'
109
110test_done