{"thread":{"id":"66329","subject":"[PATCH] t7610: use test_path_is_* helpers","startedAt":"2026-09-14T14:49:54Z","lastAt":"2026-09-14T15:42:59Z","messageCount":2,"participants":["Tanishq Singh via B4 Relay","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"552709","messageId":"20260914-t7610-test-path-helpers-v1-1-4824812314c7@tanishqsingh.com","threadId":"66329","inReplyTo":null,"subject":"[PATCH] t7610: use test_path_is_* helpers","fromName":"Tanishq Singh via B4 Relay","fromEmail":"devnull+hello.tanishqsingh.com@kernel.org","sentAt":"2026-09-14T14:49:48Z","receivedAt":"2026-09-14T14:49:54Z","isPatch":true,"body":"From: Tanishq Singh <hello@tanishqsingh.com>\n\nReplace 'test -f', 'test -d' and 'test ! -e' with the\ntest_path_is_file(), test_path_is_dir() and test_path_is_missing()\nhelpers. The helpers print the directory listing on failure, which\nmakes diagnosing a broken test easier than non-zero exit status\noffered by 'test'.\n\nSigned-off-by: Tanishq Singh <hello@tanishqsingh.com>\n---\nVerified with `cd t && ./t7610-mergetool.sh`,\nand all tests pass.\n---\n t/t7610-mergetool.sh | 30 +++++++++++++++---------------\n 1 file changed, 15 insertions(+), 15 deletions(-)\n\ndiff --git a/t/t7610-mergetool.sh b/t/t7610-mergetool.sh\nindex 0128b14452..92ac8f3fb6 100755\n--- a/t/t7610-mergetool.sh\n+++ b/t/t7610-mergetool.sh\n@@ -382,15 +382,15 @@ test_expect_success 'mergetool delete/delete conflict' '\n \tgit checkout -b test$test_count move-to-c &&\n \ttest_must_fail git merge move-to-b &&\n \techo d | git mergetool a/a/file.txt &&\n-\t! test -f a/a/file.txt &&\n+\t! test_path_is_file a/a/file.txt &&\n \tgit reset --hard &&\n \ttest_must_fail git merge move-to-b &&\n \techo m | git mergetool a/a/file.txt &&\n-\ttest -f b/b/file.txt &&\n+\ttest_path_is_file b/b/file.txt &&\n \tgit reset --hard &&\n \ttest_must_fail git merge move-to-b &&\n \t! echo a | git mergetool a/a/file.txt &&\n-\t! test -f a/a/file.txt\n+\t! test_path_is_file a/a/file.txt\n '\n \n test_expect_success 'mergetool produces no errors when keepBackup is used' '\n@@ -400,7 +400,7 @@ test_expect_success 'mergetool produces no errors when keepBackup is used' '\n \ttest_must_fail git merge move-to-b &&\n \techo d | git mergetool a/a/file.txt 2>actual &&\n \ttest_must_be_empty actual &&\n-\t! test -d a\n+\t! test_path_is_dir a\n '\n \n test_expect_success 'mergetool honors tempfile config for deleted files' '\n@@ -409,7 +409,7 @@ test_expect_success 'mergetool honors tempfile config for deleted files' '\n \ttest_config mergetool.keepTemporaries false &&\n \ttest_must_fail git merge move-to-b &&\n \techo d | git mergetool a/a/file.txt &&\n-\t! test -d a\n+\t! test_path_is_dir a\n '\n \n test_expect_success 'mergetool keeps tempfiles when aborting delete/delete' '\n@@ -419,7 +419,7 @@ test_expect_success 'mergetool keeps tempfiles when aborting delete/delete' '\n \ttest_config mergetool.keepTemporaries true &&\n \ttest_must_fail git merge move-to-b &&\n \t! test_write_lines a n | git mergetool a/a/file.txt &&\n-\ttest -d a/a &&\n+\ttest_path_is_dir a/a &&\n \tcat >expect <<-\\EOF &&\n \tfile_BASE_.txt\n \tfile_LOCAL_.txt\n@@ -462,7 +462,7 @@ test_expect_success 'deleted vs modified submodule' '\n \tyes \"\" | git mergetool both &&\n \tyes \"d\" | git mergetool file11 file12 &&\n \tyes \"l\" | git mergetool submod &&\n-\ttest ! -e submod &&\n+\ttest_path_is_missing submod &&\n \toutput=\"$(git mergetool --no-prompt)\" &&\n \ttest \"$output\" = \"No files need merging\" &&\n \tgit commit -m \"Merge resolved by deleting module\" &&\n@@ -476,8 +476,8 @@ test_expect_success 'deleted vs modified submodule' '\n \tyes \"\" | git mergetool both &&\n \tyes \"d\" | git mergetool file11 file12 &&\n \tyes \"r\" | git mergetool submod &&\n-\ttest ! -e submod &&\n-\ttest -d submod.orig &&\n+\ttest_path_is_missing submod &&\n+\ttest_path_is_dir submod.orig &&\n \tgit submodule update -N &&\n \toutput=\"$(git mergetool --no-prompt)\" &&\n \ttest \"$output\" = \"No files need merging\" &&\n@@ -547,7 +547,7 @@ test_expect_success 'file vs modified submodule' '\n \n \tgit checkout -b test$test_count.c main &&\n \trmdir submod && mv submod-movedaside submod &&\n-\ttest ! -e submod.orig &&\n+\ttest_path_is_missing submod.orig &&\n \tgit submodule update -N &&\n \ttest_must_fail git merge test$test_count &&\n \ttest -n \"$(git ls-files -u)\" &&\n@@ -558,7 +558,7 @@ test_expect_success 'file vs modified submodule' '\n \tgit rm --cached submod &&\n \tyes \"c\" | git mergetool submod~test19 &&\n \tgit mv submod~test19 submod &&\n-\ttest -d submod.orig &&\n+\ttest_path_is_dir submod.orig &&\n \tgit submodule update -N &&\n \techo \"not a submodule\" >expect &&\n \ttest_cmp expect submod &&\n@@ -672,11 +672,11 @@ test_expect_success 'directory vs modified submodule' '\n \tgit reset --hard &&\n \ttest_must_fail git merge main &&\n \ttest -n \"$(git ls-files -u)\" &&\n-\ttest ! -e submod.orig &&\n+\ttest_path_is_missing submod.orig &&\n \tyes \"r\" | git mergetool submod~main &&\n \tgit mv submod submod.orig &&\n \tgit mv submod~main submod &&\n-\ttest -d submod.orig &&\n+\ttest_path_is_dir submod.orig &&\n \techo \"not a submodule\" >expect &&\n \ttest_cmp expect submod.orig/file16 &&\n \trm -r submod.orig &&\n@@ -701,7 +701,7 @@ test_expect_success 'directory vs modified submodule' '\n \tgit submodule update -N &&\n \ttest_must_fail git merge test$test_count &&\n \ttest -n \"$(git ls-files -u)\" &&\n-\ttest ! -e submod.orig &&\n+\ttest_path_is_missing submod.orig &&\n \tyes \"r\" | git mergetool submod &&\n \techo \"not a submodule\" >expect &&\n \ttest_cmp expect submod/file16 &&\n@@ -743,7 +743,7 @@ test_expect_success 'filenames seen by tools start with ./' '\n \n test_lazy_prereq MKTEMP '\n \ttempdir=$(mktemp -d -t foo.XXXXXX) &&\n-\ttest -d \"$tempdir\" &&\n+\ttest_path_is_dir \"$tempdir\" &&\n \trmdir \"$tempdir\"\n '\n \n\n---\nbase-commit: 47ce80527c56f462cb97db4ca8125342204d3783\nchange-id: 20260914-t7610-test-path-helpers-134ded7da9df\n\n\n"},{"id":"552714","messageId":"xmqqy0d36dq7.fsf@gitster.g","threadId":"66329","inReplyTo":"20260914-t7610-test-path-helpers-v1-1-4824812314c7@tanishqsingh.com","subject":"Re: [PATCH] t7610: use test_path_is_* helpers","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-09-14T15:42:56Z","receivedAt":"2026-09-14T15:42:59Z","isPatch":true,"body":"Tanishq Singh via B4 Relay\n<devnull+hello.tanishqsingh.com@kernel.org> writes:\n\n>  \techo d | git mergetool a/a/file.txt &&\n> -\t! test -f a/a/file.txt &&\n> +\t! test_path_is_file a/a/file.txt &&\n\nThis is wrong.  Consider why you would prefer test_path_is_file()\nover test -f in the first place.\n\nThe goal is to be much louder when the expectation is not met,\nwhile remaining as silent as test -f in the happy case.  This grabs\nthe attention of those running tests.  We want to be loud when\nthings break, and silent otherwise.\n\ntest_path_is_file() expects file X to exist and will not complain\nwhen X is a file.\n\nHowever, the test \"! test -f a/a/file.txt\" in this case expects\nsomething totally different.  It ensures that such a path does not\nexist.  It is an error if a/a/file.txt exists here.  You want the\nhelper to be loud when the file exists, and silent when it does not.\n\ntest_path_is_file() called on a/a/file.txt, with or without a\nleading !, behaves incorrectly for the purpose of this conversion,\neven though the polarity of the returned status may be correct\n(i.e., test_path_is_file(), just like test -f, exits with status 0\nwhen the file a/a/file.txt exists, and a leading ! negates it,\nmaking the test line fail when a/a/file.txt exists).\n\nIf the expectation is that a/a/file.txt does not exist, use\ntest_path_is_missing().  Please read through t/test-lib.sh and\nt/test-lib-functions.sh to familiarize yourself with the helpers\nthese files offer before going further.\n\nThanks.\n"}]}