git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Corner case bug caused by shell dependent behavior
@ 2014-03-14  0:02 Uwe Storbeck
  2014-03-14  0:37 ` Jonathan Nieder
  2014-03-14  2:28 ` Jeff King
  0 siblings, 2 replies; 5+ messages in thread
From: Uwe Storbeck @ 2014-03-14  0:02 UTC (permalink / raw)
  To: git

[-- Attachment #1: Type: text/plain, Size: 799 bytes --]

Hi

When your system shell (/bin/sh) is a dash control sequences in
strings get 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.

The attached one-line patch fixes the bug. Be free to edit the
commit message when it's too long.

Maybe there are more places where it would be more robust to use
printf instead of echo.

Uwe

[-- Attachment #2: 0001-git-rebase-interactive-replace-echo-by-printf.patch --]
[-- Type: text/x-diff, Size: 1434 bytes --]

>From 53262bc8a7a3ec9d9a6b0e8ecaaea598257b87fe Mon Sep 17 00:00:00 2001
From: Uwe Storbeck <uwe@ibr.ch>
Date: Fri, 14 Mar 2014 00:28:33 +0100
Subject: [PATCH] git-rebase--interactive: replace echo by printf

to avoid shell dependent behavior.

When your system shell (/bin/sh) is a dash control sequences in
strings get 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.
---
 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 a1adae8..3ffe14c 100644
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -749,7 +749,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


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2014-03-14 23:53 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-03-14  0:02 Corner case bug caused by shell dependent behavior Uwe Storbeck
2014-03-14  0:37 ` Jonathan Nieder
2014-03-14 23:53   ` Uwe Storbeck
2014-03-14  2:28 ` Jeff King
2014-03-14  6:08   ` David Kastrup

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).