]> git.ipfire.org Git - thirdparty/git.git/blame - t/t3406-rebase-message.sh
t3406: rework rebase reflog tests
[thirdparty/git.git] / t / t3406-rebase-message.sh
CommitLineData
7afa845e
JS
1#!/bin/sh
2
3test_description='messages from rebase operation'
4
d1c02d93 5GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
334afbc7
JS
6export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
7afa845e
JS
8. ./test-lib.sh
9
9e2248ef
MZ
10test_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 &&
20 test_commit Q &&
21
9e2248ef
MZ
22 git checkout -b topic O &&
23 git cherry-pick A B &&
24 test_commit Z fileZ &&
a9c3821c 25 git tag start
7afa845e
JS
26'
27
7afa845e 28test_expect_success 'rebase -m' '
d1c02d93 29 git rebase -m main >actual &&
7db00f0b 30 test_must_be_empty actual
7afa845e
JS
31'
32
d1c02d93
JS
33test_expect_success 'rebase against main twice' '
34 git rebase --apply main >out &&
c9581cc8
MZ
35 test_i18ngrep "Current branch topic is up to date" out
36'
37
d1c02d93
JS
38test_expect_success 'rebase against main twice with --force' '
39 git rebase --force-rebase --apply main >out &&
c9581cc8
MZ
40 test_i18ngrep "Current branch topic is up to date, rebase forced" out
41'
42
d1c02d93 43test_expect_success 'rebase against main twice from another branch' '
c9581cc8 44 git checkout topic^ &&
d1c02d93 45 git rebase --apply main topic >out &&
c9581cc8
MZ
46 test_i18ngrep "Current branch topic is up to date" out
47'
48
d1c02d93 49test_expect_success 'rebase fast-forward to main' '
c9581cc8 50 git checkout topic^ &&
10cdb9f3 51 git rebase --apply topic >out &&
c9581cc8
MZ
52 test_i18ngrep "Fast-forwarded HEAD to topic" out
53'
54
a9c3821c 55test_expect_success 'rebase --stat' '
a48fcd83 56 git reset --hard start &&
d1c02d93 57 git rebase --stat main >diffstat.txt &&
0f321f95 58 grep "^ fileX | *1 +$" diffstat.txt
a9c3821c
TAV
59'
60
61test_expect_success 'rebase w/config rebase.stat' '
a48fcd83 62 git reset --hard start &&
0f321f95 63 git config rebase.stat true &&
d1c02d93 64 git rebase main >diffstat.txt &&
0f321f95 65 grep "^ fileX | *1 +$" diffstat.txt
a9c3821c
TAV
66'
67
68test_expect_success 'rebase -n overrides config rebase.stat config' '
a48fcd83 69 git reset --hard start &&
0f321f95 70 git config rebase.stat true &&
d1c02d93 71 git rebase -n main >diffstat.txt &&
0f321f95 72 ! grep "^ fileX | *1 +$" diffstat.txt
a9c3821c
TAV
73'
74
9180feaf
EFL
75test_expect_success 'rebase --onto outputs the invalid ref' '
76 test_must_fail git rebase --onto invalid-ref HEAD HEAD 2>err &&
c7108bf9 77 test_i18ngrep "invalid-ref" err
9180feaf
EFL
78'
79
04519d72
JS
80test_expect_success 'error out early upon -C<n> or --whitespace=<bad>' '
81 test_must_fail git rebase -Cnot-a-number HEAD 2>err &&
82 test_i18ngrep "numerical value" err &&
83 test_must_fail git rebase --whitespace=bad HEAD 2>err &&
84 test_i18ngrep "Invalid whitespace option" err
85'
86
4e5e1b4b
PW
87write_reflog_expect () {
88 if test $mode = --apply
89 then
90 sed 's/.*(finish)/rebase finished/; s/ ([^)]*)//'
91 else
92 cat
93 fi >expect
94}
95
96test_reflog () {
97 mode=$1
98 reflog_action="$2"
99
100 test_expect_success "rebase $mode reflog${reflog_action:+ GIT_REFLOG_ACTION=$reflog_action}" '
101 git checkout conflicts &&
102 test_when_finished "git reset --hard Q" &&
103
104 (
105 if test -n "$reflog_action"
106 then
107 GIT_REFLOG_ACTION="$reflog_action" &&
108 export GIT_REFLOG_ACTION
109 fi &&
110 git rebase $mode main
111 ) &&
112
113 git log -g --format=%gs -4 >actual &&
114 write_reflog_expect <<-EOF &&
115 ${reflog_action:-rebase} (finish): returning to refs/heads/conflicts
116 ${reflog_action:-rebase} (pick): Q
117 ${reflog_action:-rebase} (pick): P
118 ${reflog_action:-rebase} (start): checkout main
13a5a9f0
JS
119 EOF
120 test_cmp expect actual &&
121
4e5e1b4b
PW
122 git log -g --format=%gs -1 conflicts >actual &&
123 write_reflog_expect <<-EOF &&
124 ${reflog_action:-rebase} (finish): refs/heads/conflicts onto $(git rev-parse main)
13a5a9f0 125 EOF
4e5e1b4b 126 test_cmp expect actual &&
7700ab08 127
4e5e1b4b
PW
128 # check there is only one new entry in the branch reflog
129 test_cmp_rev conflicts@{1} Q
130 '
131
132 test_expect_success "rebase $mode fast-forward reflog${reflog_action:+ GIT_REFLOG_ACTION=$reflog_action}" '
133 git checkout fast-forward &&
134 test_when_finished "git reset --hard X" &&
135
136 (
137 if test -n "$reflog_action"
138 then
139 GIT_REFLOG_ACTION="$reflog_action" &&
140 export GIT_REFLOG_ACTION
141 fi &&
142 git rebase $mode main
143 ) &&
144
145 git log -g --format=%gs -2 >actual &&
146 write_reflog_expect <<-EOF &&
147 ${reflog_action:-rebase} (finish): returning to refs/heads/fast-forward
148 ${reflog_action:-rebase} (start): checkout main
7700ab08
PW
149 EOF
150 test_cmp expect actual &&
151
4e5e1b4b
PW
152 git log -g --format=%gs -1 fast-forward >actual &&
153 write_reflog_expect <<-EOF &&
154 ${reflog_action:-rebase} (finish): refs/heads/fast-forward onto $(git rev-parse main)
7700ab08 155 EOF
4e5e1b4b
PW
156 test_cmp expect actual &&
157
158 # check there is only one new entry in the branch reflog
159 test_cmp_rev fast-forward@{1} X
160 '
161}
162
163test_reflog --merge
164test_reflog --merge my-reflog-action
165test_reflog --apply
166test_reflog --apply my-reflog-action
7700ab08 167
8797f0f0
JS
168test_expect_success 'rebase -i onto unrelated history' '
169 git init unrelated &&
170 test_commit -C unrelated 1 &&
171 git -C unrelated remote add -f origin "$PWD" &&
d1c02d93 172 git -C unrelated branch --set-upstream-to=origin/main &&
8797f0f0
JS
173 git -C unrelated -c core.editor=true rebase -i -v --stat >actual &&
174 test_i18ngrep "Changes to " actual &&
175 test_i18ngrep "5 files changed" actual
176'
177
7afa845e 178test_done