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

Re: Bug: git-rebase goofs up \n in commit messages

From
Junio C Hamano <junkio@cox.net>
Date
May 26, 2007, 04:59 UTC
Message-ID
<7vps4onps0.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<20070526034236.GA18169@coredump.intra.peff.net>

It turns out that git-commit also shares the same problem under dash.

-- >8 -- git-commit: use printf "%s\n" instead of echo on user-supplied strings

This adds a test to verify the earlier fix to git-am by Jeff King, and fixes the same issue in git-commit that is exposed by the new test while at it.

Cleverly enough, this commit's log message is a good test case at the same time.

Signed-off-by: Junio C Hamano <junkio@cox.net>
---
 * I suspect we would declare either "war on echo" or "harder push
   for builtins" triggered by these.
 git-commit.sh           |    8 ++++----
 t/t4014-format-patch.sh |    6 +++---
 2 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/git-commit.sh b/git-commit.sh
index 292cf96..f3f9a35 100755
--- a/git-commit.sh
+++ b/git-commit.sh
@@ -376,12 +376,12 @@ t,)
 			rm -f "$TMP_INDEX"
 		fi || exit
 
-		echo "$commit_only" |
+		printf "%s\n" "$commit_only" |
 		GIT_INDEX_FILE="$TMP_INDEX" \
 		git-update-index --add --remove --stdin &&
 
 		save_index &&
-		echo "$commit_only" |
+		printf "%s\n" "$commit_only" |
 		(
 			GIT_INDEX_FILE="$NEXT_INDEX"
 			export GIT_INDEX_FILE
@@ -432,7 +432,7 @@ fi
 
 if test "$log_message" != ''
 then
-	echo "$log_message"
+	printf "%s\n" "$log_message"
 elif test "$logfile" != ""
 then
 	if test "$logfile" = -
@@ -475,7 +475,7 @@ if test -f "$GIT_DIR/MERGE_HEAD" && test -z "$no_edit"; then
 	echo "#"
 	echo "# It looks like you may be committing a MERGE."
 	echo "# If this is not correct, please remove the file"
-	echo "#	$GIT_DIR/MERGE_HEAD"
+	printf "%s\n" "#	$GIT_DIR/MERGE_HEAD"
 	echo "# and try again"
 	echo "#"
 fi >>"$GIT_DIR"/COMMIT_EDITMSG
diff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh
index 4795872..42aa9e4 100755
--- a/t/t4014-format-patch.sh
+++ b/t/t4014-format-patch.sh
@@ -16,16 +16,16 @@ test_expect_success setup '
 
 	for i in 1 2 5 6 A B C 7 8 9 10; do echo "$i"; done >file &&
 	git update-index file &&
-	git commit -m "Side change #1" &&
+	git commit -m "Side changes #1" &&
 
 	for i in D E F; do echo "$i"; done >>file &&
 	git update-index file &&
-	git commit -m "Side change #2" &&
+	git commit -m "Side changes #2" &&
 	git tag C2 &&
 
 	for i in 5 6 1 2 3 A 4 B C 7 8 9 10 D E F; do echo "$i"; done >file &&
 	git update-index file &&
-	git commit -m "Side change #3" &&
+	git commit -m "Side changes #3 with \\n backslash-n in it." &&
 
 	git checkout master &&
 	git diff-tree -p C2 | git apply --index &&
Previous: Junio C HamanoNext: Jeff King
Message 6 of 13 in “Bug: git-rebase goofs up \n in commit messages”
  1. Szekeres IstvanMay 25, 2007
  2. Jeff KingMay 26, 2007
  3. Herbert XuMay 26, 2007
  4. Jeff KingMay 26, 2007
  5. Junio C HamanoMay 26, 2007
  6. Junio C HamanoMay 26, 2007
  7. Jeff KingMay 26, 2007
  8. Junio C HamanoMay 26, 2007
  9. Herbert XuMay 26, 2007
  10. Jeff KingMay 26, 2007
  11. Herbert XuMay 26, 2007
  12. Jeff KingMay 26, 2007
  13. Junio C HamanoMay 26, 2007

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.