* [PATCH 1/1] t: update path checks using test_path helpers
@ 2025-10-14 16:14 Solly
2025-10-14 18:19 ` Junio C Hamano
2025-10-15 14:03 ` [PATCH v2 0/1] *** t2401: update path checks using test_path helpers *** Solly
0 siblings, 2 replies; 7+ messages in thread
From: Solly @ 2025-10-14 16:14 UTC (permalink / raw)
To: git; +Cc: Solly
Update old-style shell path checks to use the modern test
helpers 'test_path_is_file' and 'test_path_is_dir' for improved
readability.
Signed-off-by: Solly <solobarine@gmail.com>
---
t/t2401-worktree-prune.sh | 34 +++++++++++++++++-----------------
1 file changed, 17 insertions(+), 17 deletions(-)
diff --git a/t/t2401-worktree-prune.sh b/t/t2401-worktree-prune.sh
index fe671d4197..27127fa5a5 100755
--- a/t/t2401-worktree-prune.sh
+++ b/t/t2401-worktree-prune.sh
@@ -24,8 +24,8 @@ test_expect_success 'prune files inside $GIT_DIR/worktrees' '
Removing worktrees/abc: not a valid directory
EOF
test_cmp expect actual &&
- ! test -f .git/worktrees/abc &&
- ! test -d .git/worktrees
+ ! test_path_is_file .git/worktrees/abc &&
+ ! test_path_is_dir .git/worktrees
'
test_expect_success 'prune directories without gitdir' '
@@ -36,8 +36,8 @@ Removing worktrees/def: gitdir file does not exist
EOF
git worktree prune --verbose 2>actual &&
test_cmp expect actual &&
- ! test -d .git/worktrees/def &&
- ! test -d .git/worktrees
+ ! test_path_is_dir .git/worktrees/def &&
+ ! test_path_is_dir .git/worktrees
'
test_expect_success SANITY 'prune directories with unreadable gitdir' '
@@ -47,8 +47,8 @@ test_expect_success SANITY 'prune directories with unreadable gitdir' '
chmod u-r .git/worktrees/def/gitdir &&
git worktree prune --verbose 2>actual &&
test_grep "Removing worktrees/def: unable to read gitdir file" actual &&
- ! test -d .git/worktrees/def &&
- ! test -d .git/worktrees
+ ! test_path_is_dir .git/worktrees/def &&
+ ! test_path_is_dir .git/worktrees
'
test_expect_success 'prune directories with invalid gitdir' '
@@ -57,8 +57,8 @@ test_expect_success 'prune directories with invalid gitdir' '
: >.git/worktrees/def/gitdir &&
git worktree prune --verbose 2>actual &&
test_grep "Removing worktrees/def: invalid gitdir file" actual &&
- ! test -d .git/worktrees/def &&
- ! test -d .git/worktrees
+ ! test_path_is_dir .git/worktrees/def &&
+ ! test_path_is_dir .git/worktrees
'
test_expect_success 'prune directories with gitdir pointing to nowhere' '
@@ -67,8 +67,8 @@ test_expect_success 'prune directories with gitdir pointing to nowhere' '
echo "$(pwd)"/nowhere >.git/worktrees/def/gitdir &&
git worktree prune --verbose 2>actual &&
test_grep "Removing worktrees/def: gitdir file points to non-existent location" actual &&
- ! test -d .git/worktrees/def &&
- ! test -d .git/worktrees
+ ! test_path_is_dir .git/worktrees/def &&
+ ! test_path_is_dir .git/worktrees
'
test_expect_success 'not prune locked checkout' '
@@ -76,23 +76,23 @@ test_expect_success 'not prune locked checkout' '
mkdir -p .git/worktrees/ghi &&
: >.git/worktrees/ghi/locked &&
git worktree prune &&
- test -d .git/worktrees/ghi
+ test_path_is_dir .git/worktrees/ghi
'
test_expect_success 'not prune recent checkouts' '
test_when_finished rm -r .git/worktrees &&
git worktree add jlm HEAD &&
- test -d .git/worktrees/jlm &&
+ test_path_is_dir .git/worktrees/jlm &&
rm -rf jlm &&
git worktree prune --verbose --expire=2.days.ago &&
- test -d .git/worktrees/jlm
+ test_path_is_dir .git/worktrees/jlm
'
test_expect_success 'not prune proper checkouts' '
test_when_finished rm -r .git/worktrees &&
git worktree add --detach "$PWD/nop" main &&
git worktree prune &&
- test -d .git/worktrees/nop
+ test_path_is_dir .git/worktrees/nop
'
test_expect_success 'prune duplicate (linked/linked)' '
@@ -103,8 +103,8 @@ test_expect_success 'prune duplicate (linked/linked)' '
mv .git/worktrees/w2/gitdir.new .git/worktrees/w2/gitdir &&
git worktree prune --verbose 2>actual &&
test_grep "duplicate entry" actual &&
- test -d .git/worktrees/w1 &&
- ! test -d .git/worktrees/w2
+ test_path_is_dir .git/worktrees/w1 &&
+ ! test_path_is_dir .git/worktrees/w2
'
test_expect_success 'prune duplicate (main/linked)' '
@@ -116,7 +116,7 @@ test_expect_success 'prune duplicate (main/linked)' '
mv repo wt &&
git -C wt worktree prune --verbose 2>actual &&
test_grep "duplicate entry" actual &&
- ! test -d .git/worktrees/wt
+ ! test_path_is_dir .git/worktrees/wt
'
test_expect_success 'not prune proper worktrees inside linked worktree with relative paths' '
--
2.34.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 1/1] t: update path checks using test_path helpers
2025-10-14 16:14 [PATCH 1/1] t: update path checks using test_path helpers Solly
@ 2025-10-14 18:19 ` Junio C Hamano
2025-10-14 18:27 ` Usman Akinyemi
2025-10-15 14:03 ` [PATCH v2 0/1] *** t2401: update path checks using test_path helpers *** Solly
1 sibling, 1 reply; 7+ messages in thread
From: Junio C Hamano @ 2025-10-14 18:19 UTC (permalink / raw)
To: Solly; +Cc: git
Solly <solobarine@gmail.com> writes:
> Subject: Re: [PATCH 1/1] t: update path checks using test_path helpers
Using "t2401:" instead of "t:" would give you a bit more
information.
> Update old-style shell path checks to use the modern test
> helpers 'test_path_is_file' and 'test_path_is_dir' for improved
> readability.
This gives a wrong justification.
For readability, "test -f tested-file" is plenty readable. The
point of using test_path_is_file and its friends is to get better
runtime diagnosis.
Read the helper you are using and understand what it does and why it
does it (they are found in t/test-lib-functions.sh):
# debugging-friendly alternatives to "test [-f|-d|-e]"
# The commands test the existence or non-existence of $1
test_path_is_file () {
test "$#" -ne 1 && BUG "1 param"
if ! test -f "$1"
then
echo "File $1 doesn't exist"
false
fi
}
And imagine you wrote your test using this, perhaps like this:
test_expect_success 'ensure hello.c exists' '
test_path_is_file hello.c
'
What happens when (1) hello.c does exist and (2) hello.c does not
exist? If hello.c exists, "if ! test -f" fails, and the control
does not go inside of "then" part, hence the helper will succeed
silently. If hello.c does not exist, it will say "File hello.c
doesn't exist". The person who is running the test will be told why
the test failed (and the helper fails because it runs the 'false'
after giving the message). And that is the value these helpers
offer.
Armed with that knowledge, you can tell that ...
> test_cmp expect actual &&
> - ! test -f .git/worktrees/abc &&
> - ! test -d .git/worktrees
> + ! test_path_is_file .git/worktrees/abc &&
> + ! test_path_is_dir .git/worktrees
... this is a bad rewrite, right? The original wants to ensure that
a file .git/worktrees/abc does not exist. You want the test to
be silent when the path is not a file (i.e. "as expected, nothing
interesting to see here"), and complain loudly when it *is* a file.
And your "! test_path_is_file .git/worktrees/abc" would not do that,
would it? They report loudly in a wrong case!
In this case, both of them should probably become
test_path_is_missing .git/worktrees/abc &&
test_path_is_missing .git/worktrees
because the _intent_ of the test is NOT that it would be happy as
long as .git/worktrees/abc is not a file. Even though the original
uses "! test -f", seeing a .git/worktrees/abc directory there is an
unexpected outcome of the test (you need to read what is being
tested to fully understand this kind of thing).
Hope this helps.
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH 1/1] t: update path checks using test_path helpers
2025-10-14 18:19 ` Junio C Hamano
@ 2025-10-14 18:27 ` Usman Akinyemi
2025-10-14 18:47 ` Eric Sunshine
0 siblings, 1 reply; 7+ messages in thread
From: Usman Akinyemi @ 2025-10-14 18:27 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Solly, git
> Hope this helps.
>
Thanks Junio for the review.
I was on this before the email entered.
Solomon, in addition to this you might also
want to check similar review done by Junio and Eric in [1]
[1]: https://public-inbox.org/git/CAPig+cRfO8t1tdCL6MB4b9XopF3HkZ==hU83AFZ38b-2zsXDjQ@mail.gmail.com/
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/1] t: update path checks using test_path helpers
2025-10-14 18:27 ` Usman Akinyemi
@ 2025-10-14 18:47 ` Eric Sunshine
0 siblings, 0 replies; 7+ messages in thread
From: Eric Sunshine @ 2025-10-14 18:47 UTC (permalink / raw)
To: Usman Akinyemi; +Cc: Junio C Hamano, Solly, git
On Tue, Oct 14, 2025 at 2:27 PM Usman Akinyemi
<usmanakinyemi202@gmail.com> wrote:
> Thanks Junio for the review.
>
> I was on this before the email entered.
>
> Solomon, in addition to this you might also
> want to check similar review done by Junio and Eric in [1]
>
> [1]: https://public-inbox.org/git/CAPig+cRfO8t1tdCL6MB4b9XopF3HkZ==hU83AFZ38b-2zsXDjQ@mail.gmail.com/
Thanks Junio for saying what I was going to say. And thanks Usman for
digging up the link to this previous review, thus saving me the effort
of doing so.
For what it's worth, these days, I think we usually point people at
the lore.kernel.org archive rather than public-inbox.org, so the two
reviews in questions can be found at [1] and [2].
[1]: https://lore.kernel.org/git/CAPig+cRfO8t1tdCL6MB4b9XopF3HkZ==hU83AFZ38b-2zsXDjQ@mail.gmail.com/
[2]: https://lore.kernel.org/git/xmqqwmqm8rmr.fsf@gitster.g/
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v2 0/1] *** t2401: update path checks using test_path helpers ***
2025-10-14 16:14 [PATCH 1/1] t: update path checks using test_path helpers Solly
2025-10-14 18:19 ` Junio C Hamano
@ 2025-10-15 14:03 ` Solly
2025-10-15 14:03 ` [PATCH v2 1/1] t2401: update path checks using test_path helpers Solly
1 sibling, 1 reply; 7+ messages in thread
From: Solly @ 2025-10-15 14:03 UTC (permalink / raw)
To: git; +Cc: Solly
***
Thank you for the timely review.
I applied the corrections and resolved the issues highlighted
in the initial patch and used the appropriate test_helpers.
***
Solly (1):
t2401: update path checks using test_path helpers
t/t2401-worktree-prune.sh | 34 +++++++++++++++++-----------------
1 file changed, 17 insertions(+), 17 deletions(-)
base-commit: 60f3f52f17cceefa5299709b189ce6fe2d181e7b
--
2.34.1
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v2 1/1] t2401: update path checks using test_path helpers
2025-10-15 14:03 ` [PATCH v2 0/1] *** t2401: update path checks using test_path helpers *** Solly
@ 2025-10-15 14:03 ` Solly
2025-10-15 20:38 ` Junio C Hamano
0 siblings, 1 reply; 7+ messages in thread
From: Solly @ 2025-10-15 14:03 UTC (permalink / raw)
To: git; +Cc: Solly
Update old-style shell path checks to use the modern test
helpers 'test_path_is_file' and 'test_path_is_dir' for improved
runtime diagnosis.
Signed-off-by: Solly <solobarine@gmail.com>
---
t/t2401-worktree-prune.sh | 34 +++++++++++++++++-----------------
1 file changed, 17 insertions(+), 17 deletions(-)
diff --git a/t/t2401-worktree-prune.sh b/t/t2401-worktree-prune.sh
index fe671d4197..f8f28c76ee 100755
--- a/t/t2401-worktree-prune.sh
+++ b/t/t2401-worktree-prune.sh
@@ -24,8 +24,8 @@ test_expect_success 'prune files inside $GIT_DIR/worktrees' '
Removing worktrees/abc: not a valid directory
EOF
test_cmp expect actual &&
- ! test -f .git/worktrees/abc &&
- ! test -d .git/worktrees
+ test_path_is_missing .git/worktrees/abc &&
+ test_path_is_missing .git/worktrees
'
test_expect_success 'prune directories without gitdir' '
@@ -36,8 +36,8 @@ Removing worktrees/def: gitdir file does not exist
EOF
git worktree prune --verbose 2>actual &&
test_cmp expect actual &&
- ! test -d .git/worktrees/def &&
- ! test -d .git/worktrees
+ test_path_is_missing .git/worktrees/def &&
+ test_path_is_missing .git/worktrees
'
test_expect_success SANITY 'prune directories with unreadable gitdir' '
@@ -47,8 +47,8 @@ test_expect_success SANITY 'prune directories with unreadable gitdir' '
chmod u-r .git/worktrees/def/gitdir &&
git worktree prune --verbose 2>actual &&
test_grep "Removing worktrees/def: unable to read gitdir file" actual &&
- ! test -d .git/worktrees/def &&
- ! test -d .git/worktrees
+ test_path_is_missing .git/worktrees/def &&
+ test_path_is_missing .git/worktrees
'
test_expect_success 'prune directories with invalid gitdir' '
@@ -57,8 +57,8 @@ test_expect_success 'prune directories with invalid gitdir' '
: >.git/worktrees/def/gitdir &&
git worktree prune --verbose 2>actual &&
test_grep "Removing worktrees/def: invalid gitdir file" actual &&
- ! test -d .git/worktrees/def &&
- ! test -d .git/worktrees
+ test_path_is_missing .git/worktrees/def &&
+ test_path_is_missing .git/worktrees
'
test_expect_success 'prune directories with gitdir pointing to nowhere' '
@@ -67,8 +67,8 @@ test_expect_success 'prune directories with gitdir pointing to nowhere' '
echo "$(pwd)"/nowhere >.git/worktrees/def/gitdir &&
git worktree prune --verbose 2>actual &&
test_grep "Removing worktrees/def: gitdir file points to non-existent location" actual &&
- ! test -d .git/worktrees/def &&
- ! test -d .git/worktrees
+ test_path_is_missing .git/worktrees/def &&
+ test_path_is_missing .git/worktrees
'
test_expect_success 'not prune locked checkout' '
@@ -76,23 +76,23 @@ test_expect_success 'not prune locked checkout' '
mkdir -p .git/worktrees/ghi &&
: >.git/worktrees/ghi/locked &&
git worktree prune &&
- test -d .git/worktrees/ghi
+ test_path_is_dir .git/worktrees/ghi
'
test_expect_success 'not prune recent checkouts' '
test_when_finished rm -r .git/worktrees &&
git worktree add jlm HEAD &&
- test -d .git/worktrees/jlm &&
+ test_path_is_dir .git/worktrees/jlm &&
rm -rf jlm &&
git worktree prune --verbose --expire=2.days.ago &&
- test -d .git/worktrees/jlm
+ test_path_is_dir .git/worktrees/jlm
'
test_expect_success 'not prune proper checkouts' '
test_when_finished rm -r .git/worktrees &&
git worktree add --detach "$PWD/nop" main &&
git worktree prune &&
- test -d .git/worktrees/nop
+ test_path_is_dir .git/worktrees/nop
'
test_expect_success 'prune duplicate (linked/linked)' '
@@ -103,8 +103,8 @@ test_expect_success 'prune duplicate (linked/linked)' '
mv .git/worktrees/w2/gitdir.new .git/worktrees/w2/gitdir &&
git worktree prune --verbose 2>actual &&
test_grep "duplicate entry" actual &&
- test -d .git/worktrees/w1 &&
- ! test -d .git/worktrees/w2
+ test_path_is_dir .git/worktrees/w1 &&
+ test_path_is_missing .git/worktrees/w2
'
test_expect_success 'prune duplicate (main/linked)' '
@@ -116,7 +116,7 @@ test_expect_success 'prune duplicate (main/linked)' '
mv repo wt &&
git -C wt worktree prune --verbose 2>actual &&
test_grep "duplicate entry" actual &&
- ! test -d .git/worktrees/wt
+ test_path_is_missing .git/worktrees/wt
'
test_expect_success 'not prune proper worktrees inside linked worktree with relative paths' '
--
2.34.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
end of thread, other threads:[~2025-10-15 20:38 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-14 16:14 [PATCH 1/1] t: update path checks using test_path helpers Solly
2025-10-14 18:19 ` Junio C Hamano
2025-10-14 18:27 ` Usman Akinyemi
2025-10-14 18:47 ` Eric Sunshine
2025-10-15 14:03 ` [PATCH v2 0/1] *** t2401: update path checks using test_path helpers *** Solly
2025-10-15 14:03 ` [PATCH v2 1/1] t2401: update path checks using test_path helpers Solly
2025-10-15 20:38 ` Junio C Hamano
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).