test failure in t4014-format-patch.sh with master
Hello,
While trying to wrote a test for git, I discover that there is a test failure in master on my computer:
$ ./t4014-format-patch.sh [....] * FAIL 8: replay did not screw up the log message
git cat-file commit rebuild-1 | grep "^Side .* with .* backslash-n"
It seem that now, somewhere a \n has been interpreted as a newline.
Bisecting point the problem to the 2e6e3e82 commit "git-am: cope better with an empty Subject: line"
Signature · 1 line
Rémi Vanicat
Quoted 3 lines · Remi Vanicat
While trying to wrote a test for git, I discover that there is a test failure in master on my computer:
Hmm. Doesn't fail for me.
Quoted 7 lines
$ ./t4014-format-patch.sh [....] * FAIL 8: replay did not screw up the log messagegit cat-file commit rebuild-1 | grep "^Side .* with .* backslash-n"
It seem that now, somewhere a \n has been interpreted as a newline.
I wonder if it is some shell-specific variable expansion issue. What's your /bin/sh? (I assume, from your email address, that you're using Debian, and I thought Debian used bash, but maybe that's not true).
What does
a="hello\nhi" echo $a
result in?
Linus
Quoted 21 lines · Linus Torvalds
Quoted 3 lines · Remi Vanicat
While trying to wrote a test for git, I discover that there is a test failure in master on my computer:
Hmm. Doesn't fail for me.
Quoted 7 lines
$ ./t4014-format-patch.sh [....] * FAIL 8: replay did not screw up the log messagegit cat-file commit rebuild-1 | grep "^Side .* with .* backslash-n"
It seem that now, somewhere a \n has been interpreted as a newline.
I wonder if it is some shell-specific variable expansion issue. What's your
/bin/sh? (I assume, from your email address, that you're using Debian, and I thought Debian used bash, but maybe that's not true).
Quoted 6 lines
What does
a="hello\nhi" echo $aresult in?
Debian has its own dash which is supposed to be a lightweight alternative to bash and "for checking POSIX compliance of scripts" (quote from the packages description). I don't happen to know off-hand whether POSIX says that echo should default to -e, but dash seems to do that:
$ dash $ a="hello\nhi" $ echo $a hello hi
Björn
Quoted 7 lines · Björn Steinbrink
Debian has its own dash which is supposed to be a lightweight alternative to bash and "for checking POSIX compliance of scripts" (quote from the packages description). I don't happen to know off-hand whether POSIX says that echo should default to -e, but dash seems to do that:
Quoted 5 lines
$ dash $ a="hello\nhi" $ echo $a hello hi
Ahh. So that "echo" should just be replaced with a 'printf "%s\n"' instead?
We have a _lot_ of "echo"s though. I suspect the only ones we'd ever catch are the ones explicitly tested for. I suspect that the dash echo is just broken.
Linus
Quoted 16 lines · Linus Torvalds
Quoted 7 lines · Björn Steinbrink
Debian has its own dash which is supposed to be a lightweight alternative to bash and "for checking POSIX compliance of scripts" (quote from the packages description). I don't happen to know off-hand whether POSIX says that echo should default to -e, but dash seems to do that:
Quoted 5 lines
$ dash $ a="hello\nhi" $ echo $a hello hi
Quoted 6 lines
Ahh. So that "echo" should just be replaced with a 'printf "%s\n"' instead?
We have a _lot_ of "echo"s though. I suspect the only ones we'd ever catch are the ones explicitly tested for. I suspect that the dash echo is just broken.
Wow, seems that "echo" in itself is "broken". According to POSIX[1] backslashes induce implementation defined behaviour, and there seem to be two historic versions of echo, one that knows about -n and one that interprets escape sequences. So echo is totally non-portable unless you avoid -n as well as backslashes. Ouch.
The POSIX docs, as well as random Google results, indeed recommend to use printf instead. But that switch seems painful as well...
Björn
[1] http://www.opengroup.org/onlinepubs/009695399/utilities/echo.html
Quoted 6 lines · Linus Torvalds
Ahh. So that "echo" should just be replaced with a 'printf "%s\n"' instead?
We have a _lot_ of "echo"s though. I suspect the only ones we'd ever catch are the ones explicitly tested for. I suspect that the dash echo is just broken.
As Bjorn mentioned, it's POSIX. Junio and I already hunted down quite a few of these, so I think we are OK in general, and this is just a new one that got introduced.
-Peff
Quoted 3 lines · Jeff King
As Bjorn mentioned, it's POSIX. Junio and I already hunted down quite a few of these, so I think we are OK in general, and this is just a new one that got introduced.
Oops, I meant to mention this thread:
http://article.gmane.org/gmane.comp.version-control.git/48419
-Peff
2008/4/17, Linus Torvalds <[email protected]>:
Quoted 3 lines · Remi Vanicat
[...]
Quoted 5 lines
Quoted 3 lines
$ ./t4014-format-patch.sh [....] * FAIL 8: replay did not screw up the log messageHmm. Doesn't fail for me.
[...]
Quoted 3 lines
I wonder if it is some shell-specific variable expansion issue. What's your
/bin/sh? (I assume, from your email address, that you're using Debian, and I thought Debian used bash, but maybe that's not true).
Debian used bash, but I use dash as /bin/sh
Quoted 6 lines
What does
a="hello\nhi" echo $aresult in?
here is the problem:
$/bin/sh
$ a="hello\nhi" $ echo $a hello hi
Mmm, I Wonder what posix said about this, but it look like a bug with dash
Quoted 10 lines · Rémi Vanicat
2008/4/17, Linus Torvalds <[email protected]>:
Quoted 2 lines · Remi Vanicat
[...]
Quoted 5 lines
Quoted 3 lines
$ ./t4014-format-patch.sh [....] * FAIL 8: replay did not screw up the log messageHmm. Doesn't fail for me.
Quoted 14 lines
[...]
Quoted 3 lines
I wonder if it is some shell-specific variable expansion issue. What's your
/bin/sh? (I assume, from your email address, that you're using Debian, and I thought Debian used bash, but maybe that's not true).Debian used bash, but I use dash as
/bin/shQuoted 6 lines
What does
a="hello\nhi" echo $aresult in?
So perhaps this one is the troublemaker?
git-am.sh | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
git-am.sh +1 -1
@@ -330,7 +330,7 @@ do SUBJECT="$(sed -n '/^Subject/ s/Subject: //p' "$dotest/info")" case "$keep_subject" in -k) SUBJECT="[PATCH] $SUBJECT" ;; esac - (echo "$SUBJECT" ; echo ; cat "$dotest/msg") | + (printf '%s\n' "$SUBJECT" ; echo ; cat "$dotest/msg") | git stripspace > "$dotest/msg-clean" ;; esac
git-am.sh do · line 333
Quoted 3 lines · Junio C Hamano
git-am.sh +1
-1- (echo "$SUBJECT" ; echo ; cat "$dotest/msg") | + (printf '%s\n' "$SUBJECT" ; echo ; cat "$dotest/msg") |
Well, get rid of the superfluous second 'echo' then too, replacing it with another '\n'. IOW:
( printf '%s\n\n' "$SUBJECT" ; cat "$dotest/msg" ) |
instead.
Linus
2008/4/18, Linus Torvalds <[email protected]>:
Quoted 8 lines · Junio C Hamano
git-am.sh do · line 333
Quoted 3 lines
git-am.sh +1
-1- (echo "$SUBJECT" ; echo ; cat "$dotest/msg") | + (printf '%s\n' "$SUBJECT" ; echo ; cat "$dotest/msg") |
Quoted 6 lines
Well, get rid of the superfluous second 'echo' then too, replacing it
with another '\n'. IOW:( printf '%s\n\n' "$SUBJECT" ; cat "$dotest/msg" ) |instead.
This work for me: no more test failure on my computer
Quoted 9 lines · Rémi Vanicat
2008/4/18, Linus Torvalds <[email protected]>:
Quoted 8 lines · Junio C Hamano
Quoted 3 lines
git-am.sh +1
-1- (echo "$SUBJECT" ; echo ; cat "$dotest/msg") | + (printf '%s\n' "$SUBJECT" ; echo ; cat "$dotest/msg") |
Quoted 8 lines
Quoted 6 lines
Well, get rid of the superfluous second 'echo' then too, replacing it
with another '\n'. IOW:( printf '%s\n\n' "$SUBJECT" ; cat "$dotest/msg" ) |instead.
This work for me: no more test failure on my computer
Thanks for confirmation. I reproduced the breakage and the fix myself with "make SHELL_PATH=/bin/dash" myself, too.