7a37235768574db87e76b3659ca4cfd39f248563
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 'Rebase -Xsubtree --preserve-merges --onto commit' '
68 reset_rebase &&
69 git checkout -b rebase-preserve-merges to-rebase &&
70 git rebase -Xsubtree=files_subtree --preserve-merges --onto files-master master &&
71 verbose test "$(commit_message HEAD~)" = "master4" &&
72 verbose test "$(commit_message HEAD)" = "files_subtree/master5"
73'
74
75# FAILURE: Does not preserve master4.
76test_expect_failure REBASE_P 'Rebase -Xsubtree --keep-empty --preserve-merges --onto commit' '
77 reset_rebase &&
78 git checkout -b rebase-keep-empty to-rebase &&
79 git rebase -Xsubtree=files_subtree --keep-empty --preserve-merges --onto files-master master &&
80 verbose test "$(commit_message HEAD~2)" = "master4" &&
81 verbose test "$(commit_message HEAD~)" = "files_subtree/master5" &&
82 verbose test "$(commit_message HEAD)" = "Empty commit"
83'
84
85test_expect_success 'Rebase -Xsubtree --keep-empty --onto commit' '
86 reset_rebase &&
87 git checkout -b rebase-onto to-rebase &&
88 test_must_fail git rebase -Xsubtree=files_subtree --keep-empty --onto files-master master &&
89 : first pick results in no changes &&
90 git rebase --continue &&
91 verbose test "$(commit_message HEAD~2)" = "master4" &&
92 verbose test "$(commit_message HEAD~)" = "files_subtree/master5" &&
93 verbose test "$(commit_message HEAD)" = "Empty commit"
94'
95
96test_done