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

Re: [PATCH 1/1] t1403: prefer test_path_exists helper function

From
Eric Sunshine <sunshine@sunshineco.com>
Date
Mar 4, 2025, 18:07 UTC
Message-ID
<CAPig+cS3QZhZ=W2WfM3T3EngaMOSV37KH4Pqp78QHzOAODtenA@mail.gmail.com>
In-Reply-To
<xmqqcyewr8j7.fsf@gitster.g>
On Tue, Mar 4, 2025 at 12:49 PM Junio C Hamano <gitster@pobox.com> wrote:
Show 20 quoted lines
> Eric Sunshine <sunshine@sunshineco.com> writes:
> > On Tue, Mar 4, 2025 at 7:05 AM Junio C Hamano <gitster@pobox.com> wrote:
> >> Mahendra Dani <danimahendra0904@gmail.com> writes:
> >> >> >       remove_object() {
> >> >> >               file=$(sha1_file "$*") &&
> >> >> > -             test -e "$file" &&
> >> >> > +             test_path_exists "$file" &&
> >> >> >               rm -f "$file"
> >> >> >       } &&
> > That's a good question to ask, but isn't the implied suggestion of
> > dropping "-f" going in the wrong direction? If I'm reading
> > remove_object() correctly, `test -e` is being used as control flow,
> > *not* as an assertion that the file exists.
>
> If sha1_file says the loose object must be at path $file, and the
> call to test -e "$file" returns false, two things happen in this
> function:
>
>  (1) control stops and "rm -f" does not trigger
>  (2) the function returns non-zero status to the caller
True enough. I was misreading `test -e "$file"` as _only_ control flow.

However, it's still not clear to me why this function is making the `test -e "$file"` assertion in the first place or why the enclosing test should care, especially since that assertion is only checking that `git commit` worked correctly, but that's not the intent of this particular test[1]. So, `test -e "$file"` seems pointless or at least misleading.

> If you omit the check and say rm "$file" instead, under the same
> scenario, (1) "rm" is attempted, but there is nothing to remove so
> the command returns non-zero status, and (2) the function returns
> that non-zero status to the caller

Yes, I understood the implication of your suggestion, but as mentioned above, it's not clear (at least to me) why `test -e "$file"` is there at all since this test is not about checking functionality of `git commit`.

[1]: d01b8203ec (show-ref: detect dangling refs under --verify as well, 2017-01-23) doesn't explain why `test -e "$file"` was used.

Previous: Junio C HamanoNext: Eric Sunshine
Message 14 of 31 in “t1403: prefer test_path_exists helper function”
  1. Mahendra DaniMar 1, 2025
  2. 1/1 t1403: prefer test_path_exists helper functionMahendra Dani, Mar 1, 2025
  3. Patrick SteinhardtMar 3, 2025
  4. Mahendra DaniMar 4, 2025
  5. Junio C HamanoMar 4, 2025
  6. Mahendra DaniMar 4, 2025
  7. Junio C HamanoMar 4, 2025
  8. Mahendra DaniMar 4, 2025
  9. Junio C HamanoMar 4, 2025
  10. Mahendra DaniMar 4, 2025
  11. Junio C HamanoMar 4, 2025
  12. Eric SunshineMar 4, 2025
  13. Junio C HamanoMar 4, 2025
  14. Eric SunshineMar 4, 2025
  15. Eric SunshineMar 4, 2025
  16. Junio C HamanoMar 4, 2025
  17. [GSOC][PATCH v2 0/1] t1403: verify path exists and is a fileMahendra Dani, Mar 4, 2025
  18. [GSOC][PATCH v3 0/1] t1403: verify path exists and is a fileMahendra Dani, Mar 4, 2025
  19. 1/1 t1403: verify that path exists and is a fileMahendra Dani, Mar 4, 2025
  20. Junio C HamanoMar 4, 2025
  21. Junio C HamanoMar 4, 2025
  22. Mahendra DaniMar 4, 2025
  23. 0/1 t1403: verify path exists and is a fileMahendra Dani, Mar 4, 2025
  24. 0/1 t1403: verify path exists and is a fileMahendra Dani, Mar 4, 2025
  25. 1/1 t1403: verify that path exists and is a fileMahendra Dani, Mar 4, 2025
  26. Junio C HamanoMar 4, 2025
  27. Mahendra DaniMar 4, 2025
  28. Junio C HamanoMar 4, 2025
  29. 1/1 t1403: verify that path exists and is a fileMahendra Dani, Mar 4, 2025
  30. Patrick SteinhardtMar 4, 2025
  31. Mahendra DaniMar 4, 2025

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.