1#!/bin/sh
2
3test_description='git rebase --onto A...B'
4
5. ./test-lib.sh
6. "$TEST_DIRECTORY/lib-rebase.sh"
7
8# Rebase only the tip commit of "topic" on merge base between "master"
9# and "topic". Cannot do this for "side" with "master" because there
10# is no single merge base.
11#
12#
13# F---G topic G'
14# / /
15# A---B---C---D---E master --> A---B---C---D---E
16# \ \ /
17# \ x
18# \ / \
19# H---I---J---K side
20
21test_expect_success setup '
22 test_commit A &&
23 test_commit B &&
24 git branch side &&
25 test_commit C &&
26 git branch topic &&
27 git checkout side &&
28 test_commit H &&
29 git checkout master &&
30 test_tick &&
31 git merge H &&
32 git tag D &&
33 test_commit E &&
34 git checkout topic &&
35 test_commit F &&
36 test_commit G &&
37 git checkout side &&
38 test_tick &&
39 git merge C &&
40 git tag I &&
41 test_commit J &&
42 test_commit K
43'
44
45test_expect_success 'rebase --onto master...topic' '
46 git reset --hard &&
47 git checkout topic &&
48 git reset --hard G &&
49
50 git rebase --onto master...topic F &&
51 git rev-parse HEAD^1 >actual &&
52 git rev-parse C^0 >expect &&
53 test_cmp expect actual
54'
55
56test_expect_success 'rebase --onto master...' '
57 git reset --hard &&
58 git checkout topic &&
59 git reset --hard G &&
60
61 git rebase --onto master... F &&
62 git rev-parse HEAD^1 >actual &&
63 git rev-parse C^0 >expect &&
64 test_cmp expect actual
65'
66
67test_expect_success 'rebase --onto master...side' '
68 git reset --hard &&
69 git checkout side &&
70 git reset --hard K &&
71
72 test_must_fail git rebase --onto master...side J
73'
74
75test_expect_success 'rebase -i --onto master...topic' '
76 git reset --hard &&
77 git checkout topic &&
78 git reset --hard G &&
79 set_fake_editor &&
80 EXPECT_COUNT=1 git rebase -i --onto master...topic F &&
81 git rev-parse HEAD^1 >actual &&
82 git rev-parse C^0 >expect &&
83 test_cmp expect actual
84'
85
86test_expect_success 'rebase -i --onto master...' '
87 git reset --hard &&
88 git checkout topic &&
89 git reset --hard G &&
90 set_fake_editor &&
91 EXPECT_COUNT=1 git rebase -i --onto master... F &&
92 git rev-parse HEAD^1 >actual &&
93 git rev-parse C^0 >expect &&
94 test_cmp expect actual
95'
96
97test_expect_success 'rebase -i --onto master...side' '
98 git reset --hard &&
99 git checkout side &&
100 git reset --hard K &&
101
102 set_fake_editor &&
103 test_must_fail git rebase -i --onto master...side J
104'
105
106test_expect_success 'rebase --keep-base --onto incompatible' '
107 test_must_fail git rebase --keep-base --onto master...
108'
109
110test_expect_success 'rebase --keep-base --root incompatible' '
111 test_must_fail git rebase --keep-base --root
112'
113
114test_expect_success 'rebase --keep-base master from topic' '
115 git reset --hard &&
116 git checkout topic &&
117 git reset --hard G &&
118
119 git rebase --keep-base master &&
120 git rev-parse C >base.expect &&
121 git merge-base master HEAD >base.actual &&
122 test_cmp base.expect base.actual &&
123
124 git rev-parse HEAD~2 >actual &&
125 git rev-parse C^0 >expect &&
126 test_cmp expect actual
127'
128
129test_expect_success 'rebase --keep-base master from side' '
130 git reset --hard &&
131 git checkout side &&
132 git reset --hard K &&
133
134 test_must_fail git rebase --keep-base master
135'
136
137test_expect_success 'rebase -i --keep-base master from topic' '
138 git reset --hard &&
139 git checkout topic &&
140 git reset --hard G &&
141
142 set_fake_editor &&
143 EXPECT_COUNT=2 git rebase -i --keep-base master &&
144 git rev-parse C >base.expect &&
145 git merge-base master HEAD >base.actual &&
146 test_cmp base.expect base.actual &&
147
148 git rev-parse HEAD~2 >actual &&
149 git rev-parse C^0 >expect &&
150 test_cmp expect actual
151'
152
153test_expect_success 'rebase -i --keep-base master from side' '
154 git reset --hard &&
155 git checkout side &&
156 git reset --hard K &&
157
158 set_fake_editor &&
159 test_must_fail git rebase -i --keep-base master
160'
161
162test_done