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 <phillip.wood@dunelm.org.uk> Reviewed-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Charvi Mendiratta <charvi077@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Phillip Wood committed
Jan 29, 2021 at 23:50 UTC
7cdb9682545d7865e832d092f900a8037898e907
3 files changed
+36
-19
sequencer.c
+20
-1
@@ -1718,15 +1718,34 @@ static int is_pick_or_similar(enum todo_command command)
1718
}
1719
}
1720
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
+
1735
static void append_squash_message(struct strbuf *buf, const char *body,
1736
struct replay_opts *opts)
1737
{
1738
+ size_t commented_len = 0;
1739
+
1740
unlink(rebase_path_fixup_msg());
1741
+ if (starts_with(body, "squash!") || starts_with(body, "fixup!"))
1742
+ commented_len = subject_length(body);
1743
strbuf_addf(buf, "\n%c ", comment_line_char);
1744
strbuf_addf(buf, _("This is the commit message #%d:"),
1745
++opts->current_fixup_count + 1);
1746
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);
1749
}
1750
1751
static int update_squash_messages(struct repository *r,
t/t3415-rebase-autosquash.sh
+16
-14
@@ -81,8 +81,7 @@ test_auto_squash () {
81
echo 1 >file1 &&
82
git add -u &&
83
test_tick &&
84
- git commit -m "squash! first" &&
85
-
84
+ git commit -m "squash! first" -m "extra para for first" &&
85
git tag $1 &&
86
test_tick &&
87
git rebase $2 -i HEAD^^^ &&
@@ -139,7 +138,7 @@ test_expect_success 'auto squash that matches 2 commits' '
138
echo 1 >file1 &&
139
git add -u &&
140
test_tick &&
142
- git commit -m "squash! first" &&
141
+ git commit -m "squash! first" -m "extra para for first" &&
142
git tag final-multisquash &&
143
test_tick &&
144
git rebase --autosquash -i HEAD~4 &&
@@ -192,7 +191,7 @@ test_expect_success 'auto squash that matches a sha1' '
191
git add -u &&
192
test_tick &&
193
oid=$(git rev-parse --short HEAD^) &&
195
- git commit -m "squash! $oid" &&
194
+ git commit -m "squash! $oid" -m "extra para" &&
195
git tag final-shasquash &&
196
test_tick &&
197
git rebase --autosquash -i HEAD^^^ &&
@@ -203,7 +202,8 @@ test_expect_success 'auto squash that matches a sha1' '
202
git cat-file blob HEAD^:file1 >actual &&
203
test_cmp expect actual &&
204
git cat-file commit HEAD^ >commit &&
206
- grep squash commit >actual &&
205
+ ! grep "squash" commit &&
206
+ grep "^extra para" commit >actual &&
207
test_line_count = 1 actual
208
'
209
@@ -213,7 +213,7 @@ test_expect_success 'auto squash that matches longer sha1' '
213
git add -u &&
214
test_tick &&
215
oid=$(git rev-parse --short=11 HEAD^) &&
216
- git commit -m "squash! $oid" &&
216
+ git commit -m "squash! $oid" -m "extra para" &&
217
git tag final-longshasquash &&
218
test_tick &&
219
git rebase --autosquash -i HEAD^^^ &&
@@ -224,7 +224,8 @@ test_expect_success 'auto squash that matches longer sha1' '
224
git cat-file blob HEAD^:file1 >actual &&
225
test_cmp expect actual &&
226
git cat-file commit HEAD^ >commit &&
227
- grep squash commit >actual &&
227
+ ! grep "squash" commit &&
228
+ grep "^extra para" commit >actual &&
229
test_line_count = 1 actual
230
'
231
@@ -233,7 +234,7 @@ test_auto_commit_flags () {
234
echo 1 >file1 &&
235
git add -u &&
236
test_tick &&
236
- git commit --$1 first-commit &&
237
+ git commit --$1 first-commit -m "extra para for first" &&
238
git tag final-commit-$1 &&
239
test_tick &&
240
git rebase --autosquash -i HEAD^^^ &&
@@ -261,11 +262,11 @@ test_auto_fixup_fixup () {
262
echo 1 >file1 &&
263
git add -u &&
264
test_tick &&
264
- git commit -m "$1! first" &&
265
+ git commit -m "$1! first" -m "extra para for first" &&
266
echo 2 >file1 &&
267
git add -u &&
268
test_tick &&
268
- git commit -m "$1! $2! first" &&
269
+ git commit -m "$1! $2! first" -m "second extra para for first" &&
270
git tag "final-$1-$2" &&
271
test_tick &&
272
(
@@ -326,12 +327,12 @@ test_expect_success C_LOCALE_OUTPUT 'autosquash with custom inst format' '
327
git add -u &&
328
test_tick &&
329
oid=$(git rev-parse --short HEAD^) &&
329
- git commit -m "squash! $oid" &&
330
+ git commit -m "squash! $oid" -m "extra para for first" &&
331
echo 1 >file1 &&
332
git add -u &&
333
test_tick &&
334
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" &&
336
git tag final-squash-instFmt &&
337
test_tick &&
338
git rebase --autosquash -i HEAD~4 &&
@@ -342,8 +343,9 @@ test_expect_success C_LOCALE_OUTPUT 'autosquash with custom inst format' '
343
git cat-file blob HEAD^:file1 >actual &&
344
test_cmp expect actual &&
345
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
349
'
350
351
test_expect_success 'autosquash with empty custom instructionFormat' '
t/t3900-i18n-commit.sh
-4
@@ -226,10 +226,6 @@ test_commit_autosquash_multi_encoding () {
226
git rev-list HEAD >actual &&
227
test_line_count = 3 actual &&
228
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 &&
229
git cat-file commit HEAD^ >raw &&
230
(sed "1,/^$/d" raw | iconv -f $new -t utf-8) >actual &&
231
test_cmp expect actual