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

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

From
Eric Sunshine <sunshine@sunshineco.com>
Date
Dec 30, 2019, 21:55 UTC
Message-ID
<CAPig+cSSqAxuHYg9DxuJzC7m2HAt8F2YPNxT0x5+SksCGic4MA@mail.gmail.com>
In-Reply-To
<6193dc7396b9cc6cb78f382c1b1679d6bb455fe4.1577733329.git.gitgitgadget@gmail.com>

On Mon, Dec 30, 2019 at 2:15 PM Alexandr Miloslavskiy via GitGitGadget <gitgitgadget@gmail.com> wrote:

Show 16 quoted lines
> 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 <alexandr.miloslavskiy@syntevo.com>
> ---
> 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 &&
Previous: Alexandr Miloslavskiy via GitGitGadgetNext: Jonathan Nieder
Message 10 of 26 in “t: rework tests for --pathspec-from-file”
  1. 0/3 t: rework tests for --pathspec-from-fileAlexandr Miloslavskiy via GitGitGadget, Dec 30, 2019
  2. 1/3 t: fix quotes tests for --pathspec-from-fileAlexandr Miloslavskiy via GitGitGadget, Dec 30, 2019
  3. 2/3 t: directly test parse_pathspec_file()Alexandr Miloslavskiy via GitGitGadget, Dec 30, 2019
  4. Junio C HamanoDec 30, 2019
  5. Alexandr MiloslavskiyDec 30, 2019
  6. 3/3 t: drop copy&pasted tests for --pathspec-from-fileAlexandr Miloslavskiy via GitGitGadget, Dec 30, 2019
  7. 0/3 t: rework tests for --pathspec-from-fileAlexandr Miloslavskiy via GitGitGadget, Dec 30, 2019
  8. 2/3 t: directly test parse_pathspec_file()Alexandr Miloslavskiy via GitGitGadget, Dec 30, 2019
  9. 1/3 t: fix quotes tests for --pathspec-from-fileAlexandr Miloslavskiy via GitGitGadget, Dec 30, 2019
  10. Eric SunshineDec 30, 2019
  11. Jonathan NiederDec 31, 2019
  12. Alexandr MiloslavskiyDec 31, 2019
  13. 3/3 t: drop copy&pasted tests for --pathspec-from-fileAlexandr Miloslavskiy via GitGitGadget, Dec 30, 2019
  14. 0/3 t: rework tests for --pathspec-from-fileAlexandr Miloslavskiy via GitGitGadget, Dec 31, 2019
  15. 2/3 t: directly test parse_pathspec_file()Alexandr Miloslavskiy via GitGitGadget, Dec 31, 2019
  16. 1/3 t: fix quotes tests for --pathspec-from-fileAlexandr Miloslavskiy via GitGitGadget, Dec 31, 2019
  17. 3/3 t: drop copy&pasted tests for --pathspec-from-fileAlexandr Miloslavskiy via GitGitGadget, Dec 31, 2019
  18. 0/3 t: rework tests for --pathspec-from-fileAlexandr Miloslavskiy via GitGitGadget, Dec 31, 2019
  19. 1/3 t: fix quotes tests for --pathspec-from-fileAlexandr Miloslavskiy via GitGitGadget, Dec 31, 2019
  20. 2/3 t: directly test parse_pathspec_file()Alexandr Miloslavskiy via GitGitGadget, Dec 31, 2019
  21. 3/3 t: drop copy&pasted tests for --pathspec-from-fileAlexandr Miloslavskiy via GitGitGadget, Dec 31, 2019
  22. Junio C HamanoJan 7, 2020
  23. Alexandr MiloslavskiyJan 8, 2020
  24. Junio C HamanoJan 8, 2020
  25. Alexandr MiloslavskiyJan 8, 2020
  26. Junio C HamanoJan 8, 2020

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.