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

Re: [GSOC PATCH] t7003: modernize path existence checks using test helpers

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 9, 2026, 18:11 UTC
Message-ID
<xmqqpl6d4wjh.fsf@gitster.g>
In-Reply-To
<20260209172445.39536-1-valusoutrik@gmail.com>
SoutrikDas <valusoutrik@gmail.com> writes:
Show 37 quoted lines
> Replace direct uses of 'test -f' and 'test -d' with
> git's helper functions 'test_path_is_file' ,
> 'test_path_is_missing' and 'test_path_is_dir'
>
> Signed-off-by: SoutrikDas <valusoutrik@gmail.com>
> ---
>  t/t7003-filter-branch.sh | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/t/t7003-filter-branch.sh b/t/t7003-filter-branch.sh
> index 5ab4d41ee7..c475769858 100755
> --- a/t/t7003-filter-branch.sh
> +++ b/t/t7003-filter-branch.sh
> @@ -92,8 +92,8 @@ test_expect_success 'rewrite, renaming a specific file' '
>  
>  test_expect_success 'test that the file was renamed' '
>  	test D = "$(git show HEAD:doh --)" &&
> -	! test -f D.t &&
> -	test -f doh &&
> +	test_path_is_missing D.t &&
> +	test_path_is_file doh &&
>  	test D = "$(cat doh)"
>  '
> @@ -103,10 +103,10 @@ test_expect_success 'rewrite, renaming a specific directory' '
>  
>  test_expect_success 'test that the directory was renamed' '
>  	test dir/D = "$(git show HEAD:diroh/D.t --)" &&
> -	! test -d dir &&
> -	test -d diroh &&
> -	! test -d diroh/dir &&
> -	test -f diroh/D.t &&
> +	test_path_is_missing dir &&
> +	test_path_is_dir diroh &&
> +	test_path_is_missing diroh/dir &&
> +	test_path_is_file diroh/D.t &&
>  	test dir/D = "$(cat diroh/D.t)"
>  '

All the checks involving "is-missing" are now stricter than the original, in that they used to allow "dir" to exist as long as it is not a directory, etc., but if we audited the code that leads to these tests can never create a "dir" that is a regular file or something that is not a directory (which *I* did *NOT*, but presumably you have already done so?---if so that is worth noting in the proposed log message), then "test ! -d dir" that is rewritten to "test_path_is_missing dir" is actually a _better_ test.

Thanks.
Previous: SoutrikDasNext: SoutrikDas
Message 2 of 4 in “t7003: modernize path existence checks using test helpers”
  1. t7003: modernize path existence checks using test helpersSoutrikDas, Feb 9, 2026
  2. Junio C HamanoFeb 9, 2026
  3. SoutrikDasFeb 10, 2026
  4. t7003: modernize path existence checks using test helpersSoutrikDas, Feb 10, 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.