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

[PATCH v2 04/23] rebase -i: hide interactive command messages in verbose mode

From
Fabian Ruch <bafain@gmail.com>
Date
Aug 6, 2014, 23:59 UTC
Message-ID
<6d4f66b21315661e4f267f59341ebb798232a381.1407368621.git.bafain@gmail.com>
In-Reply-To
<cover.1407368621.git.bafain@gmail.com>

git-rebase--interactive prints summary messages of the commits it creates in the final history only if the `--verbose` option is specified by the user and suppresses them otherwise. This behaviour is implemented by wrapping git-commit calls in a shell function named `output` which redirects stderr to stdout, captures stdout in a shell variable and ignores its contents unless the command exits with an error status.

The command lines used to implement the to-do list commands `reword` and `squash` print diagnostic messages even in non-verbose mode. The reason for this inconsistency is that both commands launch the log message editor which usually requires a working terminal attached to stdin. Temporarily redirect the editor output to a third file descriptor in order to ship it around the capture stream. Wrap the respective git-commit command lines in `output`.

fake_editor prints the to-do list before and after applying the `FAKE_LINES` rewrite rules to it. Redirect this debug output to stderr so that it does not interfere with the git-rebase status output. Add test.

Signed-off-by: Fabian Ruch <bafain@gmail.com>
---
 git-rebase--interactive.sh    |  9 +++++----
 git-rebase.sh                 | 12 ++++++++++--
 t/lib-rebase.sh               |  8 ++++----
 t/t3404-rebase-interactive.sh | 18 ++++++------------
 t/t3406-rebase-message.sh     | 18 ++++++++++++++++++
 5 files changed, 43 insertions(+), 22 deletions(-)
diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index 89ef5e2..5dfdf13 100644
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -504,7 +504,7 @@ do_next () {
 
 		mark_action_done
 		do_pick $sha1 "$rest"
-		git commit --allow-empty --amend --no-post-rewrite ${gpg_sign_opt:+"$gpg_sign_opt"} || {
+		output git commit --allow-empty --amend --no-post-rewrite ${gpg_sign_opt:+"$gpg_sign_opt"} || {
 			warn "Could not amend commit after successfully picking $sha1... $rest"
 			warn "This is most likely due to an empty commit message, or the pre-commit hook"
 			warn "failed. If the pre-commit hook failed, you may need to resolve the issue before"
@@ -558,14 +558,14 @@ do_next () {
 			# This is the final command of this squash/fixup group
 			if test -f "$fixup_msg"
 			then
-				do_with_author git commit --allow-empty-message --allow-empty \
+				do_with_author output git commit --allow-empty-message --allow-empty \
 					--amend --no-verify -F "$fixup_msg" \
 					${gpg_sign_opt:+"$gpg_sign_opt"} ||
 					die_failed_squash $sha1 "$rest"
 			else
 				cp "$squash_msg" "$GIT_DIR"/SQUASH_MSG || exit
 				rm -f "$GIT_DIR"/MERGE_MSG
-				do_with_author git commit --allow-empty --amend --no-verify -F "$GIT_DIR"/SQUASH_MSG -e \
+				do_with_author output git commit --allow-empty --amend --no-verify -F "$GIT_DIR"/SQUASH_MSG -e \
 					${gpg_sign_opt:+"$gpg_sign_opt"} ||
 					die_failed_squash $sha1 "$rest"
 			fi
@@ -923,6 +923,8 @@ EOF
 	;;
 esac
 
+mkdir -p "$state_dir" || die "Could not create temporary $state_dir"
+
 git var GIT_COMMITTER_IDENT >/dev/null ||
 	die "You need to set your committer info first"
 
@@ -938,7 +940,6 @@ then
 fi
 
 orig_head=$(git rev-parse --verify HEAD) || die "No HEAD?"
-mkdir -p "$state_dir" || die "Could not create temporary $state_dir"
 
 : > "$state_dir"/interactive || die "Could not mark as interactive"
 write_basic_state
diff --git a/git-rebase.sh b/git-rebase.sh
index 55da9db..f90541e 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -131,9 +131,17 @@ write_basic_state () {
 output () {
 	case "$verbose" in
 	'')
-		output=$("$@" 2>&1 )
+		cat >"$state_dir"/editor.sh <<EOF
+#!/bin/sh
+$(git var GIT_EDITOR) "\$@" >&3
+EOF
+		chmod +x "$state_dir"/editor.sh
+		(
+			export GIT_EDITOR=\""$state_dir"/editor.sh\"
+			"$@" 3>&1 >"$state_dir"/output 2>&1
+		)
 		status=$?
-		test $status != 0 && printf "%s\n" "$output"
+		test $status != 0 && cat "$state_dir"/output
 		return $status
 		;;
 	*)
diff --git a/t/lib-rebase.sh b/t/lib-rebase.sh
index 6bd2522..0cd1193 100644
--- a/t/lib-rebase.sh
+++ b/t/lib-rebase.sh
@@ -41,8 +41,8 @@ set_fake_editor () {
 	test -z "$FAKE_LINES" && exit
 	grep -v '^#' < "$1" > "$1".tmp
 	rm -f "$1"
-	echo 'rebase -i script before editing:'
-	cat "$1".tmp
+	echo 'rebase -i script before editing:' >&2
+	cat "$1".tmp >&2
 	action=pick
 	for line in $FAKE_LINES; do
 		case $line in
@@ -59,8 +59,8 @@ set_fake_editor () {
 			action=pick;;
 		esac
 	done
-	echo 'rebase -i script after editing:'
-	cat "$1"
+	echo 'rebase -i script after editing:' >&2
+	cat "$1" >&2
 	EOF
 
 	test_set_editor "$(pwd)/fake-editor.sh"
diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh
index 3e64280..c6578c3 100755
--- a/t/t3404-rebase-interactive.sh
+++ b/t/t3404-rebase-interactive.sh
@@ -873,9 +873,8 @@ test_expect_success 'running "git rebase -i --exec git show HEAD"' '
 	(
 		FAKE_LINES="1 exec_git_show_HEAD 2 exec_git_show_HEAD" &&
 		export FAKE_LINES &&
-		git rebase -i HEAD~2 >expect
+		git rebase -i HEAD~2 >expected
 	) &&
-	sed -e "1,9d" expect >expected &&
 	test_cmp expected actual
 '
 
@@ -887,9 +886,8 @@ test_expect_success 'running "git rebase --exec git show HEAD -i"' '
 	(
 		FAKE_LINES="1 exec_git_show_HEAD 2 exec_git_show_HEAD" &&
 		export FAKE_LINES &&
-		git rebase -i HEAD~2 >expect
+		git rebase -i HEAD~2 >expected
 	) &&
-	sed -e "1,9d" expect >expected &&
 	test_cmp expected actual
 '
 
@@ -901,9 +899,8 @@ test_expect_success 'running "git rebase -ix git show HEAD"' '
 	(
 		FAKE_LINES="1 exec_git_show_HEAD 2 exec_git_show_HEAD" &&
 		export FAKE_LINES &&
-		git rebase -i HEAD~2 >expect
+		git rebase -i HEAD~2 >expected
 	) &&
-	sed -e "1,9d" expect >expected &&
 	test_cmp expected actual
 '
 
@@ -915,9 +912,8 @@ test_expect_success 'rebase -ix with several <CMD>' '
 	(
 		FAKE_LINES="1 exec_git_show_HEAD;_pwd 2 exec_git_show_HEAD;_pwd" &&
 		export FAKE_LINES &&
-		git rebase -i HEAD~2 >expect
+		git rebase -i HEAD~2 >expected
 	) &&
-	sed -e "1,9d" expect >expected &&
 	test_cmp expected actual
 '
 
@@ -930,9 +926,8 @@ test_expect_success 'rebase -ix with several instances of --exec' '
 		FAKE_LINES="1 exec_git_show_HEAD exec_pwd 2
 				exec_git_show_HEAD exec_pwd" &&
 		export FAKE_LINES &&
-		git rebase -i HEAD~2 >expect
+		git rebase -i HEAD~2 >expected
 	) &&
-	sed -e "1,11d" expect >expected &&
 	test_cmp expected actual
 '
 
@@ -956,9 +951,8 @@ test_expect_success 'rebase -ix with --autosquash' '
 		git checkout -b autosquash_expected &&
 		FAKE_LINES="1 fixup 3 fixup 4 exec_git_show_HEAD 2 exec_git_show_HEAD" &&
 		export FAKE_LINES &&
-		git rebase -i HEAD~4 >expect
+		git rebase -i HEAD~4 >expected
 	) &&
-	sed -e "1,13d" expect >expected &&
 	test_cmp expected actual
 '
 
diff --git a/t/t3406-rebase-message.sh b/t/t3406-rebase-message.sh
index 0392e36..d7003a9 100755
--- a/t/t3406-rebase-message.sh
+++ b/t/t3406-rebase-message.sh
@@ -4,6 +4,8 @@ test_description='messages from rebase operation'
 
 . ./test-lib.sh
 
+. "$TEST_DIRECTORY"/lib-rebase.sh
+
 test_expect_success 'setup' '
 	test_commit O fileO &&
 	test_commit X fileX &&
@@ -84,4 +86,20 @@ test_expect_success 'rebase --onto outputs the invalid ref' '
 	test_i18ngrep "invalid-ref" err
 '
 
+test_expect_success 'commit summary is suppressed in non-verbose mode' '
+	git checkout --detach Y &&
+	cat >expected.out <<-EOF &&
+	Rebasing (1/5)\r
+	Rebasing (2/5)\r
+	Rebasing (3/5)\r
+	Rebasing (4/5)\r
+	Rebasing (5/5)\r
+	EOF
+	set_fake_editor &&
+	FAKE_LINES="reword 1 fixup 2 fixup 3 4 squash 5" \
+	git rebase -i --root >actual.out.tmp &&
+	sed -e "s/\r/\\\\r\n/g" <actual.out.tmp >actual.out &&
+	test_cmp expected.out actual.out
+'
+
 test_done
-- 
2.0.1
Previous: Fabian RuchNext: Thomas Rast
Message 88 of 148 in “rebase -i: Implement `reword` and `squash` in terms of `do_pick`”
  1. 0/7 rebase -i: Implement `reword` and `squash` in terms of `do_pick`Fabian Ruch, Jun 19, 2014
  2. 00/19 Enable options --signoff, --reset-author for pick, rewordFabian Ruch, Jul 2, 2014
  3. 01/19 rebase -i: Failed reword prints redundant error messageFabian Ruch, Jul 2, 2014
  4. Junio C HamanoJul 8, 2014
  5. Andrew WongJul 10, 2014
  6. Fabian RuchJul 10, 2014
  7. Andrew WongJul 10, 2014
  8. 02/19 rebase -i: reword complains about empty commit despite --keep-emptyFabian Ruch, Jul 2, 2014
  9. Junio C HamanoJul 8, 2014
  10. Fabian RuchJul 9, 2014
  11. 03/19 rebase -i: reword executes pre-commit hook on interim commitFabian Ruch, Jul 2, 2014
  12. Junio C HamanoJul 8, 2014
  13. Fabian RuchJul 13, 2014
  14. 04/19 rebase -i: Teach do_pick the option --editFabian Ruch, Jul 2, 2014
  15. 05/19 rebase -i: Implement reword in terms of do_pickFabian Ruch, Jul 2, 2014
  16. Matthieu MoyAug 4, 2014
  17. Fabian RuchAug 4, 2014
  18. 06/19 rebase -i: Stop on root commits with empty log messagesFabian Ruch, Jul 2, 2014
  19. Junio C HamanoJul 8, 2014
  20. Fabian RuchJul 10, 2014
  21. Junio C HamanoJul 10, 2014
  22. Junio C HamanoJul 10, 2014
  23. 07/19 rebase -i: The replay of root commits is not shown with --verboseFabian Ruch, Jul 2, 2014
  24. Junio C HamanoJul 8, 2014
  25. Fabian RuchJul 11, 2014
  26. Chris WebbJul 15, 2014
  27. 08/19 rebase -i: Root commits are replayed with an unnecessary optionFabian Ruch, Jul 2, 2014
  28. Junio C HamanoJul 8, 2014
  29. Fabian RuchJul 18, 2014
  30. Junio C HamanoJul 18, 2014
  31. Fabian RuchJul 19, 2014
  32. 09/19 rebase -i: Commit only once when rewriting picksFabian Ruch, Jul 2, 2014
  33. 10/19 rebase -i: Do not die in do_pickFabian Ruch, Jul 2, 2014
  34. 11/19 rebase -i: Teach do_pick the option --amendFabian Ruch, Jul 2, 2014
  35. 12/19 rebase -i: Teach do_pick the option --fileFabian Ruch, Jul 2, 2014
  36. 13/19 rebase -i: Prepare for squash in terms of do_pick --amendFabian Ruch, Jul 2, 2014
  37. 14/19 rebase -i: Implement squash in terms of do_pickFabian Ruch, Jul 2, 2014
  38. 15/19 rebase -i: Explicitly distinguish replay commands and exec tasksFabian Ruch, Jul 2, 2014
  39. Junio C HamanoJul 10, 2014
  40. 16/19 rebase -i: Parse to-do list command line optionsFabian Ruch, Jul 2, 2014
  41. 17/19 rebase -i: Teach do_pick the option --reset-authorFabian Ruch, Jul 2, 2014
  42. 18/19 rebase -i: Teach do_pick the option --signoffFabian Ruch, Jul 2, 2014
  43. 19/19 rebase -i: Enable options --signoff, --reset-author for pick, rewordFabian Ruch, Jul 2, 2014
  44. Michael HaggertyJul 3, 2014
  45. Junio C HamanoJul 8, 2014
  46. Fabian RuchJul 9, 2014
  47. Thomas RastJul 18, 2014
  48. 00/19 Enable options --signoff, --reset-author for pick, rewordFabian Ruch, Jul 28, 2014
  49. 01/19 rebase -i: failed reword prints redundant error messageFabian Ruch, Jul 28, 2014
  50. 02/19 rebase -i: allow rewording an empty commit without complaintsFabian Ruch, Jul 28, 2014
  51. 03/19 rebase -i: reword executes pre-commit hook on interim commitFabian Ruch, Jul 28, 2014
  52. Jeff KingAug 1, 2014
  53. Fabian RuchAug 4, 2014
  54. Jeff KingAug 6, 2014
  55. 04/19 rebase -i: teach do_pick the option --editFabian Ruch, Jul 28, 2014
  56. 05/19 rebase -i: implement reword in terms of do_pickFabian Ruch, Jul 28, 2014
  57. 06/19 rebase -i: allow replaying commits with empty log messagesFabian Ruch, Jul 28, 2014
  58. 07/19 rebase -i: log the replay of root commitsFabian Ruch, Jul 28, 2014
  59. Jeff KingAug 2, 2014
  60. Fabian RuchAug 4, 2014
  61. Jeff KingAug 6, 2014
  62. 08/19 rebase -i: root commits are replayed with an unnecessary optionFabian Ruch, Jul 28, 2014
  63. Jeff KingAug 2, 2014
  64. Fabian RuchAug 4, 2014
  65. 09/19 rebase -i: commit only once when rewriting picksFabian Ruch, Jul 28, 2014
  66. Jeff KingAug 2, 2014
  67. Fabian RuchAug 7, 2014
  68. 10/19 rebase -i: do not die in do_pickFabian Ruch, Jul 28, 2014
  69. 11/19 rebase -i: teach do_pick the option --amendFabian Ruch, Jul 28, 2014
  70. 12/19 rebase -i: teach do_pick the option --fileFabian Ruch, Jul 28, 2014
  71. 13/19 rebase -i: prepare for squash in terms of do_pick --amendFabian Ruch, Jul 28, 2014
  72. 14/19 rebase -i: implement squash in terms of do_pickFabian Ruch, Jul 28, 2014
  73. 15/19 rebase -i: explicitly distinguish replay commands and exec tasksFabian Ruch, Jul 28, 2014
  74. 16/19 rebase -i: parse to-do list command line optionsFabian Ruch, Jul 28, 2014
  75. 17/19 rebase -i: teach do_pick the option --reset-authorFabian Ruch, Jul 28, 2014
  76. 18/19 rebase -i: teach do_pick the option --signoffFabian Ruch, Jul 28, 2014
  77. 19/19 rebase -i: enable options --signoff, --reset-author for pick, rewordFabian Ruch, Jul 28, 2014
  78. Jeff KingAug 2, 2014
  79. Fabian RuchAug 4, 2014
  80. 00/23 Enable options --signoff, --reset-author for pick, rewordFabian Ruch, Aug 6, 2014
  81. 01/23 rebase -i: allow replaying commits with empty log messagesFabian Ruch, Aug 6, 2014
  82. 02/23 rebase -i: allow squashing empty commits without complaintsFabian Ruch, Aug 6, 2014
  83. Peter KreftingAug 7, 2014
  84. Eric SunshineAug 7, 2014
  85. Fabian RuchAug 11, 2014
  86. Phil HordAug 13, 2014
  87. 03/23 rebase -i: allow rewording empty commits without complaintsFabian Ruch, Aug 6, 2014
  88. 04/23 rebase -i: hide interactive command messages in verbose modeFabian Ruch, Aug 6, 2014
  89. Thomas RastAug 8, 2014
  90. Fabian RuchAug 11, 2014
  91. Thomas RastAug 11, 2014
  92. 05/23 rebase -i: failed reword prints redundant error messageFabian Ruch, Aug 6, 2014
  93. 06/23 commit: allow disabling pre-commit and commit-msg separatelyFabian Ruch, Aug 6, 2014
  94. 07/23 rebase -i: squash skips commit-msg hookFabian Ruch, Aug 6, 2014
  95. 08/23 rebase -i: reword executes pre-commit hook on interim commitFabian Ruch, Aug 6, 2014
  96. Thomas RastAug 8, 2014
  97. Fabian RuchAug 11, 2014
  98. Thomas RastAug 11, 2014
  99. 09/23 rebase -i: teach do_pick the option --editFabian Ruch, Aug 6, 2014
  100. 10/23 rebase -i: implement reword in terms of do_pickFabian Ruch, Aug 6, 2014
  101. 11/23 rebase -i: log the replay of root commitsFabian Ruch, Aug 6, 2014
  102. 12/23 rebase -i: root commits are replayed with an unnecessary optionFabian Ruch, Aug 6, 2014
  103. 13/23 rebase -i: commit only once when rewriting picksFabian Ruch, Aug 6, 2014
  104. 14/23 rebase -i: do not die in do_pickFabian Ruch, Aug 6, 2014
  105. 15/23 rebase -i: teach do_pick the option --amendFabian Ruch, Aug 6, 2014
  106. 16/23 rebase -i: teach do_pick the option --fileFabian Ruch, Aug 6, 2014
  107. 17/23 rebase -i: prepare for squash in terms of do_pick --amendFabian Ruch, Aug 6, 2014
  108. 18/23 rebase -i: implement squash in terms of do_pickFabian Ruch, Aug 6, 2014
  109. 19/23 rebase -i: explicitly distinguish replay commands and exec tasksFabian Ruch, Aug 6, 2014
  110. 20/23 rebase -i: parse to-do list command line optionsFabian Ruch, Aug 6, 2014
  111. Thomas RastAug 8, 2014
  112. Fabian RuchAug 11, 2014
  113. 21/23 rebase -i: teach do_pick the option --reset-authorFabian Ruch, Aug 6, 2014
  114. 22/23 rebase -i: teach do_pick the option --signoffFabian Ruch, Aug 6, 2014
  115. 23/23 rebase -i: enable options --signoff, --reset-author for pick, rewordFabian Ruch, Aug 6, 2014
  116. Thomas RastAug 8, 2014
  117. Fabian RuchAug 12, 2014
  118. Michael HaggertyAug 13, 2014
  119. Fabian RuchAug 14, 2014
  120. Fabian RuchSep 21, 2014
  121. 00/27 Enable options --signoff, --reset-author for pick, reword, editFabian Ruch, Aug 18, 2014
  122. 01/27 rebase -i: allow replaying commits with empty log messagesFabian Ruch, Aug 18, 2014
  123. 02/27 rebase -i: allow squashing empty commits without complaintsFabian Ruch, Aug 18, 2014
  124. 03/27 rebase -i: allow rewording empty commits without complaintsFabian Ruch, Aug 18, 2014
  125. 04/27 fake_editor: leave standard output unchangedFabian Ruch, Aug 18, 2014
  126. 05/27 rebase -i: hide interactive command messages in verbose modeFabian Ruch, Aug 18, 2014
  127. 06/27 rebase -i: discard redundant message when rewording failsFabian Ruch, Aug 18, 2014
  128. 07/27 commit: allow disabling pre-commit and commit-msg separatelyFabian Ruch, Aug 18, 2014
  129. 08/27 rebase -i: verify squash messages using commit-msgFabian Ruch, Aug 18, 2014
  130. 09/27 rebase -i: do not verify reworded patches using pre-commitFabian Ruch, Aug 18, 2014
  131. 10/27 rebase -i: teach do_pick the option --editFabian Ruch, Aug 18, 2014
  132. 11/27 rebase -i: implement reword in terms of do_pickFabian Ruch, Aug 18, 2014
  133. 12/27 rebase -i: log the replay of root commitsFabian Ruch, Aug 18, 2014
  134. 13/27 rebase -i: do not use -C when --no-edit is sufficientFabian Ruch, Aug 18, 2014
  135. 14/27 rebase -i: commit only once when rewriting picksFabian Ruch, Aug 18, 2014
  136. 15/27 rebase -i: do not die in do_pickFabian Ruch, Aug 18, 2014
  137. 16/27 rebase -i: teach do_pick the option --amendFabian Ruch, Aug 18, 2014
  138. 17/27 rebase -i: teach do_pick the option --fileFabian Ruch, Aug 18, 2014
  139. 18/27 rebase -i: remove no-op do_with_author git commit --amendFabian Ruch, Aug 18, 2014
  140. 19/27 rebase -i: prepare for squash in terms of do_pick --amendFabian Ruch, Aug 18, 2014
  141. 20/27 rebase -i: implement squash in terms of do_pickFabian Ruch, Aug 18, 2014
  142. 21/27 rebase -i: explicitly distinguish replay commands and exec tasksFabian Ruch, Aug 18, 2014
  143. 22/27 rebase -i: parse to-do list command line optionsFabian Ruch, Aug 18, 2014
  144. 23/27 rebase -i: teach do_pick the option --reset-authorFabian Ruch, Aug 18, 2014
  145. 24/27 rebase -i: teach do_pick the option --signoffFabian Ruch, Aug 18, 2014
  146. 25/27 rebase -i: do not overwrite user author informationFabian Ruch, Aug 18, 2014
  147. 26/27 rebase -i: refuse to commit when resuming with updated headFabian Ruch, Aug 18, 2014
  148. 27/27 rebase -i: enable --signoff, --reset-author for pick, reword, editFabian Ruch, Aug 18, 2014

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.