From: "SZEDER Gábor" <szeder.dev@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: Jeff King <peff@peff.net>, Jiang Xin <zhiyou.jx@alibaba-inc.com>,
Mickey Endito <mickey.endito.2323@protonmail.com>,
"git@vger.kernel.org" <git@vger.kernel.org>,
Jacob Keller <jacob.keller@gmail.com>
Subject: Re: [PATCH] t5582: remove spurious 'cd "$D"' line
Date: Sat, 28 Aug 2021 11:47:26 +0200 [thread overview]
Message-ID: <20210828094726.GG2257957@szeder.dev> (raw)
In-Reply-To: <xmqqsfyxjyfe.fsf@gitster.g>
On Wed, Aug 25, 2021 at 09:12:37AM -0700, Junio C Hamano wrote:
> Jeff King <peff@peff.net> writes:
>
> > Hmm. I think that one is different, in that the "cd" is not redundant,
> > but wrong. But it turns out not to matter to the test. ;)
>
> Funny.
>
> We are lucky because 'cd ""' stays in the same repository as the
> current one and not to a random place,
Actually, the results of 'cd ""' are unspecified, though most shells
do as you said. Do we want something like this?
--- >8 ---
Subject: [PATCH] test-lib: catch 'cd "$dir"' with unset variable
We just had to fix two test cases [1] that invoked 'cd "$dir"' while
the given variable was accidentally unset. While POSIX states that if
'cd's directory parameter "is an empty string, the results are
unspecified" [2], most shells treat this as a no-op [3], i.e. they
neither change directory nor return error, that's why both of those
tests happened to succeed on common shells, and thus these issues
remained hidden for a while.
Catch 'cd ""' by adding a thin wrapper function overriding the
shell's 'cd' command to verify the non-emptiness of its parameters and
call BUG if necessary.
[1] bd72824c60 (t5582: remove spurious 'cd "$D"' line, 2021-08-23)
c21b2511c2 (t5323: drop mentions of "master", 2021-08-24)
[2] https://pubs.opengroup.org/onlinepubs/9699919799/utilities/cd.html
[3] 'ksh' and 'ksh93' are the only shells I found that error out on
'cd ""' with "cd: bad directory" (though these shells are unable
to run significant portion of our test sute anyway).
Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
---
t/test-lib.sh | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/t/test-lib.sh b/t/test-lib.sh
index abcfbed6d6..06b75d8430 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -1436,6 +1436,14 @@ EMPTY_TREE=$(test_oid empty_tree)
EMPTY_BLOB=$(test_oid empty_blob)
_z40=$ZERO_OID
+cd () {
+ if test -z "$@"
+ then
+ BUG "cd invoked with empty parameter"
+ fi
+ command cd "$@"
+}
+
# Provide an implementation of the 'yes' utility; the upper bound
# limit is there to help Windows that cannot stop this loop from
# wasting cycles when the downstream stops reading, so do not be
--
2.33.0.358.g803110d36e
next prev parent reply other threads:[~2021-08-28 9:50 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-23 20:12 [PATCH] t5582: remove spurious 'cd "$D"' line Mickey Endito
2021-08-23 23:32 ` Junio C Hamano
2021-08-24 18:59 ` SZEDER Gábor
2021-08-24 21:10 ` Junio C Hamano
2021-08-25 1:35 ` Jeff King
2021-08-25 16:12 ` Junio C Hamano
2021-08-28 9:47 ` SZEDER Gábor [this message]
2021-08-30 16:42 ` Junio C Hamano
2021-08-30 18:58 ` Jeff King
2021-08-30 19:51 ` Junio C Hamano
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210828094726.GG2257957@szeder.dev \
--to=szeder.dev@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jacob.keller@gmail.com \
--cc=mickey.endito.2323@protonmail.com \
--cc=peff@peff.net \
--cc=zhiyou.jx@alibaba-inc.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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).