Merge branch 'cl/config-regexp-docfix' into maint-2.46
[git/gitster.git] / t / t3406-rebase-message.sh
blob82108b67e67c18230c385dfef03f7bdee37f9eb2
1 #!/bin/sh
3 test_description='messages from rebase operation'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
8 TEST_PASSES_SANITIZE_LEAK=true
9 . ./test-lib.sh
11 test_expect_success 'setup' '
12 test_commit O fileO &&
13 test_commit X fileX &&
14 git branch fast-forward &&
15 test_commit A fileA &&
16 test_commit B fileB &&
17 test_commit Y fileY &&
19 git checkout -b conflicts O &&
20 test_commit P &&
21 test_commit conflict-X fileX &&
22 test_commit Q &&
24 git checkout -b topic O &&
25 git cherry-pick A B &&
26 test_commit Z fileZ &&
27 git tag start
30 test_expect_success 'rebase -m' '
31 git rebase -m main >actual &&
32 test_must_be_empty actual
35 test_expect_success 'rebase against main twice' '
36 git rebase --apply main >out &&
37 test_grep "Current branch topic is up to date" out
40 test_expect_success 'rebase against main twice with --force' '
41 git rebase --force-rebase --apply main >out &&
42 test_grep "Current branch topic is up to date, rebase forced" out
45 test_expect_success 'rebase against main twice from another branch' '
46 git checkout topic^ &&
47 git rebase --apply main topic >out &&
48 test_grep "Current branch topic is up to date" out
51 test_expect_success 'rebase fast-forward to main' '
52 git checkout topic^ &&
53 git rebase --apply topic >out &&
54 test_grep "Fast-forwarded HEAD to topic" out
57 test_expect_success 'rebase --stat' '
58 git reset --hard start &&
59 git rebase --stat main >diffstat.txt &&
60 grep "^ fileX | *1 +$" diffstat.txt
63 test_expect_success 'rebase w/config rebase.stat' '
64 git reset --hard start &&
65 git config rebase.stat true &&
66 git rebase main >diffstat.txt &&
67 grep "^ fileX | *1 +$" diffstat.txt
70 test_expect_success 'rebase -n overrides config rebase.stat config' '
71 git reset --hard start &&
72 git config rebase.stat true &&
73 git rebase -n main >diffstat.txt &&
74 ! grep "^ fileX | *1 +$" diffstat.txt
77 test_expect_success 'rebase --onto outputs the invalid ref' '
78 test_must_fail git rebase --onto invalid-ref HEAD HEAD 2>err &&
79 test_grep "invalid-ref" err
82 test_expect_success 'error out early upon -C<n> or --whitespace=<bad>' '
83 test_must_fail git rebase -Cnot-a-number HEAD 2>err &&
84 test_grep "numerical value" err &&
85 test_must_fail git rebase --whitespace=bad HEAD 2>err &&
86 test_grep "Invalid whitespace option" err
89 write_reflog_expect () {
90 if test $mode = --apply
91 then
92 sed 's/(continue)/(pick)/'
93 else
94 cat
95 fi >expect
98 test_reflog () {
99 mode=$1
100 reflog_action="$2"
102 test_expect_success "rebase $mode reflog${reflog_action:+ GIT_REFLOG_ACTION=$reflog_action}" '
103 git checkout conflicts &&
104 test_when_finished "git reset --hard Q" &&
107 if test -n "$reflog_action"
108 then
109 GIT_REFLOG_ACTION="$reflog_action" &&
110 export GIT_REFLOG_ACTION
111 fi &&
112 test_must_fail git rebase $mode main &&
113 echo resolved >fileX &&
114 git add fileX &&
115 git rebase --continue
116 ) &&
118 git log -g --format=%gs -5 >actual &&
119 write_reflog_expect <<-EOF &&
120 ${reflog_action:-rebase} (finish): returning to refs/heads/conflicts
121 ${reflog_action:-rebase} (pick): Q
122 ${reflog_action:-rebase} (continue): conflict-X
123 ${reflog_action:-rebase} (pick): P
124 ${reflog_action:-rebase} (start): checkout main
126 test_cmp expect actual &&
128 git log -g --format=%gs -1 conflicts >actual &&
129 write_reflog_expect <<-EOF &&
130 ${reflog_action:-rebase} (finish): refs/heads/conflicts onto $(git rev-parse main)
132 test_cmp expect actual &&
134 # check there is only one new entry in the branch reflog
135 test_cmp_rev conflicts@{1} Q
138 test_expect_success "rebase $mode fast-forward reflog${reflog_action:+ GIT_REFLOG_ACTION=$reflog_action}" '
139 git checkout fast-forward &&
140 test_when_finished "git reset --hard X" &&
143 if test -n "$reflog_action"
144 then
145 GIT_REFLOG_ACTION="$reflog_action" &&
146 export GIT_REFLOG_ACTION
147 fi &&
148 git rebase $mode main
149 ) &&
151 git log -g --format=%gs -2 >actual &&
152 write_reflog_expect <<-EOF &&
153 ${reflog_action:-rebase} (finish): returning to refs/heads/fast-forward
154 ${reflog_action:-rebase} (start): checkout main
156 test_cmp expect actual &&
158 git log -g --format=%gs -1 fast-forward >actual &&
159 write_reflog_expect <<-EOF &&
160 ${reflog_action:-rebase} (finish): refs/heads/fast-forward onto $(git rev-parse main)
162 test_cmp expect actual &&
164 # check there is only one new entry in the branch reflog
165 test_cmp_rev fast-forward@{1} X
168 test_expect_success "rebase $mode --skip reflog${reflog_action:+ GIT_REFLOG_ACTION=$reflog_action}" '
169 git checkout conflicts &&
170 test_when_finished "git reset --hard Q" &&
173 if test -n "$reflog_action"
174 then
175 GIT_REFLOG_ACTION="$reflog_action" &&
176 export GIT_REFLOG_ACTION
177 fi &&
178 test_must_fail git rebase $mode main &&
179 git rebase --skip
180 ) &&
182 git log -g --format=%gs -4 >actual &&
183 write_reflog_expect <<-EOF &&
184 ${reflog_action:-rebase} (finish): returning to refs/heads/conflicts
185 ${reflog_action:-rebase} (pick): Q
186 ${reflog_action:-rebase} (pick): P
187 ${reflog_action:-rebase} (start): checkout main
189 test_cmp expect actual
192 test_expect_success "rebase $mode --abort reflog${reflog_action:+ GIT_REFLOG_ACTION=$reflog_action}" '
193 git checkout conflicts &&
194 test_when_finished "git reset --hard Q" &&
196 git log -g -1 conflicts >branch-expect &&
198 if test -n "$reflog_action"
199 then
200 GIT_REFLOG_ACTION="$reflog_action" &&
201 export GIT_REFLOG_ACTION
202 fi &&
203 test_must_fail git rebase $mode main &&
204 git rebase --abort
205 ) &&
207 git log -g --format=%gs -3 >actual &&
208 write_reflog_expect <<-EOF &&
209 ${reflog_action:-rebase} (abort): returning to refs/heads/conflicts
210 ${reflog_action:-rebase} (pick): P
211 ${reflog_action:-rebase} (start): checkout main
213 test_cmp expect actual &&
215 # check branch reflog is unchanged
216 git log -g -1 conflicts >branch-actual &&
217 test_cmp branch-expect branch-actual
220 test_expect_success "rebase $mode --abort detached HEAD reflog${reflog_action:+ GIT_REFLOG_ACTION=$reflog_action}" '
221 git checkout Q &&
222 test_when_finished "git reset --hard Q" &&
225 if test -n "$reflog_action"
226 then
227 GIT_REFLOG_ACTION="$reflog_action" &&
228 export GIT_REFLOG_ACTION
229 fi &&
230 test_must_fail git rebase $mode main &&
231 git rebase --abort
232 ) &&
234 git log -g --format=%gs -3 >actual &&
235 write_reflog_expect <<-EOF &&
236 ${reflog_action:-rebase} (abort): returning to $(git rev-parse Q)
237 ${reflog_action:-rebase} (pick): P
238 ${reflog_action:-rebase} (start): checkout main
240 test_cmp expect actual
244 test_reflog --merge
245 test_reflog --merge my-reflog-action
246 test_reflog --apply
247 test_reflog --apply my-reflog-action
249 test_expect_success 'rebase -i onto unrelated history' '
250 git init unrelated &&
251 test_commit -C unrelated 1 &&
252 git -C unrelated remote add -f origin "$PWD" &&
253 git -C unrelated branch --set-upstream-to=origin/main &&
254 git -C unrelated -c core.editor=true rebase -i -v --stat >actual &&
255 test_grep "Changes to " actual &&
256 test_grep "5 files changed" actual
259 test_done