3 test_description
='messages from rebase operation'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
10 test_expect_success
'setup' '
11 test_commit O fileO &&
12 test_commit X fileX &&
13 git branch fast-forward &&
14 test_commit A fileA &&
15 test_commit B fileB &&
16 test_commit Y fileY &&
18 git checkout -b conflicts O &&
20 test_commit conflict-X fileX &&
23 git checkout -b topic O &&
24 git cherry-pick A B &&
25 test_commit Z fileZ &&
29 test_expect_success
'rebase -m' '
30 git rebase -m main >actual &&
31 test_must_be_empty actual
34 test_expect_success
'rebase against main twice' '
35 git rebase --apply main >out &&
36 test_grep "Current branch topic is up to date" out
39 test_expect_success
'rebase against main twice with --force' '
40 git rebase --force-rebase --apply main >out &&
41 test_grep "Current branch topic is up to date, rebase forced" out
44 test_expect_success
'rebase against main twice from another branch' '
45 git checkout topic^ &&
46 git rebase --apply main topic >out &&
47 test_grep "Current branch topic is up to date" out
50 test_expect_success
'rebase fast-forward to main' '
51 git checkout topic^ &&
52 git rebase --apply topic >out &&
53 test_grep "Fast-forwarded HEAD to topic" out
56 test_expect_success
'rebase --stat' '
57 git reset --hard start &&
58 git rebase --stat main >diffstat.txt &&
59 grep "^ fileX | *1 +$" diffstat.txt
62 test_expect_success
'rebase w/config rebase.stat' '
63 git reset --hard start &&
64 git config rebase.stat true &&
65 git rebase main >diffstat.txt &&
66 grep "^ fileX | *1 +$" diffstat.txt
69 test_expect_success
'rebase -n overrides config rebase.stat config' '
70 git reset --hard start &&
71 git config rebase.stat true &&
72 git rebase -n main >diffstat.txt &&
73 ! grep "^ fileX | *1 +$" diffstat.txt
76 test_expect_success
'rebase --onto outputs the invalid ref' '
77 test_must_fail git rebase --onto invalid-ref HEAD HEAD 2>err &&
78 test_grep "invalid-ref" err
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 &&
83 test_grep "numerical value" err &&
84 test_must_fail git rebase --whitespace=bad HEAD 2>err &&
85 test_grep "Invalid whitespace option" err
88 write_reflog_expect
() {
89 if test $mode = --apply
91 sed 's/(continue)/(pick)/'
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" &&
106 if test -n "$reflog_action"
108 GIT_REFLOG_ACTION="$reflog_action" &&
109 export GIT_REFLOG_ACTION
111 test_must_fail git rebase $mode main &&
112 echo resolved >fileX &&
114 git rebase --continue
117 git log -g --format=%gs -5 >actual &&
118 write_reflog_expect <<-EOF &&
119 ${reflog_action:-rebase} (finish): returning to refs/heads/conflicts
120 ${reflog_action:-rebase} (pick): Q
121 ${reflog_action:-rebase} (continue): conflict-X
122 ${reflog_action:-rebase} (pick): P
123 ${reflog_action:-rebase} (start): checkout main
125 test_cmp expect actual &&
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)
131 test_cmp expect actual &&
133 # check there is only one new entry in the branch reflog
134 test_cmp_rev conflicts@{1} Q
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" &&
142 if test -n "$reflog_action"
144 GIT_REFLOG_ACTION="$reflog_action" &&
145 export GIT_REFLOG_ACTION
147 git rebase $mode main
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
155 test_cmp expect actual &&
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)
161 test_cmp expect actual &&
163 # check there is only one new entry in the branch reflog
164 test_cmp_rev fast-forward@{1} X
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" &&
172 if test -n "$reflog_action"
174 GIT_REFLOG_ACTION="$reflog_action" &&
175 export GIT_REFLOG_ACTION
177 test_must_fail git rebase $mode main &&
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
188 test_cmp expect actual
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" &&
195 git log -g -1 conflicts >branch-expect &&
197 if test -n "$reflog_action"
199 GIT_REFLOG_ACTION="$reflog_action" &&
200 export GIT_REFLOG_ACTION
202 test_must_fail git rebase $mode main &&
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
212 test_cmp expect actual &&
214 # check branch reflog is unchanged
215 git log -g -1 conflicts >branch-actual &&
216 test_cmp branch-expect branch-actual
219 test_expect_success
"rebase $mode --abort detached HEAD reflog${reflog_action:+ GIT_REFLOG_ACTION=$reflog_action}" '
221 test_when_finished "git reset --hard Q" &&
224 if test -n "$reflog_action"
226 GIT_REFLOG_ACTION="$reflog_action" &&
227 export GIT_REFLOG_ACTION
229 test_must_fail git rebase $mode main &&
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
239 test_cmp expect actual
244 test_reflog
--merge my-reflog-action
246 test_reflog
--apply my-reflog-action
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" &&
252 git -C unrelated branch --set-upstream-to=origin/main &&
253 git -C unrelated -c core.editor=true rebase -i -v --stat >actual &&
254 test_grep "Changes to " actual &&
255 test_grep "5 files changed" actual