]>
Commit | Line | Data |
---|---|---|
7afa845e JS |
1 | #!/bin/sh |
2 | ||
3 | test_description='messages from rebase operation' | |
4 | ||
d1c02d93 | 5 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
334afbc7 JS |
6 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
7 | ||
7afa845e JS |
8 | . ./test-lib.sh |
9 | ||
9e2248ef MZ |
10 | test_expect_success 'setup' ' |
11 | test_commit O fileO && | |
12 | test_commit X fileX && | |
4e5e1b4b | 13 | git branch fast-forward && |
9e2248ef MZ |
14 | test_commit A fileA && |
15 | test_commit B fileB && | |
16 | test_commit Y fileY && | |
7afa845e | 17 | |
4e5e1b4b PW |
18 | git checkout -b conflicts O && |
19 | test_commit P && | |
da1d6336 | 20 | test_commit conflict-X fileX && |
4e5e1b4b PW |
21 | test_commit Q && |
22 | ||
9e2248ef MZ |
23 | git checkout -b topic O && |
24 | git cherry-pick A B && | |
25 | test_commit Z fileZ && | |
a9c3821c | 26 | git tag start |
7afa845e JS |
27 | ' |
28 | ||
7afa845e | 29 | test_expect_success 'rebase -m' ' |
d1c02d93 | 30 | git rebase -m main >actual && |
7db00f0b | 31 | test_must_be_empty actual |
7afa845e JS |
32 | ' |
33 | ||
d1c02d93 JS |
34 | test_expect_success 'rebase against main twice' ' |
35 | git rebase --apply main >out && | |
6789275d | 36 | test_grep "Current branch topic is up to date" out |
c9581cc8 MZ |
37 | ' |
38 | ||
d1c02d93 JS |
39 | test_expect_success 'rebase against main twice with --force' ' |
40 | git rebase --force-rebase --apply main >out && | |
6789275d | 41 | test_grep "Current branch topic is up to date, rebase forced" out |
c9581cc8 MZ |
42 | ' |
43 | ||
d1c02d93 | 44 | test_expect_success 'rebase against main twice from another branch' ' |
c9581cc8 | 45 | git checkout topic^ && |
d1c02d93 | 46 | git rebase --apply main topic >out && |
6789275d | 47 | test_grep "Current branch topic is up to date" out |
c9581cc8 MZ |
48 | ' |
49 | ||
d1c02d93 | 50 | test_expect_success 'rebase fast-forward to main' ' |
c9581cc8 | 51 | git checkout topic^ && |
10cdb9f3 | 52 | git rebase --apply topic >out && |
6789275d | 53 | test_grep "Fast-forwarded HEAD to topic" out |
c9581cc8 MZ |
54 | ' |
55 | ||
a9c3821c | 56 | test_expect_success 'rebase --stat' ' |
a48fcd83 | 57 | git reset --hard start && |
d1c02d93 | 58 | git rebase --stat main >diffstat.txt && |
0f321f95 | 59 | grep "^ fileX | *1 +$" diffstat.txt |
a9c3821c TAV |
60 | ' |
61 | ||
62 | test_expect_success 'rebase w/config rebase.stat' ' | |
a48fcd83 | 63 | git reset --hard start && |
0f321f95 | 64 | git config rebase.stat true && |
d1c02d93 | 65 | git rebase main >diffstat.txt && |
0f321f95 | 66 | grep "^ fileX | *1 +$" diffstat.txt |
a9c3821c TAV |
67 | ' |
68 | ||
69 | test_expect_success 'rebase -n overrides config rebase.stat config' ' | |
a48fcd83 | 70 | git reset --hard start && |
0f321f95 | 71 | git config rebase.stat true && |
d1c02d93 | 72 | git rebase -n main >diffstat.txt && |
0f321f95 | 73 | ! grep "^ fileX | *1 +$" diffstat.txt |
a9c3821c TAV |
74 | ' |
75 | ||
9180feaf EFL |
76 | test_expect_success 'rebase --onto outputs the invalid ref' ' |
77 | test_must_fail git rebase --onto invalid-ref HEAD HEAD 2>err && | |
6789275d | 78 | test_grep "invalid-ref" err |
9180feaf EFL |
79 | ' |
80 | ||
04519d72 JS |
81 | test_expect_success 'error out early upon -C<n> or --whitespace=<bad>' ' |
82 | test_must_fail git rebase -Cnot-a-number HEAD 2>err && | |
6789275d | 83 | test_grep "numerical value" err && |
04519d72 | 84 | test_must_fail git rebase --whitespace=bad HEAD 2>err && |
6789275d | 85 | test_grep "Invalid whitespace option" err |
04519d72 JS |
86 | ' |
87 | ||
4e5e1b4b PW |
88 | write_reflog_expect () { |
89 | if test $mode = --apply | |
90 | then | |
be0d29d3 | 91 | sed 's/(continue)/(pick)/' |
4e5e1b4b PW |
92 | else |
93 | cat | |
94 | fi >expect | |
95 | } | |
96 | ||
97 | test_reflog () { | |
98 | mode=$1 | |
99 | reflog_action="$2" | |
100 | ||
101 | test_expect_success "rebase $mode reflog${reflog_action:+ GIT_REFLOG_ACTION=$reflog_action}" ' | |
102 | git checkout conflicts && | |
103 | test_when_finished "git reset --hard Q" && | |
104 | ||
105 | ( | |
106 | if test -n "$reflog_action" | |
107 | then | |
108 | GIT_REFLOG_ACTION="$reflog_action" && | |
109 | export GIT_REFLOG_ACTION | |
110 | fi && | |
da1d6336 PW |
111 | test_must_fail git rebase $mode main && |
112 | echo resolved >fileX && | |
113 | git add fileX && | |
114 | git rebase --continue | |
4e5e1b4b PW |
115 | ) && |
116 | ||
da1d6336 | 117 | git log -g --format=%gs -5 >actual && |
4e5e1b4b PW |
118 | write_reflog_expect <<-EOF && |
119 | ${reflog_action:-rebase} (finish): returning to refs/heads/conflicts | |
120 | ${reflog_action:-rebase} (pick): Q | |
da1d6336 | 121 | ${reflog_action:-rebase} (continue): conflict-X |
4e5e1b4b PW |
122 | ${reflog_action:-rebase} (pick): P |
123 | ${reflog_action:-rebase} (start): checkout main | |
13a5a9f0 JS |
124 | EOF |
125 | test_cmp expect actual && | |
126 | ||
4e5e1b4b PW |
127 | git log -g --format=%gs -1 conflicts >actual && |
128 | write_reflog_expect <<-EOF && | |
129 | ${reflog_action:-rebase} (finish): refs/heads/conflicts onto $(git rev-parse main) | |
13a5a9f0 | 130 | EOF |
4e5e1b4b | 131 | test_cmp expect actual && |
7700ab08 | 132 | |
4e5e1b4b PW |
133 | # check there is only one new entry in the branch reflog |
134 | test_cmp_rev conflicts@{1} Q | |
135 | ' | |
136 | ||
137 | test_expect_success "rebase $mode fast-forward reflog${reflog_action:+ GIT_REFLOG_ACTION=$reflog_action}" ' | |
138 | git checkout fast-forward && | |
139 | test_when_finished "git reset --hard X" && | |
140 | ||
141 | ( | |
142 | if test -n "$reflog_action" | |
143 | then | |
144 | GIT_REFLOG_ACTION="$reflog_action" && | |
145 | export GIT_REFLOG_ACTION | |
146 | fi && | |
147 | git rebase $mode main | |
148 | ) && | |
149 | ||
150 | git log -g --format=%gs -2 >actual && | |
151 | write_reflog_expect <<-EOF && | |
152 | ${reflog_action:-rebase} (finish): returning to refs/heads/fast-forward | |
153 | ${reflog_action:-rebase} (start): checkout main | |
7700ab08 PW |
154 | EOF |
155 | test_cmp expect actual && | |
156 | ||
4e5e1b4b PW |
157 | git log -g --format=%gs -1 fast-forward >actual && |
158 | write_reflog_expect <<-EOF && | |
159 | ${reflog_action:-rebase} (finish): refs/heads/fast-forward onto $(git rev-parse main) | |
7700ab08 | 160 | EOF |
4e5e1b4b PW |
161 | test_cmp expect actual && |
162 | ||
163 | # check there is only one new entry in the branch reflog | |
164 | test_cmp_rev fast-forward@{1} X | |
165 | ' | |
1f2d5dc4 PW |
166 | |
167 | test_expect_success "rebase $mode --skip reflog${reflog_action:+ GIT_REFLOG_ACTION=$reflog_action}" ' | |
168 | git checkout conflicts && | |
169 | test_when_finished "git reset --hard Q" && | |
170 | ||
171 | ( | |
172 | if test -n "$reflog_action" | |
173 | then | |
174 | GIT_REFLOG_ACTION="$reflog_action" && | |
175 | export GIT_REFLOG_ACTION | |
176 | fi && | |
177 | test_must_fail git rebase $mode main && | |
178 | git rebase --skip | |
179 | ) && | |
180 | ||
181 | git log -g --format=%gs -4 >actual && | |
182 | write_reflog_expect <<-EOF && | |
183 | ${reflog_action:-rebase} (finish): returning to refs/heads/conflicts | |
184 | ${reflog_action:-rebase} (pick): Q | |
185 | ${reflog_action:-rebase} (pick): P | |
186 | ${reflog_action:-rebase} (start): checkout main | |
187 | EOF | |
188 | test_cmp expect actual | |
189 | ' | |
6159e7ad PW |
190 | |
191 | test_expect_success "rebase $mode --abort reflog${reflog_action:+ GIT_REFLOG_ACTION=$reflog_action}" ' | |
192 | git checkout conflicts && | |
193 | test_when_finished "git reset --hard Q" && | |
194 | ||
195 | git log -g -1 conflicts >branch-expect && | |
196 | ( | |
197 | if test -n "$reflog_action" | |
198 | then | |
199 | GIT_REFLOG_ACTION="$reflog_action" && | |
200 | export GIT_REFLOG_ACTION | |
201 | fi && | |
202 | test_must_fail git rebase $mode main && | |
203 | git rebase --abort | |
204 | ) && | |
205 | ||
206 | git log -g --format=%gs -3 >actual && | |
207 | write_reflog_expect <<-EOF && | |
208 | ${reflog_action:-rebase} (abort): returning to refs/heads/conflicts | |
209 | ${reflog_action:-rebase} (pick): P | |
210 | ${reflog_action:-rebase} (start): checkout main | |
211 | EOF | |
212 | test_cmp expect actual && | |
213 | ||
214 | # check branch reflog is unchanged | |
215 | git log -g -1 conflicts >branch-actual && | |
216 | test_cmp branch-expect branch-actual | |
217 | ' | |
218 | ||
219 | test_expect_success "rebase $mode --abort detached HEAD reflog${reflog_action:+ GIT_REFLOG_ACTION=$reflog_action}" ' | |
220 | git checkout Q && | |
221 | test_when_finished "git reset --hard Q" && | |
222 | ||
223 | ( | |
224 | if test -n "$reflog_action" | |
225 | then | |
226 | GIT_REFLOG_ACTION="$reflog_action" && | |
227 | export GIT_REFLOG_ACTION | |
228 | fi && | |
229 | test_must_fail git rebase $mode main && | |
230 | git rebase --abort | |
231 | ) && | |
232 | ||
233 | git log -g --format=%gs -3 >actual && | |
234 | write_reflog_expect <<-EOF && | |
235 | ${reflog_action:-rebase} (abort): returning to $(git rev-parse Q) | |
236 | ${reflog_action:-rebase} (pick): P | |
237 | ${reflog_action:-rebase} (start): checkout main | |
238 | EOF | |
239 | test_cmp expect actual | |
240 | ' | |
4e5e1b4b PW |
241 | } |
242 | ||
243 | test_reflog --merge | |
244 | test_reflog --merge my-reflog-action | |
245 | test_reflog --apply | |
246 | test_reflog --apply my-reflog-action | |
7700ab08 | 247 | |
8797f0f0 JS |
248 | test_expect_success 'rebase -i onto unrelated history' ' |
249 | git init unrelated && | |
250 | test_commit -C unrelated 1 && | |
251 | git -C unrelated remote add -f origin "$PWD" && | |
d1c02d93 | 252 | git -C unrelated branch --set-upstream-to=origin/main && |
8797f0f0 | 253 | git -C unrelated -c core.editor=true rebase -i -v --stat >actual && |
6789275d JH |
254 | test_grep "Changes to " actual && |
255 | test_grep "5 files changed" actual | |
8797f0f0 JS |
256 | ' |
257 | ||
7afa845e | 258 | test_done |