Jeff King [off-list ref] 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, and because the current one
happens to have no pack and running the command in a repository
without any pack is what the test wants to do anyway.
Thanks, will queue.
quoted hunk
diff --git a/t/t5323-pack-redundant.sh b/t/t5323-pack-redundant.sh
index 8b01793845..8dbbcc5e51 100755
--- a/t/t5323-pack-redundant.sh
+++ b/t/t5323-pack-redundant.sh
@@ -114,9 +114,9 @@ test_expect_success 'setup main repo' '
create_commits_in "$main_repo" A B C D E F G H I J K L M N O P Q R
'
-test_expect_success 'master: pack-redundant works with no packfile' '
+test_expect_success 'main: pack-redundant works with no packfile' '
(
- cd "$master_repo" &&
+ cd "$main_repo" &&
cat >expect <<-EOF &&
fatal: Zero packs found!
EOF
On Wed, Aug 25, 2021 at 09:12:37AM -0700, Junio C Hamano wrote:
Jeff King [off-list ref] writes:
quoted
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 <redacted>
---
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