Re: Corner case bug caused by shell dependent behavior

2014-03-14 Thread David Kastrup
Jeff King p...@peff.net writes:

 Hmph. We ran into this before and fixed all of the sites (e.g., d1c3b10
 and 938791c). This one appears to have been added a few months later
 (by 68d5d03).

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

 FWIW, I just looked through the other uses of echo in git-rebase*.sh,
 and I think this is the only problematic case.

 -echo $sha1 $action $prefix $rest
 +printf %s %s %s %s\n $sha1 $action $prefix 
 $rest

 Looks obviously correct. The echo just below here does not need the same
 treatment, as $rest is the problematic bit ($prefix is always
 fixup or squash).

I'd not rationalize this away by deep analysis.  Copypaste is a thing,
so to just use printf whenever _any_ seriously variable strings (source
not immediately the shell script itself, perhaps even _any_ nonconstant
strings) are involved keeps people from introducing bugs by following
apparent practice.

-- 
David Kastrup
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: Corner case bug caused by shell dependent behavior

2014-03-14 Thread Uwe Storbeck
On Mar 13, Jonathan Nieder wrote:
 May we have your sign-off?  (See Documentation/SubmittingPatches
 section Sign your work for what this means.

I could have found that myself .. thanks! I'll try to follow it
now. :)
I'll resend the patch. Hopefully I'll do it right.

 Would it make sense to add this as a test to e.g.
 t/t3404-rebase-interactive.sh?

It's a rather special case, so I'm not sure if it's worth it.
I'll send a patch which adds a test for it. The test works for
me, but as I don't understand the test mechanisms already good
enough a few questions:

- Is it correct to call the fake editor with an empty variable
  FAKE_LINES when you want it to not change the todo list of a
  rebase -i and use it as it is (the work is already done by the
  autosquash option)? I can achieve the same with EDITOR=true.
  What's the preferred way? Is there an advantage to use the fake
  editor also in this case?
- The tests in t3404-rebase-interactive.sh use their variables
  a bit differently, some just set the variables, some export
  the variables and some use a subshell to encapsulate them.
  Also some of the tests reset their rebase state so that
  subsequent tests, which also use rebase, do not fail when the
  rebase fails. Other tests don't do that.
  What's the expected resp. recommended behavior?

While trying to understand the test mechanisms I stumbled over
two other problematic uses of echo. These although only affect
the test output, not git itself.

Uwe
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Corner case bug caused by shell dependent behavior

2014-03-13 Thread Uwe Storbeck
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 -mthis 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
From 53262bc8a7a3ec9d9a6b0e8ecaaea598257b87fe Mon Sep 17 00:00:00 2001
From: Uwe Storbeck u...@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 -mthis 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



Re: Corner case bug caused by shell dependent behavior

2014-03-13 Thread Jonathan Nieder
Hi,

Uwe Storbeck wrote:

 To reproduce the behavior (with dash as /bin/sh):

   mkdir test  cd test  git init
   echo 1 foo  git add foo
   git commit -mthis 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.

Would it make sense to add this as a test to e.g.
t/t3404-rebase-interactive.sh?

 The attached one-line patch fixes the bug.

May we have your sign-off?  (See Documentation/SubmittingPatches
section Sign your work for what this means.

Looks obviously correct, so for what it's worth,
Reviewed-by: Jonathan Nieder jrnie...@gmail.com

Thanks,
Jonathan
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: Corner case bug caused by shell dependent behavior

2014-03-13 Thread Jeff King
On Fri, Mar 14, 2014 at 01:02:13AM +0100, Uwe Storbeck wrote:

 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 -mthis commit message ends with '\n'
   echo 2 foo  git commit -a --fixup HEAD
   git rebase -i --autosquash --root

Hmph. We ran into this before and fixed all of the sites (e.g., d1c3b10
and 938791c). This one appears to have been added a few months later
(by 68d5d03).

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

FWIW, I just looked through the other uses of echo in git-rebase*.sh,
and I think this is the only problematic case.

 - echo $sha1 $action $prefix $rest
 + printf %s %s %s %s\n $sha1 $action $prefix 
 $rest

Looks obviously correct. The echo just below here does not need the same
treatment, as $rest is the problematic bit ($prefix is always
fixup or squash).

-Peff
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html