git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[RFC PATCH 3/9] rebase -i: comment out squash!/fixup! subjects from squash message

From
Charvi Mendiratta <charvi077@gmail.com>
Date
Jan 8, 2021, 09:23 UTC
Message-ID
<20210108092345.2178-4-charvi077@gmail.com>
In-Reply-To
<20210108092345.2178-1-charvi077@gmail.com>
From: Phillip Wood <phillip.wood@dunelm.org.uk>

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>
Signed-off-by: Charvi Mendiratta <charvi077@gmail.com>
---
 sequencer.c                  | 25 ++++++++++++++++++++++++-
 t/t3415-rebase-autosquash.sh | 27 +++++++++++++--------------
 t/t3900-i18n-commit.sh       |  4 ----
 3 files changed, 37 insertions(+), 19 deletions(-)
diff --git a/sequencer.c b/sequencer.c
index 5062976d10..b050a9a212 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -1718,15 +1718,38 @@ static int is_pick_or_similar(enum todo_command command)
 	}
 }
 
+static size_t subject_length(const char *body)
+{
+	size_t i, len = 0;
+	char c;
+	int blank_line = 1;
+	for (i = 0, c = body[i]; c; c = body[++i]) {
+		if (c == '\n') {
+			if (blank_line)
+				return len;
+			len = i + 1;
+			blank_line = 1;
+		} else if (!isspace(c)) {
+			blank_line = 0;
+		}
+	}
+	return blank_line ? len : i;
+}
+
 static void append_squash_message(struct strbuf *buf, const char *body,
 				  struct replay_opts *opts)
 {
+	size_t commented_len = 0;
+
 	unlink(rebase_path_fixup_msg());
+	if (starts_with(body, "squash!") || starts_with(body, "fixup!"))
+		commented_len = subject_length(body);
 	strbuf_addf(buf, "\n%c ", comment_line_char);
 	strbuf_addf(buf, _("This is the commit message #%d:"),
 		    ++opts->current_fixup_count + 1);
 	strbuf_addstr(buf, "\n\n");
-	strbuf_addstr(buf, body);
+	strbuf_add_commented_lines(buf, body, commented_len);
+	strbuf_addstr(buf, body + commented_len);
 }
 
 static int update_squash_messages(struct repository *r,
diff --git a/t/t3415-rebase-autosquash.sh b/t/t3415-rebase-autosquash.sh
index 7bab6000dc..45fe6a227e 100755
--- a/t/t3415-rebase-autosquash.sh
+++ b/t/t3415-rebase-autosquash.sh
@@ -81,8 +81,7 @@ test_auto_squash () {
 	echo 1 >file1 &&
 	git add -u &&
 	test_tick &&
-	git commit -m "squash! first" &&
-
+	git commit -m "squash! first" -m "extra para for first" &&
 	git tag $1 &&
 	test_tick &&
 	git rebase $2 -i HEAD^^^ &&
@@ -139,7 +138,7 @@ test_expect_success 'auto squash that matches 2 commits' '
 	echo 1 >file1 &&
 	git add -u &&
 	test_tick &&
-	git commit -m "squash! first" &&
+	git commit -m "squash! first" -m "extra para for first" &&
 	git tag final-multisquash &&
 	test_tick &&
 	git rebase --autosquash -i HEAD~4 &&
@@ -192,7 +191,7 @@ test_expect_success 'auto squash that matches a sha1' '
 	git add -u &&
 	test_tick &&
 	oid=$(git rev-parse --short HEAD^) &&
-	git commit -m "squash! $oid" &&
+	git commit -m "squash! $oid" -m "extra para" &&
 	git tag final-shasquash &&
 	test_tick &&
 	git rebase --autosquash -i HEAD^^^ &&
@@ -203,7 +202,7 @@ test_expect_success 'auto squash that matches a sha1' '
 	git cat-file blob HEAD^:file1 >actual &&
 	test_cmp expect actual &&
 	git cat-file commit HEAD^ >commit &&
-	grep squash commit >actual &&
+	grep "extra para" commit >actual &&
 	test_line_count = 1 actual
 '
 
@@ -213,7 +212,7 @@ test_expect_success 'auto squash that matches longer sha1' '
 	git add -u &&
 	test_tick &&
 	oid=$(git rev-parse --short=11 HEAD^) &&
-	git commit -m "squash! $oid" &&
+	git commit -m "squash! $oid" -m "extra para" &&
 	git tag final-longshasquash &&
 	test_tick &&
 	git rebase --autosquash -i HEAD^^^ &&
@@ -224,7 +223,7 @@ test_expect_success 'auto squash that matches longer sha1' '
 	git cat-file blob HEAD^:file1 >actual &&
 	test_cmp expect actual &&
 	git cat-file commit HEAD^ >commit &&
-	grep squash commit >actual &&
+	grep "extra para" commit >actual &&
 	test_line_count = 1 actual
 '
 
@@ -233,7 +232,7 @@ test_auto_commit_flags () {
 	echo 1 >file1 &&
 	git add -u &&
 	test_tick &&
-	git commit --$1 first-commit &&
+	git commit --$1 first-commit -m "extra para for first" &&
 	git tag final-commit-$1 &&
 	test_tick &&
 	git rebase --autosquash -i HEAD^^^ &&
@@ -261,11 +260,11 @@ test_auto_fixup_fixup () {
 	echo 1 >file1 &&
 	git add -u &&
 	test_tick &&
-	git commit -m "$1! first" &&
+	git commit -m "$1! first" -m "extra para for first" &&
 	echo 2 >file1 &&
 	git add -u &&
 	test_tick &&
-	git commit -m "$1! $2! first" &&
+	git commit -m "$1! $2! first" -m "second extra para for first" &&
 	git tag "final-$1-$2" &&
 	test_tick &&
 	(
@@ -326,12 +325,12 @@ test_expect_success C_LOCALE_OUTPUT 'autosquash with custom inst format' '
 	git add -u &&
 	test_tick &&
 	oid=$(git rev-parse --short HEAD^) &&
-	git commit -m "squash! $oid" &&
+	git commit -m "squash! $oid" -m "extra para for first" &&
 	echo 1 >file1 &&
 	git add -u &&
 	test_tick &&
 	subject=$(git log -n 1 --format=%s HEAD~2) &&
-	git commit -m "squash! $subject" &&
+	git commit -m "squash! $subject" -m "second extra para for first" &&
 	git tag final-squash-instFmt &&
 	test_tick &&
 	git rebase --autosquash -i HEAD~4 &&
@@ -342,8 +341,8 @@ test_expect_success C_LOCALE_OUTPUT 'autosquash with custom inst format' '
 	git cat-file blob HEAD^:file1 >actual &&
 	test_cmp expect actual &&
 	git cat-file commit HEAD^ >commit &&
-	grep squash commit >actual &&
-	test_line_count = 2 actual
+	grep first commit >actual &&
+	test_line_count = 3 actual
 '
 
 test_expect_success 'autosquash with empty custom instructionFormat' '
diff --git a/t/t3900-i18n-commit.sh b/t/t3900-i18n-commit.sh
index d277a9f4b7..bfab245eb3 100755
--- a/t/t3900-i18n-commit.sh
+++ b/t/t3900-i18n-commit.sh
@@ -226,10 +226,6 @@ test_commit_autosquash_multi_encoding () {
 		git rev-list HEAD >actual &&
 		test_line_count = 3 actual &&
 		iconv -f $old -t UTF-8 "$TEST_DIRECTORY"/t3900/$msg >expect &&
-		if test $flag = squash; then
-			subject="$(head -1 expect)" &&
-			printf "\nsquash! %s\n" "$subject" >>expect
-		fi &&
 		git cat-file commit HEAD^ >raw &&
 		(sed "1,/^$/d" raw | iconv -f $new -t utf-8) >actual &&
 		test_cmp expect actual
-- 
2.29.0.rc1
Previous: Charvi MendirattaNext: Taylor Blau
Message 10 of 110 in “[Outreachy] rebase -i: add options to fixup command”
  1. 0/9 [Outreachy] rebase -i: add options to fixup commandCharvi Mendiratta, Jan 8, 2021
  2. 1/9 rebase -i: only write fixup-message when it's neededCharvi Mendiratta, Jan 8, 2021
  3. Taylor BlauJan 13, 2021
  4. Charvi MendirattaJan 14, 2021
  5. Phillip WoodJan 14, 2021
  6. Charvi MendirattaJan 15, 2021
  7. Junio C HamanoJan 15, 2021
  8. Charvi MendirattaJan 16, 2021
  9. 2/9 sequencer: factor out code to append squash messageCharvi Mendiratta, Jan 8, 2021
  10. 3/9 rebase -i: comment out squash!/fixup! subjects from squash messageCharvi Mendiratta, Jan 8, 2021
  11. Taylor BlauJan 13, 2021
  12. Charvi MendirattaJan 14, 2021
  13. Phillip WoodJan 14, 2021
  14. Charvi MendirattaJan 15, 2021
  15. Christian CouderJan 15, 2021
  16. Charvi MendirattaJan 15, 2021
  17. Charvi MendirattaJan 17, 2021
  18. Phillip WoodJan 18, 2021
  19. Charvi MendirattaJan 19, 2021
  20. 4/9 sequencer: pass todo_item to do_pick_commit()Charvi Mendiratta, Jan 8, 2021
  21. 5/9 sequencer: use const variable for commit message commentsCharvi Mendiratta, Jan 8, 2021
  22. Taylor BlauJan 13, 2021
  23. Junio C HamanoJan 13, 2021
  24. Christian CouderJan 14, 2021
  25. Charvi MendirattaJan 14, 2021
  26. 6/9 rebase -i: add fixup [-C | -c] commandCharvi Mendiratta, Jan 8, 2021
  27. Christian CouderJan 14, 2021
  28. Charvi MendirattaJan 14, 2021
  29. 8/9 rebase -i: teach --autosquash to work with amend!Charvi Mendiratta, Jan 8, 2021
  30. 7/9 t3437: test script for fixup [-C|-c] options in interactive rebaseCharvi Mendiratta, Jan 8, 2021
  31. 9/9 doc/git-rebase: add documentation for fixup [-C|-c] optionsCharvi Mendiratta, Jan 8, 2021
  32. 0/9 [Outreachy] rebase -i: add options to fixup commandCharvi Mendiratta, Jan 19, 2021
  33. 0/9 [Outreachy] rebase -i: add options to fixup commandCharvi Mendiratta, Jan 24, 2021
  34. 1/9 rebase -i: only write fixup-message when it's neededCharvi Mendiratta, Jan 24, 2021
  35. 2/9 sequencer: factor out code to append squash messageCharvi Mendiratta, Jan 24, 2021
  36. 3/9 rebase -i: comment out squash!/fixup! subjects from squash messageCharvi Mendiratta, Jan 24, 2021
  37. 4/9 sequencer: pass todo_item to do_pick_commit()Charvi Mendiratta, Jan 24, 2021
  38. 5/9 sequencer: use const variable for commit message commentsCharvi Mendiratta, Jan 24, 2021
  39. 6/9 rebase -i: add fixup [-C | -c] commandCharvi Mendiratta, Jan 24, 2021
  40. 7/9 t3437: test script for fixup [-C|-c] options in interactive rebaseCharvi Mendiratta, Jan 24, 2021
  41. 8/9 rebase -i: teach --autosquash to work with amend!Charvi Mendiratta, Jan 24, 2021
  42. 9/9 doc/git-rebase: add documentation for fixup [-C|-c] optionsCharvi Mendiratta, Jan 24, 2021
  43. 0/9 [Outreachy] rebase -i: add options to fixup commandCharvi Mendiratta, Jan 29, 2021
  44. 1/9 rebase -i: only write fixup-message when it's neededCharvi Mendiratta, Jan 29, 2021
  45. 2/9 sequencer: factor out code to append squash messageCharvi Mendiratta, Jan 29, 2021
  46. 3/9 rebase -i: comment out squash!/fixup! subjects from squash messageCharvi Mendiratta, Jan 29, 2021
  47. 6/9 rebase -i: add fixup [-C | -c] commandCharvi Mendiratta, Jan 29, 2021
  48. Eric SunshineFeb 2, 2021
  49. Charvi MendirattaFeb 2, 2021
  50. Eric SunshineFeb 3, 2021
  51. Charvi MendirattaFeb 4, 2021
  52. Eric SunshineFeb 4, 2021
  53. 9/9 doc/git-rebase: add documentation for fixup [-C|-c] optionsCharvi Mendiratta, Jan 29, 2021
  54. Eric SunshineFeb 2, 2021
  55. Charvi MendirattaFeb 2, 2021
  56. Marc BranchaudFeb 2, 2021
  57. 7/9 t3437: test script for fixup [-C|-c] options in interactive rebaseCharvi Mendiratta, Jan 29, 2021
  58. Eric SunshineFeb 2, 2021
  59. Christian CouderFeb 2, 2021
  60. Charvi MendirattaFeb 2, 2021
  61. Eric SunshineFeb 3, 2021
  62. Charvi MendirattaFeb 4, 2021
  63. Phillip WoodFeb 4, 2021
  64. Eric SunshineFeb 4, 2021
  65. Charvi MendirattaFeb 4, 2021
  66. 4/9 sequencer: pass todo_item to do_pick_commit()Charvi Mendiratta, Jan 29, 2021
  67. 8/9 rebase -i: teach --autosquash to work with amend!Charvi Mendiratta, Jan 29, 2021
  68. Eric SunshineFeb 2, 2021
  69. Charvi MendirattaFeb 2, 2021
  70. 5/9 sequencer: use const variable for commit message commentsCharvi Mendiratta, Jan 29, 2021
  71. 0/8 [Outreachy] rebase -i: add options to fixup commandCharvi Mendiratta, Feb 4, 2021
  72. 1/8 rebase -i: only write fixup-message when it's neededCharvi Mendiratta, Feb 4, 2021
  73. 3/8 rebase -i: comment out squash!/fixup! subjects from squash messageCharvi Mendiratta, Feb 4, 2021
  74. 7/8 t3437: test script for fixup [-C|-c] options in interactive rebaseCharvi Mendiratta, Feb 4, 2021
  75. 6/8 rebase -i: add fixup [-C | -c] commandCharvi Mendiratta, Feb 4, 2021
  76. 2/8 sequencer: factor out code to append squash messageCharvi Mendiratta, Feb 4, 2021
  77. 5/8 sequencer: use const variable for commit message commentsCharvi Mendiratta, Feb 4, 2021
  78. 8/8 doc/git-rebase: add documentation for fixup [-C|-c] optionsCharvi Mendiratta, Feb 4, 2021
  79. 4/8 sequencer: pass todo_item to do_pick_commit()Charvi Mendiratta, Feb 4, 2021
  80. Eric SunshineFeb 5, 2021
  81. Charvi MendirattaFeb 5, 2021
  82. Christian CouderFeb 5, 2021
  83. Eric SunshineFeb 5, 2021
  84. Charvi MendirattaFeb 6, 2021
  85. Junio C HamanoFeb 5, 2021
  86. Charvi MendirattaFeb 6, 2021
  87. 1/9 rebase -i: only write fixup-message when it's neededCharvi Mendiratta, Jan 19, 2021
  88. 2/9 sequencer: factor out code to append squash messageCharvi Mendiratta, Jan 19, 2021
  89. 5/9 sequencer: use const variable for commit message commentsCharvi Mendiratta, Jan 19, 2021
  90. 3/9 rebase -i: comment out squash!/fixup! subjects from squash messageCharvi Mendiratta, Jan 19, 2021
  91. Junio C HamanoJan 21, 2021
  92. Charvi MendirattaJan 21, 2021
  93. Christian CouderJan 21, 2021
  94. Phillip WoodJan 21, 2021
  95. Junio C HamanoJan 21, 2021
  96. Charvi MendirattaJan 22, 2021
  97. Charvi MendirattaJan 22, 2021
  98. 4/9 sequencer: pass todo_item to do_pick_commit()Charvi Mendiratta, Jan 19, 2021
  99. 7/9 t3437: test script for fixup [-C|-c] options in interactive rebaseCharvi Mendiratta, Jan 19, 2021
  100. 8/9 rebase -i: teach --autosquash to work with amend!Charvi Mendiratta, Jan 19, 2021
  101. 9/9 doc/git-rebase: add documentation for fixup [-C|-c] optionsCharvi Mendiratta, Jan 19, 2021
  102. Marc BranchaudJan 19, 2021
  103. Charvi MendirattaJan 19, 2021
  104. Marc BranchaudJan 19, 2021
  105. Charvi MendirattaJan 20, 2021
  106. Phillip WoodJan 20, 2021
  107. Charvi MendirattaJan 20, 2021
  108. Phillip WoodJan 20, 2021
  109. Charvi MendirattaJan 20, 2021
  110. 6/9 rebase -i: add fixup [-C | -c] commandCharvi Mendiratta, Jan 19, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.