Skip to content

Commit 7cdb968

Browse files
phillipwoodgitster
authored andcommitted
rebase -i: comment out squash!/fixup! subjects from squash message
When squashing commit messages the squash!/fixup! subjects are not of interest so comment them out to stop them becoming part of the final message. This change breaks a bunch of --autosquash tests which rely on the "squash! <subject>" line appearing in the final commit message. This is addressed by adding a second line to the commit message of the "squash! ..." commits and testing for that. Signed-off-by: Phillip Wood <[email protected]> Reviewed-by: Taylor Blau <[email protected]> Signed-off-by: Charvi Mendiratta <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 498bb5b commit 7cdb968

File tree

3 files changed

+36
-19
lines changed

3 files changed

+36
-19
lines changed

sequencer.c

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1718,15 +1718,34 @@ static int is_pick_or_similar(enum todo_command command)
17181718
}
17191719
}
17201720

1721+
static size_t subject_length(const char *body)
1722+
{
1723+
const char *p = body;
1724+
while (*p) {
1725+
const char *next = skip_blank_lines(p);
1726+
if (next != p)
1727+
break;
1728+
p = strchrnul(p, '\n');
1729+
if (*p)
1730+
p++;
1731+
}
1732+
return p - body;
1733+
}
1734+
17211735
static void append_squash_message(struct strbuf *buf, const char *body,
17221736
struct replay_opts *opts)
17231737
{
1738+
size_t commented_len = 0;
1739+
17241740
unlink(rebase_path_fixup_msg());
1741+
if (starts_with(body, "squash!") || starts_with(body, "fixup!"))
1742+
commented_len = subject_length(body);
17251743
strbuf_addf(buf, "\n%c ", comment_line_char);
17261744
strbuf_addf(buf, _("This is the commit message #%d:"),
17271745
++opts->current_fixup_count + 1);
17281746
strbuf_addstr(buf, "\n\n");
1729-
strbuf_addstr(buf, body);
1747+
strbuf_add_commented_lines(buf, body, commented_len);
1748+
strbuf_addstr(buf, body + commented_len);
17301749
}
17311750

17321751
static int update_squash_messages(struct repository *r,

t/t3415-rebase-autosquash.sh

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ test_auto_squash () {
8181
echo 1 >file1 &&
8282
git add -u &&
8383
test_tick &&
84-
git commit -m "squash! first" &&
85-
84+
git commit -m "squash! first" -m "extra para for first" &&
8685
git tag $1 &&
8786
test_tick &&
8887
git rebase $2 -i HEAD^^^ &&
@@ -139,7 +138,7 @@ test_expect_success 'auto squash that matches 2 commits' '
139138
echo 1 >file1 &&
140139
git add -u &&
141140
test_tick &&
142-
git commit -m "squash! first" &&
141+
git commit -m "squash! first" -m "extra para for first" &&
143142
git tag final-multisquash &&
144143
test_tick &&
145144
git rebase --autosquash -i HEAD~4 &&
@@ -192,7 +191,7 @@ test_expect_success 'auto squash that matches a sha1' '
192191
git add -u &&
193192
test_tick &&
194193
oid=$(git rev-parse --short HEAD^) &&
195-
git commit -m "squash! $oid" &&
194+
git commit -m "squash! $oid" -m "extra para" &&
196195
git tag final-shasquash &&
197196
test_tick &&
198197
git rebase --autosquash -i HEAD^^^ &&
@@ -203,7 +202,8 @@ test_expect_success 'auto squash that matches a sha1' '
203202
git cat-file blob HEAD^:file1 >actual &&
204203
test_cmp expect actual &&
205204
git cat-file commit HEAD^ >commit &&
206-
grep squash commit >actual &&
205+
! grep "squash" commit &&
206+
grep "^extra para" commit >actual &&
207207
test_line_count = 1 actual
208208
'
209209

@@ -213,7 +213,7 @@ test_expect_success 'auto squash that matches longer sha1' '
213213
git add -u &&
214214
test_tick &&
215215
oid=$(git rev-parse --short=11 HEAD^) &&
216-
git commit -m "squash! $oid" &&
216+
git commit -m "squash! $oid" -m "extra para" &&
217217
git tag final-longshasquash &&
218218
test_tick &&
219219
git rebase --autosquash -i HEAD^^^ &&
@@ -224,7 +224,8 @@ test_expect_success 'auto squash that matches longer sha1' '
224224
git cat-file blob HEAD^:file1 >actual &&
225225
test_cmp expect actual &&
226226
git cat-file commit HEAD^ >commit &&
227-
grep squash commit >actual &&
227+
! grep "squash" commit &&
228+
grep "^extra para" commit >actual &&
228229
test_line_count = 1 actual
229230
'
230231

@@ -233,7 +234,7 @@ test_auto_commit_flags () {
233234
echo 1 >file1 &&
234235
git add -u &&
235236
test_tick &&
236-
git commit --$1 first-commit &&
237+
git commit --$1 first-commit -m "extra para for first" &&
237238
git tag final-commit-$1 &&
238239
test_tick &&
239240
git rebase --autosquash -i HEAD^^^ &&
@@ -261,11 +262,11 @@ test_auto_fixup_fixup () {
261262
echo 1 >file1 &&
262263
git add -u &&
263264
test_tick &&
264-
git commit -m "$1! first" &&
265+
git commit -m "$1! first" -m "extra para for first" &&
265266
echo 2 >file1 &&
266267
git add -u &&
267268
test_tick &&
268-
git commit -m "$1! $2! first" &&
269+
git commit -m "$1! $2! first" -m "second extra para for first" &&
269270
git tag "final-$1-$2" &&
270271
test_tick &&
271272
(
@@ -326,12 +327,12 @@ test_expect_success C_LOCALE_OUTPUT 'autosquash with custom inst format' '
326327
git add -u &&
327328
test_tick &&
328329
oid=$(git rev-parse --short HEAD^) &&
329-
git commit -m "squash! $oid" &&
330+
git commit -m "squash! $oid" -m "extra para for first" &&
330331
echo 1 >file1 &&
331332
git add -u &&
332333
test_tick &&
333334
subject=$(git log -n 1 --format=%s HEAD~2) &&
334-
git commit -m "squash! $subject" &&
335+
git commit -m "squash! $subject" -m "second extra para for first" &&
335336
git tag final-squash-instFmt &&
336337
test_tick &&
337338
git rebase --autosquash -i HEAD~4 &&
@@ -342,8 +343,9 @@ test_expect_success C_LOCALE_OUTPUT 'autosquash with custom inst format' '
342343
git cat-file blob HEAD^:file1 >actual &&
343344
test_cmp expect actual &&
344345
git cat-file commit HEAD^ >commit &&
345-
grep squash commit >actual &&
346-
test_line_count = 2 actual
346+
! grep "squash" commit &&
347+
grep first commit >actual &&
348+
test_line_count = 3 actual
347349
'
348350

349351
test_expect_success 'autosquash with empty custom instructionFormat' '

t/t3900-i18n-commit.sh

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,10 +226,6 @@ test_commit_autosquash_multi_encoding () {
226226
git rev-list HEAD >actual &&
227227
test_line_count = 3 actual &&
228228
iconv -f $old -t UTF-8 "$TEST_DIRECTORY"/t3900/$msg >expect &&
229-
if test $flag = squash; then
230-
subject="$(head -1 expect)" &&
231-
printf "\nsquash! %s\n" "$subject" >>expect
232-
fi &&
233229
git cat-file commit HEAD^ >raw &&
234230
(sed "1,/^$/d" raw | iconv -f $new -t utf-8) >actual &&
235231
test_cmp expect actual

0 commit comments

Comments
 (0)