git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] filter-branch: pass tag name via stdin without newline

From
Eric N. Vander Weele <ericvw@gmail.com>
Date
Dec 7, 2015, 01:17 UTC
Message-ID
<1449451046-19752-1-git-send-email-ericvw@gmail.com>

"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
Next: Junio C Hamano
Message 1 of 4 in “filter-branch: pass tag name via stdin without newline”
  1. filter-branch: pass tag name via stdin without newlineEric N. Vander Weele, Dec 7, 2015
  2. Junio C HamanoDec 7, 2015
  3. Eric Vander WeeleDec 7, 2015
  4. Jeff KingDec 7, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.