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

Re: [PATCH] git-am: add --directory=<dir> option

From
Junio C Hamano <gitster@pobox.com>
Date
Jan 15, 2009, 00:21 UTC
Message-ID
<7vzlhtxvu5.fsf@gitster.siamese.dyndns.org>
In-Reply-To
<20090114234602.GD32313@leksak.fem-net>
Stephan Beyer <s-beyer@gmx.net> writes:
Show 5 quoted lines
> Do I have a thinko or should it be this:
>
> +		sed -e 's/'\''/'\''\\\'\'''\''/g' -e 's/.*/ '\''&'\''/'
> 		                   ^^
> 			(added for escaping ' outside single quotes)
Almost.

Certainly my original was bad; shell unquotes to "s/'/'\''/g", but that backslash is not protected from further interpretation by sed, which happily turns backslash-single quote into a single quote, which I forgot.

You feed "s/'/'\\\''/g" which correctly protects one backslash from sed by doubling it, but it has one unnecessary extra backslash. The extra one does not hurt because the backslash + single quote is eaten by sed to produce a single quote, but it is not quite right.

We should be feeding sed with "s/'/'\\''/g", so you need to add one backslash to mine.

> Have you forgotten to add the files prefixed with "am-test-5-" or is this
> patch based on another one?

The one I actually queued is b47dfe9 (git-am: add --directory=<dir> option, 2009-01-11) and it does include these test vectors. My bad.

This patch is relative to b47dfe9.

-- >8 -- Fix git-am shell quoting

Noticed by Stephan Beyer; the new test is mine.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 git-am.sh             |    2 +-
 t/t4252-am-options.sh |    8 ++++++++
 2 files changed, 9 insertions(+), 1 deletions(-)
diff --git c/git-am.sh w/git-am.sh
index 7e6329b..4beb12d 100755
--- c/git-am.sh
+++ w/git-am.sh
@@ -38,7 +38,7 @@ sq () {
 	for sqarg
 	do
 		printf "%s" "$sqarg" |
-		sed -e 's/'\''/'\''\'\'''\''/g' -e 's/.*/ '\''&'\''/'
+		sed -e 's/'\''/'\''\\'\'''\''/g' -e 's/.*/ '\''&'\''/'
 	done
 }
 
diff --git c/t/t4252-am-options.sh w/t/t4252-am-options.sh
index e91a6da..5fdd188 100755
--- c/t/t4252-am-options.sh
+++ w/t/t4252-am-options.sh
@@ -58,4 +58,12 @@ test_expect_success 'interrupted am --directory="frotz nitfol"' '
 	grep One "frotz nitfol/file-5"
 '
 
+test_expect_success 'apply to a funny path' '
+	with_sq="with'\''sq"
+	rm -fr .git/rebase-apply &&
+	git reset --hard initial &&
+	git am --directory="$with_sq" "$tm"/am-test-5-2 &&
+	test -f "$with_sq/file-5"
+'
+
 test_done
Previous: Stephan BeyerNext: Stephan Beyer
Message 3 of 4 in “git-am: add --directory=<dir> option”
  1. git-am: add --directory=<dir> optionJunio C Hamano, Jan 12, 2009
  2. Stephan BeyerJan 14, 2009
  3. Junio C HamanoJan 15, 2009
  4. Stephan BeyerJan 15, 2009

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.