{"thread":{"id":"18929","subject":"[PATCH] Work around ash \"alternate value\" expansion bug","startedAt":"2009-04-18T08:47:39Z","lastAt":"2009-04-19T04:38:17Z","messageCount":4,"participants":["Ben Jackson","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"111564","messageId":"1240044459-57227-1-git-send-email-ben@ben.com","threadId":"18929","inReplyTo":null,"subject":"[PATCH] Work around ash \"alternate value\" expansion bug","fromName":"Ben Jackson","fromEmail":"ben@ben.com","sentAt":"2009-04-18T08:47:39Z","receivedAt":"2009-04-18T08:47:39Z","isPatch":true,"sender":{"key":"ben@ben.com","avatar":"https://gravatar.com/avatar/df49904dd23b03a5f57d9d53c0bf9fb6f69a14fac075c98f54f26cf1ce960794?d=mp&s=160"},"body":"Ash (used as /bin/sh on many distros) has a shell expansion bug\nfor the form ${var:+word word}.  The result is a single argument\n\"word word\".  Work around by using ${var:+word} ${var:+word} or\nequivalent.\n\nSigned-off-by: Ben Jackson <ben@ben.com>\n---\n\nI found this by accident while testing another trivial git-am patch.\nIt was broken about a week ago in git-am.sh by f79d4c8a and one of the\ntest cases caught it on FreeBSD.\n\nThe other instance has been around longer and I found it by grepping.\nI added a new testcase (none too exciting) which exposes the problem.\nThere are more instances of ${x:+alt} which don't have spaces which I\ndid not touch.\n\nFor the curious:\n\nbash on linux:\n\t$ parent=ok\n\t$ echo ${parent:+-p $parent}\n\t-p ok\n\t$ for i in ${parent:+-p $parent} ; do echo .$i; done\n\t.-p\n\t.ok\n\nash (/bin/sh) on freebsd:\n\t$ parent=ok\n\t$ echo ${parent:+-p $parent}\n\t-p ok\n\t$ for i in ${parent:+-p $parent} ; do echo .$i; done\n\t.-p ok\n\nThis is probably a bug in ash.  It does expand ${foo:+*} into many words.\n\n git-am.sh                  |    2 +-\n git-submodule.sh           |    2 +-\n t/t7400-submodule-basic.sh |    8 ++++++++\n 3 files changed, 10 insertions(+), 2 deletions(-)\n\ndiff --git a/git-am.sh b/git-am.sh\nindex bfc50c9..e539c60 100755\n--- a/git-am.sh\n+++ b/git-am.sh\n@@ -570,7 +570,7 @@ do\n \t\t\tGIT_COMMITTER_DATE=\"$GIT_AUTHOR_DATE\"\n \t\t\texport GIT_COMMITTER_DATE\n \t\tfi &&\n-\t\tgit commit-tree $tree ${parent:+-p $parent} <\"$dotest/final-commit\"\n+\t\tgit commit-tree $tree ${parent:+-p} $parent <\"$dotest/final-commit\"\n \t) &&\n \tgit update-ref -m \"$GIT_REFLOG_ACTION: $FIRSTLINE\" HEAD $commit $parent ||\n \tstop_here $this\ndiff --git a/git-submodule.sh b/git-submodule.sh\nindex 7c2e060..bb3766d 100755\n--- a/git-submodule.sh\n+++ b/git-submodule.sh\n@@ -204,7 +204,7 @@ cmd_add()\n \telse\n \n \t\tmodule_clone \"$path\" \"$realrepo\" || exit\n-\t\t(unset GIT_DIR; cd \"$path\" && git checkout -f -q ${branch:+-b \"$branch\" \"origin/$branch\"}) ||\n+\t\t(unset GIT_DIR; cd \"$path\" && git checkout -f -q ${branch:+-b} ${branch:+\"$branch\"} ${branch:+\"origin/$branch\"}) ||\n \t\tdie \"Unable to checkout submodule '$path'\"\n \tfi\n \ndiff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh\nindex af690ec..3c05c27 100755\n--- a/t/t7400-submodule-basic.sh\n+++ b/t/t7400-submodule-basic.sh\n@@ -64,6 +64,14 @@ test_expect_success 'submodule add' '\n \t)\n '\n \n+test_expect_success 'submodule add --branch' '\n+\t(\n+\t\tcd addtest &&\n+\t\tgit submodule add -b initial \"$submodurl\" submod-branch &&\n+\t\tgit submodule init\n+\t)\n+'\n+\n test_expect_success 'submodule add with ./ in path' '\n \t(\n \t\tcd addtest &&\n-- \n1.6.0.1\n"},{"id":"111608","messageId":"7vfxg5x199.fsf@gitster.siamese.dyndns.org","threadId":"18929","inReplyTo":"1240044459-57227-1-git-send-email-ben@ben.com","subject":"Re: [PATCH] Work around ash \"alternate value\" expansion bug","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-04-18T18:30:58Z","receivedAt":"2009-04-18T18:30:58Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Ben Jackson <ben@ben.com> writes:\n\n> Ash (used as /bin/sh on many distros) has a shell expansion bug\n> for the form ${var:+word word}.  The result is a single argument\n> \"word word\".  Work around by using ${var:+word} ${var:+word} or\n> equivalent.\n>\n> Signed-off-by: Ben Jackson <ben@ben.com>\n> ---\n>\n> I found this by accident while testing another trivial git-am patch.\n> It was broken about a week ago in git-am.sh by f79d4c8a and one of the\n> test cases caught it on FreeBSD.\n>\n> The other instance has been around longer and I found it by grepping.\n> I added a new testcase (none too exciting) which exposes the problem.\n> There are more instances of ${x:+alt} which don't have spaces which I\n> did not touch.\n>\n> For the curious:\n>\n> bash on linux:\n> \t$ parent=ok\n> \t$ echo ${parent:+-p $parent}\n> \t-p ok\n> \t$ for i in ${parent:+-p $parent} ; do echo .$i; done\n> \t.-p\n> \t.ok\n>\n> ash (/bin/sh) on freebsd:\n> \t$ parent=ok\n> \t$ echo ${parent:+-p $parent}\n> \t-p ok\n> \t$ for i in ${parent:+-p $parent} ; do echo .$i; done\n> \t.-p ok\n>\n> This is probably a bug in ash.  It does expand ${foo:+*} into many words.\n>\n>  git-am.sh                  |    2 +-\n>  git-submodule.sh           |    2 +-\n>  t/t7400-submodule-basic.sh |    8 ++++++++\n>  3 files changed, 10 insertions(+), 2 deletions(-)\n>\n> diff --git a/git-am.sh b/git-am.sh\n> index bfc50c9..e539c60 100755\n> --- a/git-am.sh\n> +++ b/git-am.sh\n> @@ -570,7 +570,7 @@ do\n>  \t\t\tGIT_COMMITTER_DATE=\"$GIT_AUTHOR_DATE\"\n>  \t\t\texport GIT_COMMITTER_DATE\n>  \t\tfi &&\n> -\t\tgit commit-tree $tree ${parent:+-p $parent} <\"$dotest/final-commit\"\n> +\t\tgit commit-tree $tree ${parent:+-p} $parent <\"$dotest/final-commit\"\n>  \t) &&\n>  \tgit update-ref -m \"$GIT_REFLOG_ACTION: $FIRSTLINE\" HEAD $commit $parent ||\n>  \tstop_here $this\n\nI do not mind this one, but\n\n> diff --git a/git-submodule.sh b/git-submodule.sh\n> index 7c2e060..bb3766d 100755\n> --- a/git-submodule.sh\n> +++ b/git-submodule.sh\n> @@ -204,7 +204,7 @@ cmd_add()\n>  \telse\n>  \n>  \t\tmodule_clone \"$path\" \"$realrepo\" || exit\n> -\t\t(unset GIT_DIR; cd \"$path\" && git checkout -f -q ${branch:+-b \"$branch\" \"origin/$branch\"}) ||\n> +\t\t(unset GIT_DIR; cd \"$path\" && git checkout -f -q ${branch:+-b} ${branch:+\"$branch\"} ${branch:+\"origin/$branch\"}) ||\n\nthis is too ugly to live in our codebase, and without an accompanying code\ncomment, I am sure somebody (if not myself) will \"fix\" it again.\n\n\t(\n        \tunset GIT_DIR\n\t\tcd \"$path\" &&\n\t\t# BSD ash mishandles ${branch:+-b \"$branch\" ...}, sheesh.\n                case \"$branch\" in\n                '')\tgit checkout -f -q ;;\n                ?*)\tgit checkout -f -q -b \"$branch\" \"origin/$branch\" ;;\n                esac\n\t) ||\n\t...\n"},{"id":"111628","messageId":"1240112527-79979-1-git-send-email-ben@ben.com","threadId":"18929","inReplyTo":"1240044459-57227-1-git-send-email-ben@ben.com","subject":"[PATCH v2] Work around ash \"alternate value\" expansion bug","fromName":"Ben Jackson","fromEmail":"ben@ben.com","sentAt":"2009-04-19T03:42:07Z","receivedAt":"2009-04-19T03:42:07Z","isPatch":true,"sender":{"key":"ben@ben.com","avatar":"https://gravatar.com/avatar/df49904dd23b03a5f57d9d53c0bf9fb6f69a14fac075c98f54f26cf1ce960794?d=mp&s=160"},"body":"Ash (used as /bin/sh on many distros) has a shell expansion bug\nfor the form ${var:+word word}.  The result is a single argument\n\"word word\".  Work around by using ${var:+word} ${var:+word} or\nequivalent.\n\nSigned-off-by: Ben Jackson <ben@ben.com>\n---\n\nSee http://thread.gmane.org/gmane.comp.version-control.git/116816 for\nthe original notes which describe the problem in more detail.\n\nThis version uses a different workaround suggested by Junio for\ngit-submodule which is less likely to be \"cleaned up\" back to the\noriginal problem.  Since new the change is more complex I beefed\nup the new test slightly to ensure we are getting into the right case.\n\n git-am.sh                  |    2 +-\n git-submodule.sh           |   11 +++++++++--\n t/t7400-submodule-basic.sh |   10 ++++++++++\n 3 files changed, 20 insertions(+), 3 deletions(-)\n\ndiff --git a/git-am.sh b/git-am.sh\nindex bfc50c9..e539c60 100755\n--- a/git-am.sh\n+++ b/git-am.sh\n@@ -570,7 +570,7 @@ do\n \t\t\tGIT_COMMITTER_DATE=\"$GIT_AUTHOR_DATE\"\n \t\t\texport GIT_COMMITTER_DATE\n \t\tfi &&\n-\t\tgit commit-tree $tree ${parent:+-p $parent} <\"$dotest/final-commit\"\n+\t\tgit commit-tree $tree ${parent:+-p} $parent <\"$dotest/final-commit\"\n \t) &&\n \tgit update-ref -m \"$GIT_REFLOG_ACTION: $FIRSTLINE\" HEAD $commit $parent ||\n \tstop_here $this\ndiff --git a/git-submodule.sh b/git-submodule.sh\nindex 7c2e060..8e234a4 100755\n--- a/git-submodule.sh\n+++ b/git-submodule.sh\n@@ -204,8 +204,15 @@ cmd_add()\n \telse\n \n \t\tmodule_clone \"$path\" \"$realrepo\" || exit\n-\t\t(unset GIT_DIR; cd \"$path\" && git checkout -f -q ${branch:+-b \"$branch\" \"origin/$branch\"}) ||\n-\t\tdie \"Unable to checkout submodule '$path'\"\n+\t\t(\n+\t\t\tunset GIT_DIR\n+\t\t\tcd \"$path\" &&\n+\t\t\t# ash fails to wordsplit ${branch:+-b \"$branch\"...}\n+\t\t\tcase \"$branch\" in\n+\t\t\t'') git checkout -f -q ;;\n+\t\t\t?*) git checkout -f -q -b \"$branch\" \"origin/$branch\" ;;\n+\t\t\tesac\n+\t\t) || die \"Unable to checkout submodule '$path'\"\n \tfi\n \n \tgit add \"$path\" ||\ndiff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh\nindex af690ec..0f2ccc6 100755\n--- a/t/t7400-submodule-basic.sh\n+++ b/t/t7400-submodule-basic.sh\n@@ -64,6 +64,16 @@ test_expect_success 'submodule add' '\n \t)\n '\n \n+test_expect_success 'submodule add --branch' '\n+\t(\n+\t\tcd addtest &&\n+\t\tgit submodule add -b initial \"$submodurl\" submod-branch &&\n+\t\tgit submodule init &&\n+\t\tcd submod-branch &&\n+\t\tgit branch | grep initial\n+\t)\n+'\n+\n test_expect_success 'submodule add with ./ in path' '\n \t(\n \t\tcd addtest &&\n-- \n1.6.0.1\n"},{"id":"111629","messageId":"7vws9hs1fq.fsf@gitster.siamese.dyndns.org","threadId":"18929","inReplyTo":"1240112527-79979-1-git-send-email-ben@ben.com","subject":"Re: [PATCH v2] Work around ash \"alternate value\" expansion bug","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-04-19T04:38:17Z","receivedAt":"2009-04-19T04:38:17Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Thanks, looks good.\n"}]}