Thread (19 messages) 19 messages, 4 authors, 2019-12-31

Re: [PATCH v2 1/3] t: fix quotes tests for --pathspec-from-file

From: Eric Sunshine <hidden>
Date: 2019-12-30 21:56:13

On Mon, Dec 30, 2019 at 2:15 PM Alexandr Miloslavskiy via GitGitGadget
[off-list ref] wrote:
quoted hunk ↗ jump to hunk
While working on the next patch, I also noticed that quotes testing via
`"\"file\\101.t\""` was somewhat incorrect: I escaped `\` one time while
I had to escape it two times! Tests still worked due to `"` being
preserved which in turn prevented pathspec from matching files.

Fix this by properly escaping one more time.

Signed-off-by: Alexandr Miloslavskiy <redacted>
---
diff --git a/t/t2026-checkout-pathspec-file.sh b/t/t2026-checkout-pathspec-file.sh
@@ -109,7 +109,10 @@ test_expect_success 'CRLF delimiters' '
-       printf "\"file\\101.t\"" | git checkout --pathspec-from-file=- HEAD^1 &&
+       # shell  takes \\\\101 and spits \\101
+       # printf takes   \\101 and spits  \101
+       # git    takes    \101 and spits     A
+       printf "\"file\\\\101.t\"" | git checkout --pathspec-from-file=- HEAD^1 &&
So, you want git-checkout to receive the following, quotes, backslash,
and no newline, on its standard input?

    "file\101.t"

If so, another way to achieve the same without taxing the brain of the
reader or the next person who works on this code would be:

    tr -d "\012" | git checkout --pathspec-from-file=- HEAD^1 <<-\EOF &&
    "file\101.t"
    EOF

Although it's three lines long, the body of the here-doc is the
literal text you want sent to the Git command, so no counting
backslashes, and no need for a lengthy in-code comment.

But is the "no newline" bit indeed intentional? If not, then a simple
echo would be even easier (though with a bit more escaping):

    echo "\"file\101.t\"" | git checkout --pathspec-from-file=- HEAD^1 &&
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help