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

Re: [RFC/PATCH 1/4] test-lib: add test_dir_is_empty()

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 25, 2014, 20:49 UTC
Message-ID
<xmqq4n2mknqf.fsf@gitster.dls.corp.google.com>
In-Reply-To
<5331B717.5010600@web.de>
Jens Lehmann <Jens.Lehmann@web.de> writes:
Show 9 quoted lines
> For the upcoming submodule test framework we often need to assert that an
> empty directory exists in the work tree. Add the test_dir_is_empty()
> function which asserts that the given argument is an empty directory.
>
> Signed-off-by: Jens Lehmann <Jens.Lehmann@web.de>
> ---
>
> I believe this one is pretty straightforward (unless I missed that this
> functionality already exists someplace I forgot to look ;-).

I am not very thrilled to see that it depends on "." and ".." to always exist, which may be true for all POSIX filesystems, but still...

Do expected callsites of this helper care if "$1" is a symbolic link that points at an empty directory?

What do expected callsites really want to ensure? In other words, why do they care if the directory is empty? Is it to make sure, after some operation, they can "rmdir" the directory?

Show 25 quoted lines
>  t/test-lib-functions.sh | 11 +++++++++++
>  1 file changed, 11 insertions(+)
>
> diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
> index 158e10a..93d10cd 100644
> --- a/t/test-lib-functions.sh
> +++ b/t/test-lib-functions.sh
> @@ -489,6 +489,17 @@ test_path_is_dir () {
>  	fi
>  }
>
> +# Check if the directory exists and is empty as expected, barf otherwise.
> +test_dir_is_empty () {
> +	test_path_is_dir "$1" &&
> +	if test $(ls -a1 "$1" | wc -l) != 2
> +	then
> +		echo "Directory '$1' is not empty, it contains:"
> +		ls -la "$1"
> +		return 1
> +	fi
> +}
> +
>  test_path_is_missing () {
>  	if [ -e "$1" ]
>  	then
Previous: Jens LehmannNext: David Kastrup
Message 3 of 17 in “Add submodule test harness”
  1. 0/4 Add submodule test harnessJens Lehmann, Mar 25, 2014
  2. 1/4 test-lib: add test_dir_is_empty()Jens Lehmann, Mar 25, 2014
  3. Junio C HamanoMar 25, 2014
  4. David KastrupMar 25, 2014
  5. Jens LehmannMar 26, 2014
  6. Michael HaggertyMar 26, 2014
  7. Jens LehmannMar 26, 2014
  8. 2/4 Submodules: Add the lib-submodule-update.sh test libraryJens Lehmann, Mar 25, 2014
  9. W. Trevor KingApr 17, 2014
  10. Junio C HamanoApr 17, 2014
  11. Jens LehmannApr 17, 2014
  12. Heiko VoigtApr 18, 2014
  13. Jens LehmannApr 17, 2014
  14. W. Trevor KingApr 17, 2014
  15. Jens LehmannApr 18, 2014
  16. 3/4 checkout: call the new submodule update test frameworkJens Lehmann, Mar 25, 2014
  17. 4/4 apply: add t4137 for submodule updatesJens Lehmann, Mar 25, 2014

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.