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

[PATCH v2] rebase -i: replace an echo command by printf

From
USUwe Storbeck <uwe@ibr.ch>
Date
Mar 14, 2014, 23:56 UTC
Message-ID
<20140314235642.GA6917@ibr.ch>
to avoid shell dependent behavior.

When your system shell (/bin/sh) is a dash backslash sequences in strings are interpreted by the echo command. A commit message which ends with the string '\n' may result in a garbage line in the todo list of an interactive rebase which causes the rebase to fail.

To reproduce the behavior (with dash as /bin/sh):
  mkdir test && cd test && git init
  echo 1 >foo && git add foo
  git commit -m"this commit message ends with '\n'"
  echo 2 >foo && git commit -a --fixup HEAD
  git rebase -i --autosquash --root

Now the editor opens with garbage in line 3 which has to be removed or the rebase fails.

Signed-off-by: Uwe Storbeck <uwe@ibr.ch>
---
 git-rebase--interactive.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index 43c19e0..43631b4 100644
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -739,7 +739,7 @@ rearrange_squash () {
 					;;
 				esac
 			done
-			echo "$sha1 $action $prefix $rest"
+			printf '%s %s %s %s\n' "$sha1" "$action" "$prefix" "$rest"
 			# if it's a single word, try to resolve to a full sha1 and
 			# emit a second copy. This allows us to match on both message
 			# and on sha1 prefix
-- 
1.9.0
Next: Junio C Hamano
Message 1 of 3 in “rebase -i: replace an echo command by printf”
  1. rebase -i: replace an echo command by printfUwe Storbeck, Mar 14, 2014
  2. Junio C HamanoMar 17, 2014
  3. Uwe StorbeckMar 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.