git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Eric N. Vander Weele" <ericvw@gmail.com>
To: git@vger.kernel.org
Cc: johannes.schindelin@gmx.de
Subject: [PATCH] filter-branch: pass tag name via stdin without newline
Date: Sun,  6 Dec 2015 17:17:26 -0800	[thread overview]
Message-ID: <1449451046-19752-1-git-send-email-ericvw@gmail.com> (raw)

"git filter-branch --tag-name-filter" fails when the user-provided
command attempts to trivially append text to the originally tag name,
passed via stdin, due to an unexpected newline ('\n').  The newline is
introduced due to "echo" piping the original tag name to the
user-provided tag name filter command.

The only portable usage of "echo" is without any options and escape
sequences.  Therefore, replacing "echo" with "printf" is a suitable,
POSIX compliant alternative.

Signed-off-by: Eric N. Vander Weele <ericvw@gmail.com>
---
 git-filter-branch.sh     | 2 +-
 t/t7003-filter-branch.sh | 5 +++++
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/git-filter-branch.sh b/git-filter-branch.sh
index 98f1779..949cd30 100755
--- a/git-filter-branch.sh
+++ b/git-filter-branch.sh
@@ -503,7 +503,7 @@ if [ "$filter_tag_name" ]; then
 		new_sha1="$(cat "../map/$sha1")"
 		GIT_COMMIT="$sha1"
 		export GIT_COMMIT
-		new_ref="$(echo "$ref" | eval "$filter_tag_name")" ||
+		new_ref="$(printf "$ref" | eval "$filter_tag_name")" ||
 			die "tag name filter failed: $filter_tag_name"
 
 		echo "$ref -> $new_ref ($sha1 -> $new_sha1)"
diff --git a/t/t7003-filter-branch.sh b/t/t7003-filter-branch.sh
index 869e0bf..0db6808 100755
--- a/t/t7003-filter-branch.sh
+++ b/t/t7003-filter-branch.sh
@@ -269,6 +269,11 @@ test_expect_success 'Tag name filtering retains tag message' '
 	test_cmp expect actual
 '
 
+test_expect_success 'Tag name filter does not pass tag ref with newline' '
+	git filter-branch -f --tag-name-filter "cat && printf "_append"" -- A &&
+	git rev-parse A_append > /dev/null 2>&1
+'
+
 faux_gpg_tag='object XXXXXX
 type commit
 tag S
-- 
2.6.3

             reply	other threads:[~2015-12-07  1:17 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-07  1:17 Eric N. Vander Weele [this message]
2015-12-07  2:55 ` [PATCH] filter-branch: pass tag name via stdin without newline Junio C Hamano
2015-12-07  5:15   ` Eric Vander Weele
2015-12-07 20:44   ` Jeff King

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1449451046-19752-1-git-send-email-ericvw@gmail.com \
    --to=ericvw@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=johannes.schindelin@gmx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).