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

Re: [PATCH] replace test -f with test_path_is_file

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 19, 2021, 18:04 UTC
Message-ID
<xmqqr1kbm34j.fsf@gitster.g>
In-Reply-To
<pull.982.git.git.1616147527082.gitgitgadget@gmail.com>
"Krushnal Patel via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 8 quoted lines
> From: krush11 <krushnalpatel11@gmail.com>
>
> Although  has the same functionality as test_path_is_file(), in
> the case where test_path_is_file() fails, we get much better debugging
> information.
>
> Replace  with test_path_is_file so that future developers
> will have a better experience debugging these test cases.

While this change is not wrong per-se, in the context of this test script, I think the original use of "test -f" is not quite right to begin with. These are all "even after running 'git clean', these paths should exist without getting removed by mistake", so the intent of these "test -f" invocations are actually "test -e".

Similarly, the invocations of "test ! -f" we see (and there also is at least one "! test -d") mean to say "these paths should be gone as the result of running 'git clean'". If by some accident a directory exists at the path that is checked with "test ! -f" due to a bug in 'git clean', these tests will not catch such a bug, because a directory does not pass "test -f".

So most likely these negative tests this patch does not convert are better off being spelled as "! test -e", too.

It would be more appropriate to use test_path_exists and test_path_is_missing to replace these "must exist as a file" and "must not exist as a file".

Thanks.
Previous: Krushnal Patel via GitGitGadgetNext: Krushnal Patel via GitGitGadget
Message 2 of 6 in “replace test -f with test_path_is_file”
  1. replace test -f with test_path_is_fileKrushnal Patel via GitGitGadget, Mar 19, 2021
  2. Junio C HamanoMar 19, 2021
  3. 0/2 replace test -f with test_path_is_fileKrushnal Patel via GitGitGadget, Mar 19, 2021
  4. 1/2 replace test -f with test_path_is_filekrush11 via GitGitGadget, Mar 19, 2021
  5. 2/2 replaced test -f and test ! -fkrush11 via GitGitGadget, Mar 19, 2021
  6. Junio C HamanoMar 19, 2021

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.