64ba95f3e0dda0fc72fceac07627a769f0335828
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 filter-branch --prune-empty -f --subdirectory-filter files_subtree &&
63 git commit -m "Empty commit" --allow-empty
64'
65
66# FAILURE: Does not preserve master4.
67test_expect_failure REBASE_P \
68 'Rebase -Xsubtree --preserve-merges --onto commit 4' '
69 reset_rebase &&
70 git checkout -b rebase-preserve-merges-4 to-rebase &&
71 git rebase -Xsubtree=files_subtree --preserve-merges --onto files-master master &&
72 verbose test "$(commit_message HEAD~)" = "files_subtree/master4"
73'
74
75# FAILURE: Does not preserve master5.
76test_expect_failure REBASE_P \
77 'Rebase -Xsubtree --preserve-merges --onto commit 5' '
78 reset_rebase &&
79 git checkout -b rebase-preserve-merges-5 to-rebase &&
80 git rebase -Xsubtree=files_subtree --preserve-merges --onto files-master master &&
81 verbose test "$(commit_message HEAD)" = "files_subtree/master5"
82'
83
84# FAILURE: Does not preserve master4.
85test_expect_failure REBASE_P \
86 'Rebase -Xsubtree --keep-empty --preserve-merges --onto commit 4' '
87 reset_rebase &&
88 git checkout -b rebase-keep-empty-4 to-rebase &&
89 git rebase -Xsubtree=files_subtree --keep-empty --preserve-merges --onto files-master master &&
90 verbose test "$(commit_message HEAD~2)" = "files_subtree/master4"
91'
92
93# FAILURE: Does not preserve master5.
94test_expect_failure REBASE_P \
95 'Rebase -Xsubtree --keep-empty --preserve-merges --onto commit 5' '
96 reset_rebase &&
97 git checkout -b rebase-keep-empty-5 to-rebase &&
98 git rebase -Xsubtree=files_subtree --keep-empty --preserve-merges --onto files-master master &&
99 verbose test "$(commit_message HEAD~)" = "files_subtree/master5"
100'
101
102# FAILURE: Does not preserve Empty.
103test_expect_failure REBASE_P \
104 'Rebase -Xsubtree --keep-empty --preserve-merges --onto empty commit' '
105 reset_rebase &&
106 git checkout -b rebase-keep-empty-empty to-rebase &&
107 git rebase -Xsubtree=files_subtree --keep-empty --preserve-merges --onto files-master master &&
108 verbose test "$(commit_message HEAD)" = "Empty commit"
109'
110
111# FAILURE: fatal: Could not parse object
112test_expect_failure 'Rebase -Xsubtree --onto commit 4' '
113 reset_rebase &&
114 git checkout -b rebase-onto-4 to-rebase &&
115 git rebase -Xsubtree=files_subtree --onto files-master master &&
116 verbose test "$(commit_message HEAD~2)" = "files_subtree/master4"
117'
118
119# FAILURE: fatal: Could not parse object
120test_expect_failure 'Rebase -Xsubtree --onto commit 5' '
121 reset_rebase &&
122 git checkout -b rebase-onto-5 to-rebase &&
123 git rebase -Xsubtree=files_subtree --onto files-master master &&
124 verbose test "$(commit_message HEAD~)" = "files_subtree/master5"
125'
126# FAILURE: fatal: Could not parse object
127test_expect_failure 'Rebase -Xsubtree --onto empty commit' '
128 reset_rebase &&
129 git checkout -b rebase-onto-empty to-rebase &&
130 git rebase -Xsubtree=files_subtree --onto files-master master &&
131 verbose test "$(commit_message HEAD)" = "Empty commit"
132'
133
134test_done