All of lore.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: William Chargin <wchargin@gmail.com>
Cc: sunshine@sunshineco.com, git@vger.kernel.org, jrnieder@gmail.com,
	peff@peff.net
Subject: Re: [PATCH v4] test_dir_is_empty: fix edge cases with newlines and hyphens
Date: Wed, 12 Sep 2018 12:50:19 -0700	[thread overview]
Message-ID: <xmqq7ejqlclg.fsf@gitster-ct.c.googlers.com> (raw)
In-Reply-To: <20180912183534.7486-1-wchargin@gmail.com> (William Chargin's message of "Wed, 12 Sep 2018 11:35:34 -0700")

William Chargin <wchargin@gmail.com> writes:

> While the `test_dir_is_empty` function appears correct in most normal
> use cases, it can improperly pass if a directory contains a filename
> with a newline, and can improperly fail if an empty directory looks like
> an argument to `ls`. This patch changes the implementation to check that
> the output of `ls -a` has at most two lines (for `.` and `..`), which
> should be better behaved, and adds the `--` delimiter before the
> directory name when invoking `ls`.

AFIAK dot and dot-dot are allowed not to exist; "at most two" is not
a good test.

Quite honestly, our tests are still run inside a sort-of controlled
environment, so if it _requires_ use of things we have avoided
depending on, like "ls -A" and "xargs -0", or the fact that most
filesystems always have "." and ".." even in an empty directory, in
order to be resistant to funnily-named files like dot-LF-dot, I
would say it is not worth worrying about these funny names--instead
we can simply refrain from using such a pathological name, can't we?

In other words, is there a real-world need in the context of our
test suite for this change?

Also, I find that its support for directories whose names begin with
a dash red-herring.  All the test scripts in our test suite knows that
they can prefix "./" to avoid problems, i.e.

	test_dir_is_empty ./--wat

So it appears that the only problematic case is when we create a
directory, create a file or a directory whose name is dot-LF-dot and
nothing else, and then do something that ought to cause that file to
disappear, and make sure that the directory is empty, e.g.

	mkdir empty &&
	echo foo >"empty/$dotLFdot" &&
	git add "empty/$dotLFdot" &&
	git reset --hard &&
	test_dir_is_empty empty

We do want to make sure funny names can be added with "git add" and
"git reset --hard" to HEAD that lacked those paths with funny names
to remove them correctly.  But the funny names used in such a test
do not have to be $dotLFdot; you can use "${dotLFdot}X" instead in
the above and can ensure whatever the original test wanted to
ensure.

So...




  reply	other threads:[~2018-09-12 19:50 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-05  2:20 [PATCH 0/1] t/test-lib: make `test_dir_is_empty` more robust William Chargin
2018-08-05  2:20 ` [PATCH 1/1] " William Chargin
2018-08-05  4:19   ` Jonathan Nieder
2018-08-05  5:23     ` Eric Sunshine
2018-08-05 20:52       ` Jeff King
2018-08-06 13:02         ` Jeff King
2018-08-06 17:52           ` Eric Sunshine
2018-08-12  4:06             ` [PATCH v3] test_dir_is_empty: properly detect files with newline in name William Chargin
2018-08-12  6:17               ` Eric Sunshine
2018-08-12  6:32                 ` William Chargin
2018-08-12  6:44                   ` Eric Sunshine
2018-09-12 18:35                     ` [PATCH v4] test_dir_is_empty: fix edge cases with newlines and hyphens William Chargin
2018-09-12 19:50                       ` Junio C Hamano [this message]
2018-09-12 18:37                     ` William Chargin
2018-08-12  4:06             ` [PATCH 1/1] t/test-lib: make `test_dir_is_empty` more robust William Chargin
2018-08-05  5:24     ` William Chargin
2018-08-05  6:34       ` Jonathan Nieder
2018-08-05  6:03     ` Junio C Hamano
2018-08-05  6:23       ` Jonathan Nieder
2018-08-05  3:36 ` [PATCH 0/1] " Jonathan Nieder
2018-08-05  4:19   ` William Chargin
2018-08-05  4:20   ` [PATCH v2] " William Chargin
2018-08-05  8:34     ` Johannes Sixt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqq7ejqlclg.fsf@gitster-ct.c.googlers.com \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=jrnieder@gmail.com \
    --cc=peff@peff.net \
    --cc=sunshine@sunshineco.com \
    --cc=wchargin@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.