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

Re: [PATCH] t3310: avoid hiding failures from rev-parse in command substitutions

From
Eric Sunshine <sunshine@sunshineco.com>
Date
Mar 4, 2026, 22:21 UTC
Message-ID
<CAPig+cTHyB2sbBOELPb2=B5sU69OzSPU0JVn0p=2qMp=0=8vEg@mail.gmail.com>
In-Reply-To
<20260304121955.73794-1-francescopaparatto@gmail.com>

On Wed, Mar 4, 2026 at 7:20 AM Francesco Paparatto <francescopaparatto@gmail.com> wrote:

Show 6 quoted lines
> Running `git` commands inside command substitutions like
>
>     test "$(git rev-parse A)" = "$(git rev-parse B)"
>
> can hide failures from the `git` invocations. Extract the
> `rev-parse` calls into variables so failures are not ignored.
Okay, surfacing failures of `git` invocations is a laudable goal. However...
Show 8 quoted lines
> Signed-off-by: Francesco Paparatto <francescopaparatto@gmail.com>
> ---
> diff --git a/t/t3310-notes-merge-manual-resolve.sh b/t/t3310-notes-merge-manual-resolve.sh
> @@ -227,7 +227,8 @@ test_expect_success 'merge z into m (== y) with default ("manual") resolver => C
> -       test "$(git rev-parse refs/notes/m)" = "$(cat pre_merge_y)"
> +       m=$(git rev-parse refs/notes/m) &&
> +       test "$m" = "$(cat pre_merge_y)"
>  '

...a failure exposed by `test` is not very developer-friendly since it doesn't give any indication about what went wrong. Since the pre-merge value of "y" (and also "z" in subsequent tests) is already in a file, we can make the failure mode much more helpful by using `test_cmp <expect> <actual>` which will show both the expected and actual values when they don't match. Thus, the above transformation would be better stated along these lines:

    git rev-parse refs/notes/m >actual &&
    test_cmp pre_merge_y actual
The same comment applies to other changes in this patch.
Show 12 quoted lines
> @@ -569,13 +580,17 @@ EOF
>         # Refs are unchanged
> -       test "$(git rev-parse refs/notes/m)" = "$(git rev-parse refs/notes/w)" &&
> -       test "$(git rev-parse refs/notes/y)" = "$(git rev-parse NOTES_MERGE_PARTIAL^1)" &&
> -       test "$(git rev-parse refs/notes/m)" != "$(git rev-parse NOTES_MERGE_PARTIAL^1)" &&
> +       m=$(git rev-parse refs/notes/m) &&
> +       w=$(git rev-parse refs/notes/w) &&
> +       y=$(git rev-parse refs/notes/y) &&
> +       p1=$(git rev-parse NOTES_MERGE_PARTIAL^1) &&
> +       test "$m" = "$w" &&
> +       test "$y" = "$p1" &&
> +       test "$m" != "$p1" &&

In this case we can do even better by taking advantage of `test_cmp_rev`, which would allow you to express the above more simply along these lines:

    test_cmp_rev refs/notes/m rev-parse refs/notes/w &&
    test_cmp_rev refs/notes/y NOTES_MERGE_PARTIAL^1 &&
    test_cmp_rev ! refs/notes/m NOTES_MERGE_PARTIAL^1 &&
Note the "!" for negation in the third line.
The same comment applies to other changes in this patch.
Previous: Francesco PaparattoNext: Francesco Paparatto
Message 2 of 15 in “t3310: avoid hiding failures from rev-parse in command substitutions”
  1. t3310: avoid hiding failures from rev-parse in command substitutionsFrancesco Paparatto, Mar 4, 2026
  2. Eric SunshineMar 4, 2026
  3. t3310: avoid hiding failures from rev-parse in command substitutionsFrancesco Paparatto, Mar 5, 2026
  4. Junio C HamanoMar 5, 2026
  5. Eric SunshineMar 5, 2026
  6. Francesco PaparattoMar 5, 2026
  7. Francesco PaparattoMar 5, 2026
  8. t3310: avoid hiding failures from rev-parse in command substitutionsFrancesco Paparatto, Mar 5, 2026
  9. Junio C HamanoMar 5, 2026
  10. Junio C HamanoMar 5, 2026
  11. Eric SunshineMar 7, 2026
  12. Francesco PaparattoMar 7, 2026
  13. t3310: avoid hiding failures from rev-parse in command substitutionsFrancesco Paparatto, Mar 7, 2026
  14. Eric SunshineMar 8, 2026
  15. Junio C HamanoMar 8, 2026

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.