@@ -9,7 +9,9 @@ This test checks the "fixup [-C|-c]" command of rebase interactive.
9
9
In addition to amending the contents of the commit, "fixup -C"
10
10
replaces the original commit message with the message of the fixup
11
11
commit. "fixup -c" also replaces the original message, but opens the
12
- editor to allow the user to edit the message before committing.
12
+ editor to allow the user to edit the message before committing. Similar
13
+ to the "fixup" command that works with "fixup!", "fixup -C" works with
14
+ "amend!" upon --autosquash.
13
15
'
14
16
15
17
. ./test-lib.sh
@@ -18,35 +20,35 @@ editor to allow the user to edit the message before committing.
18
20
19
21
EMPTY=" "
20
22
23
+ # test_commit_message <rev> -m <msg>
24
+ # test_commit_message <rev> <path>
25
+ # Verify that the commit message of <rev> matches
26
+ # <msg> or the content of <path>.
21
27
test_commit_message () {
22
- rev=" $1 " && # commit or tag we want to test
23
- file=" $2 " && # test against the content of a file
24
- git show --no-patch --pretty=format:%B " $rev " > actual-message &&
25
- if test " $2 " = -m
26
- then
27
- str=" $3 " && # test against a string
28
- printf " %s\n" " $str " > tmp-expected-message &&
29
- file=" tmp-expected-message"
30
- fi
31
- test_cmp " $file " actual-message
28
+ git show --no-patch --pretty=format:%B " $1 " > actual &&
29
+ case " $2 " in
30
+ -m)
31
+ echo " $3 " > expect &&
32
+ test_cmp expect actual ;;
33
+ * )
34
+ test_cmp " $2 " actual ;;
35
+ esac
32
36
}
33
37
34
38
get_author () {
35
39
rev=" $1 " &&
36
- git log -1 --pretty=format:" %an %ae" " $rev "
40
+ git log -1 --pretty=format:" %an %ae %at " " $rev "
37
41
}
38
42
39
43
test_expect_success ' setup' '
40
44
cat >message <<-EOF &&
41
- amend! B
42
- ${EMPTY}
43
- new subject
44
- ${EMPTY}
45
- new
46
- body
47
- EOF
48
-
49
- sed "1,2d" message >expected-message &&
45
+ amend! B
46
+ $EMPTY
47
+ new subject
48
+ $EMPTY
49
+ new
50
+ body
51
+ EOF
50
52
51
53
test_commit A A &&
52
54
test_commit B B &&
@@ -68,40 +70,43 @@ test_expect_success 'setup' '
68
70
echo B1 >B &&
69
71
test_tick &&
70
72
git commit --fixup=HEAD -a &&
73
+ git tag B1 &&
71
74
test_tick &&
72
75
git commit --allow-empty -F - <<-EOF &&
73
- amend! B
74
- ${ EMPTY}
75
- B
76
- ${ EMPTY}
77
- edited 1
78
- EOF
76
+ amend! B
77
+ $ EMPTY
78
+ B
79
+ $ EMPTY
80
+ edited 1
81
+ EOF
79
82
test_tick &&
80
83
git commit --allow-empty -F - <<-EOF &&
81
- amend! amend! B
82
- ${ EMPTY}
83
- B
84
- ${ EMPTY}
85
- edited 1
86
- ${ EMPTY}
87
- edited 2
88
- EOF
84
+ amend! amend! B
85
+ $ EMPTY
86
+ B
87
+ $ EMPTY
88
+ edited 1
89
+ $ EMPTY
90
+ edited 2
91
+ EOF
89
92
echo B2 >B &&
90
93
test_tick &&
91
94
FAKE_COMMIT_AMEND="edited squash" git commit --squash=HEAD -a &&
95
+ git tag B2 &&
92
96
echo B3 >B &&
93
97
test_tick &&
94
98
git commit -a -F - <<-EOF &&
95
- amend! amend! amend! B
96
- ${EMPTY}
97
- B
98
- ${EMPTY}
99
- edited 1
100
- ${EMPTY}
101
- edited 2
102
- ${EMPTY}
103
- edited 3
104
- EOF
99
+ amend! amend! amend! B
100
+ $EMPTY
101
+ B
102
+ $EMPTY
103
+ edited 1
104
+ $EMPTY
105
+ edited 2
106
+ $EMPTY
107
+ edited 3
108
+ EOF
109
+ git tag B3 &&
105
110
106
111
GIT_AUTHOR_NAME="Rebase Author" &&
107
112
GIT_AUTHOR_EMAIL="[email protected] " &&
@@ -134,6 +139,7 @@ test_expect_success 'simple fixup -c works' '
134
139
test_expect_success ' fixup -C removes amend! from message' '
135
140
test_when_finished "test_might_fail git rebase --abort" &&
136
141
git checkout --detach A1 &&
142
+ git log -1 --pretty=format:%b >expected-message &&
137
143
FAKE_LINES="1 fixup_-C 2" git rebase -i A &&
138
144
test_cmp_rev HEAD^ A &&
139
145
test_cmp_rev HEAD^{tree} A1^{tree} &&
@@ -145,13 +151,14 @@ test_expect_success 'fixup -C removes amend! from message' '
145
151
test_expect_success ' fixup -C with conflicts gives correct message' '
146
152
test_when_finished "test_might_fail git rebase --abort" &&
147
153
git checkout --detach A1 &&
154
+ git log -1 --pretty=format:%b >expected-message &&
155
+ test_write_lines "" "edited" >>expected-message &&
148
156
test_must_fail env FAKE_LINES="1 fixup_-C 2" git rebase -i conflicts &&
149
157
git checkout --theirs -- A &&
150
158
git add A &&
151
159
FAKE_COMMIT_AMEND=edited git rebase --continue &&
152
160
test_cmp_rev HEAD^ conflicts &&
153
161
test_cmp_rev HEAD^{tree} A1^{tree} &&
154
- test_write_lines "" edited >>expected-message &&
155
162
test_commit_message HEAD expected-message &&
156
163
get_author HEAD >actual-author &&
157
164
test_cmp expected-author actual-author
@@ -167,20 +174,20 @@ test_expect_success 'skipping fixup -C after fixup gives correct message' '
167
174
'
168
175
169
176
test_expect_success ' sequence of fixup, fixup -C & squash --signoff works' '
170
- git checkout --detach branch &&
177
+ git checkout --detach B3 &&
171
178
FAKE_LINES="1 fixup 2 fixup_-C 3 fixup_-C 4 squash 5 fixup_-C 6" \
172
179
FAKE_COMMIT_AMEND=squashed \
173
180
FAKE_MESSAGE_COPY=actual-squash-message \
174
181
git -c commit.status=false rebase -ik --signoff A &&
175
- git diff-tree --exit-code --patch HEAD branch -- &&
182
+ git diff-tree --exit-code --patch HEAD B3 -- &&
176
183
test_cmp_rev HEAD^ A &&
177
184
test_i18ncmp "$TEST_DIRECTORY/t3437/expected-squash-message" \
178
185
actual-squash-message
179
186
'
180
187
181
188
test_expect_success ' first fixup -C commented out in sequence fixup fixup -C fixup -C' '
182
189
test_when_finished "test_might_fail git rebase --abort" &&
183
- git checkout branch && git checkout --detach branch~2 &&
190
+ git checkout --detach B2~ &&
184
191
git log -1 --pretty=format:%b >expected-message &&
185
192
FAKE_LINES="1 fixup 2 fixup_-C 3 fixup_-C 4" git rebase -i A &&
186
193
test_cmp_rev HEAD^ A &&
@@ -190,13 +197,16 @@ test_expect_success 'first fixup -C commented out in sequence fixup fixup -C fix
190
197
test_expect_success ' multiple fixup -c opens editor once' '
191
198
test_when_finished "test_might_fail git rebase --abort" &&
192
199
git checkout --detach A3 &&
193
- base=$(git rev-parse HEAD~4) &&
194
- FAKE_COMMIT_MESSAGE="Modified-A3" \
200
+ git log -1 --pretty=format:%B >expected-message &&
201
+ test_write_lines "" "Modified-A3" >>expected-message &&
202
+ FAKE_COMMIT_AMEND="Modified-A3" \
195
203
FAKE_LINES="1 fixup_-C 2 fixup_-c 3 fixup_-c 4" \
196
204
EXPECT_HEADER_COUNT=4 \
197
- git rebase -i $base &&
198
- test_cmp_rev $base HEAD^ &&
199
- test 1 = $(git show | grep Modified-A3 | wc -l)
205
+ git rebase -i A &&
206
+ test_cmp_rev HEAD^ A &&
207
+ get_author HEAD >actual-author &&
208
+ test_cmp expected-author actual-author &&
209
+ test_commit_message HEAD expected-message
200
210
'
201
211
202
212
test_expect_success ' sequence squash, fixup & fixup -c gives combined message' '
@@ -211,12 +221,12 @@ test_expect_success 'sequence squash, fixup & fixup -c gives combined message' '
211
221
'
212
222
213
223
test_expect_success ' fixup -C works upon --autosquash with amend!' '
214
- git checkout --detach branch &&
224
+ git checkout --detach B3 &&
215
225
FAKE_COMMIT_AMEND=squashed \
216
226
FAKE_MESSAGE_COPY=actual-squash-message \
217
227
git -c commit.status=false rebase -ik --autosquash \
218
228
--signoff A &&
219
- git diff-tree --exit-code --patch HEAD branch -- &&
229
+ git diff-tree --exit-code --patch HEAD B3 -- &&
220
230
test_cmp_rev HEAD^ A &&
221
231
test_i18ncmp "$TEST_DIRECTORY/t3437/expected-squash-message" \
222
232
actual-squash-message
0 commit comments