{"thread":{"id":"34548","subject":"subtree split prepends \"-n<newline>\" to commit messages on OS X","startedAt":"2013-07-26T22:47:29Z","lastAt":"2013-07-29T17:07:27Z","messageCount":3,"participants":["Bryan Head","Lukas Fleischer","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"224154","messageId":"CAFM=nTeRpZ=Y-+4KMCZd8Qj-9K105uSquh8Y=7mC3aqJiE0gbQ@mail.gmail.com","threadId":"34548","inReplyTo":null,"subject":"subtree split prepends \"-n<newline>\" to commit messages on OS X","fromName":"Bryan Head","fromEmail":"bryan.head@gmail.com","sentAt":"2013-07-26T22:47:29Z","receivedAt":"2013-07-26T22:47:29Z","isPatch":false,"sender":{"key":"bryan.head@gmail.com","avatar":null},"body":"Looks like this was introduced in 1.8.3.3.\n\nTo reproduce, run\n\ngit init repo\ncd repo\nmkdir splitme\ntouch splitme/foo\ngit add splitme/\ngit commit -m 'Add foo'\ngit subtree split -P splitme -b splitme-only\n\n\nAfter that, I get:\n\n$ git log splitme-only\ncommit 6ce8124a0b5e52d4bba198144d2f3f664d7b19e7\nAuthor: me\nDate:   Fri Jul 26 12:22:27 2013 -0500\n    -n\n    Add foo\n\n\nCompared with the original:\n\n$ git log master\ncommit 6d5164076bd88d1dab8963d91ec013372e58a444\nAuthor: me\nDate:   Fri Jul 26 12:22:27 2013 -0500\n    Add foo\n\n\nNotice how `-n<newline>` has been prepended to the commit message.\n\nThis was introduced when subtree was changed to use `sh` instead of\n`bash`, in this\ncommit:https://github.com/git/git/commit/6912ea952bf5d1b2d21d5935d6b726bab02d8bf6#contrib/subtree/git-subtree.sh\nThis was merged in here:\nhttps://github.com/git/git/commit/779fd737d79a3e19a1aa420c33cf1195c7e20dd7#contrib/subtree/git-subtree.sh\n\nI verified that changing the line in question back to `#!/bin/bash`\neliminates the problem.\n\nI believe that it was caused by the fact that sh echos the \"-n\" in\nthis line: https://github.com/git/git/blob/master/contrib/subtree/git-subtree.sh#L314\n\nNote that this consequently happens when, for instance, using `git\nsubtree push` to push the subtree to an upstream repository.\n\nI'm using OS X 10.8.4. The problem does not occur on Ubuntu at least\nsince Ubuntu's sh is actually dash.\n"},{"id":"224179","messageId":"1374927093-16663-1-git-send-email-git@cryptocrack.de","threadId":"34548","inReplyTo":"CAFM=nTeRpZ=Y-+4KMCZd8Qj-9K105uSquh8Y=7mC3aqJiE0gbQ@mail.gmail.com","subject":"[PATCH] Avoid using `echo -n` anywhere","fromName":"Lukas Fleischer","fromEmail":"git@cryptocrack.de","sentAt":"2013-07-27T12:11:33Z","receivedAt":"2013-07-27T12:11:33Z","isPatch":true,"sender":{"key":"git@cryptocrack.de","avatar":null},"body":"`echo -n` is non-portable. The POSIX specification says:\n\n    Conforming applications that wish to do prompting without <newline>\n    characters or that could possibly be expecting to echo a -n, should\n    use the printf utility derived from the Ninth Edition system.\n\nSince all of the affected shell scripts use a POSIX shell shebang,\nreplace `echo -n` invocations with printf.\n\nSigned-off-by: Lukas Fleischer <git@cryptocrack.de>\n---\n contrib/subtree/git-subtree.sh     | 2 +-\n contrib/subtree/t/t7900-subtree.sh | 8 ++++----\n t/perf/perf-lib.sh                 | 4 ++--\n 3 files changed, 7 insertions(+), 7 deletions(-)\n\ndiff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh\nindex 51ae932..7d7af03 100755\n--- a/contrib/subtree/git-subtree.sh\n+++ b/contrib/subtree/git-subtree.sh\n@@ -311,7 +311,7 @@ copy_commit()\n \t\t\tGIT_COMMITTER_NAME \\\n \t\t\tGIT_COMMITTER_EMAIL \\\n \t\t\tGIT_COMMITTER_DATE\n-\t\t(echo -n \"$annotate\"; cat ) |\n+\t\t(printf \"%s\" \"$annotate\"; cat ) |\n \t\tgit commit-tree \"$2\" $3  # reads the rest of stdin\n \t) || die \"Can't copy commit $1\"\n }\ndiff --git a/contrib/subtree/t/t7900-subtree.sh b/contrib/subtree/t/t7900-subtree.sh\nindex b0f8536..556a94d 100755\n--- a/contrib/subtree/t/t7900-subtree.sh\n+++ b/contrib/subtree/t/t7900-subtree.sh\n@@ -182,9 +182,9 @@ test_expect_success 'merge new subproj history into subdir' '\n test_expect_success 'Check that prefix argument is required for split' '\n         echo \"You must provide the --prefix option.\" > expected &&\n         test_must_fail git subtree split > actual 2>&1 &&\n-        test_debug \"echo -n expected: \" &&\n+        test_debug \"printf '\"'\"'expected: '\"'\"'\" &&\n         test_debug \"cat expected\" &&\n-        test_debug \"echo -n actual: \" &&\n+        test_debug \"printf '\"'\"'actual: '\"'\"'\" &&\n         test_debug \"cat actual\" &&\n         test_cmp expected actual &&\n         rm -f expected actual\n@@ -193,9 +193,9 @@ test_expect_success 'Check that prefix argument is required for split' '\n test_expect_success 'Check that the <prefix> exists for a split' '\n         echo \"'\"'\"'non-existent-directory'\"'\"'\" does not exist\\; use \"'\"'\"'git subtree add'\"'\"'\" > expected &&\n         test_must_fail git subtree split --prefix=non-existent-directory > actual 2>&1 &&\n-        test_debug \"echo -n expected: \" &&\n+        test_debug \"printf '\"'\"'expected: '\"'\"'\" &&\n         test_debug \"cat expected\" &&\n-        test_debug \"echo -n actual: \" &&\n+        test_debug \"printf '\"'\"'actual: '\"'\"'\" &&\n         test_debug \"cat actual\" &&\n         test_cmp expected actual\n #        rm -f expected actual\ndiff --git a/t/perf/perf-lib.sh b/t/perf/perf-lib.sh\nindex c61d535..ae44117 100644\n--- a/t/perf/perf-lib.sh\n+++ b/t/perf/perf-lib.sh\n@@ -161,7 +161,7 @@ test_perf () {\n \t\techo \"$test_count\" >>\"$perf_results_dir\"/$base.subtests\n \t\techo \"$1\" >\"$perf_results_dir\"/$base.$test_count.descr\n \t\tif test -z \"$verbose\"; then\n-\t\t\techo -n \"perf $test_count - $1:\"\n+\t\t\tprintf \"%s\" \"perf $test_count - $1:\"\n \t\telse\n \t\t\techo \"perf $test_count - $1:\"\n \t\tfi\n@@ -170,7 +170,7 @@ test_perf () {\n \t\t\tif test_run_perf_ \"$2\"\n \t\t\tthen\n \t\t\t\tif test -z \"$verbose\"; then\n-\t\t\t\t\techo -n \" $i\"\n+\t\t\t\t\tprintf \" %d\" \"$i\"\n \t\t\t\telse\n \t\t\t\t\techo \"* timing run $i/$GIT_PERF_REPEAT_COUNT:\"\n \t\t\t\tfi\n-- \n1.8.3.3.1135.ge2c9e63\n"},{"id":"224235","messageId":"7vr4ehz44w.fsf@alter.siamese.dyndns.org","threadId":"34548","inReplyTo":"1374927093-16663-1-git-send-email-git@cryptocrack.de","subject":"Re: [PATCH] Avoid using `echo -n` anywhere","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-07-29T17:07:27Z","receivedAt":"2013-07-29T17:07:27Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Lukas Fleischer <git@cryptocrack.de> writes:\n\n> `echo -n` is non-portable. The POSIX specification says:\n>\n>     Conforming applications that wish to do prompting without <newline>\n>     characters or that could possibly be expecting to echo a -n, should\n>     use the printf utility derived from the Ninth Edition system.\n>\n> Since all of the affected shell scripts use a POSIX shell shebang,\n> replace `echo -n` invocations with printf.\n>\n> Signed-off-by: Lukas Fleischer <git@cryptocrack.de>\n> ...\n> diff --git a/t/perf/perf-lib.sh b/t/perf/perf-lib.sh\n> index c61d535..ae44117 100644\n> --- a/t/perf/perf-lib.sh\n> +++ b/t/perf/perf-lib.sh\n> @@ -161,7 +161,7 @@ test_perf () {\n>  \t\techo \"$test_count\" >>\"$perf_results_dir\"/$base.subtests\n>  \t\techo \"$1\" >\"$perf_results_dir\"/$base.$test_count.descr\n>  \t\tif test -z \"$verbose\"; then\n> -\t\t\techo -n \"perf $test_count - $1:\"\n> +\t\t\tprintf \"%s\" \"perf $test_count - $1:\"\n>  \t\telse\n>  \t\t\techo \"perf $test_count - $1:\"\n>  \t\tfi\n> @@ -170,7 +170,7 @@ test_perf () {\n>  \t\t\tif test_run_perf_ \"$2\"\n>  \t\t\tthen\n>  \t\t\t\tif test -z \"$verbose\"; then\n> -\t\t\t\t\techo -n \" $i\"\n> +\t\t\t\t\tprintf \" %d\" \"$i\"\n\nI'd prefer to see '%s' here; it is more faithful transliteration\nfrom \"echo -n\".\n\nThanks, will queue with the above tweak.\n\n>  \t\t\t\telse\n>  \t\t\t\t\techo \"* timing run $i/$GIT_PERF_REPEAT_COUNT:\"\n>  \t\t\t\tfi\n"}]}