t3406: rework rebase reflog tests

Refactor the tests in preparation for adding more tests in the next few commits. The reworked tests use the same function for testing both the "merge" and "apply" backends. The test coverage for the "apply" backend now includes setting GIT_REFLOG_ACTION. Note that rebasing the "conflicts" branch does not create any conflicts yet. A commit to do that will be added in the next commit and the diff ends up smaller if we have don't rename the branch when it is added. Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Phillip Wood committed Oct 12, 2022 at 09:35 UTC 4e5e1b4b616f0354218ff2e2ff3c71e4c730bbe1
1 file changed +76 -39
t/t3406-rebase-message.sh
+76 -39
@@ -10,10 +10,15 @@ 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 &&
17
18 + git checkout -b conflicts O &&
19 + test_commit P &&
20 + test_commit Q &&
21 +
22 git checkout -b topic O &&
23 git cherry-pick A B &&
24 test_commit Z fileZ &&
@@ -79,54 +84,86 @@ test_expect_success 'error out early upon -C<n> or --whitespace=<bad>' '
84 test_i18ngrep "Invalid whitespace option" err
85 '
86
82 -test_expect_success 'GIT_REFLOG_ACTION' '
83 - git checkout start &&
84 - test_commit reflog-onto &&
85 - git checkout -b reflog-topic start &&
86 - test_commit reflog-to-rebase &&
87 -
88 - git rebase reflog-onto &&
89 - git log -g --format=%gs -3 >actual &&
90 - cat >expect <<-\EOF &&
91 - rebase (finish): returning to refs/heads/reflog-topic
92 - rebase (pick): reflog-to-rebase
93 - rebase (start): checkout reflog-onto
87 +write_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 +
96 +test_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
119 EOF
120 test_cmp expect actual &&
121
97 - git checkout -b reflog-prefix reflog-to-rebase &&
98 - GIT_REFLOG_ACTION=change-the-reflog git rebase reflog-onto &&
99 - git log -g --format=%gs -3 >actual &&
100 - cat >expect <<-\EOF &&
101 - change-the-reflog (finish): returning to refs/heads/reflog-prefix
102 - change-the-reflog (pick): reflog-to-rebase
103 - change-the-reflog (start): checkout reflog-onto
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)
125 EOF
105 - test_cmp expect actual
106 -'
107 -
108 -test_expect_success 'rebase --apply reflog' '
109 - git checkout -b reflog-apply start &&
110 - old_head_reflog="$(git log -g --format=%gs -1 HEAD)" &&
111 -
112 - git rebase --apply Y &&
126 + test_cmp expect actual &&
127
114 - git log -g --format=%gs -4 HEAD >actual &&
115 - cat >expect <<-EOF &&
116 - rebase finished: returning to refs/heads/reflog-apply
117 - rebase: Z
118 - rebase: checkout Y
119 - $old_head_reflog
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
149 EOF
150 test_cmp expect actual &&
151
123 - git log -g --format=%gs -2 reflog-apply >actual &&
124 - cat >expect <<-EOF &&
125 - rebase finished: refs/heads/reflog-apply onto $(git rev-parse Y)
126 - branch: Created from start
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)
155 EOF
128 - test_cmp expect actual
129 -'
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 +
163 +test_reflog --merge
164 +test_reflog --merge my-reflog-action
165 +test_reflog --apply
166 +test_reflog --apply my-reflog-action
167
168 test_expect_success 'rebase -i onto unrelated history' '
169 git init unrelated &&