]> git.ipfire.org Git - thirdparty/git.git/commitdiff
t5534: fix misleading grep invocation
authorJohannes Schindelin <johannes.schindelin@gmx.de>
Wed, 5 Jul 2017 11:37:49 +0000 (13:37 +0200)
committerJunio C Hamano <gitster@pobox.com>
Wed, 5 Jul 2017 16:26:52 +0000 (09:26 -0700)
It seems to be a little-known feature of `grep` (and it certainly came
as a surprise to this here developer who believed to know the Unix tools
pretty well) that multiple patterns can be passed in the same
command-line argument simply by separating them by newlines. Watch, and
learn:

$ printf '1\n2\n3\n' | grep "$(printf '1\n3\n')"
1
3

That behavior also extends to patterns passed via `-e`, and it is not
modified by passing the option `-E` (but trying this with -P issues the
error "grep: the -P option only supports a single pattern").

It seems that there are more old Unix hands who are surprised by this
behavior, as grep invocations of the form

grep "$(git rev-parse A B) C" file

were introduced in a85b377d041 (push: the beginning of "git push
--signed", 2014-09-12), and later faithfully copy-edited in b9459019bbb
(push: heed user.signingkey for signed pushes, 2014-10-22).

Please note that the output of `git rev-parse A B` separates the object
IDs via *newlines*, not via spaces, and those newlines are preserved
because the interpolation is enclosed in double quotes.

As a consequence, these tests try to validate that the file contains
either A's object ID, or B's object ID followed by C, or both. Clearly,
however, what the test wanted to see is that there is a line that
contains all of them.

This is clearly unintended, and the grep invocations in question really
match too many lines.

Fix the test by avoiding the newlines in the patterns.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/t5534-push-signed.sh

index ecb8d446a58d422bd8a9a25f75e4f9a20ec50818..2db0c3389c01cc31fdbf553592fc6b47cc8480c2 100755 (executable)
@@ -119,8 +119,11 @@ test_expect_success GPG 'signed push sends push certificate' '
                sed -n -e "s/^nonce /NONCE=/p" -e "/^$/q" dst/push-cert
        ) >expect &&
 
-       grep "$(git rev-parse noop ff) refs/heads/ff" dst/push-cert &&
-       grep "$(git rev-parse noop noff) refs/heads/noff" dst/push-cert &&
+       noop=$(git rev-parse noop) &&
+       ff=$(git rev-parse ff) &&
+       noff=$(git rev-parse noff) &&
+       grep "$noop $ff refs/heads/ff" dst/push-cert &&
+       grep "$noop $noff refs/heads/noff" dst/push-cert &&
        test_cmp expect dst/push-cert-status
 '
 
@@ -163,8 +166,11 @@ test_expect_success GPG 'fail without key and heed user.signingkey' '
                sed -n -e "s/^nonce /NONCE=/p" -e "/^$/q" dst/push-cert
        ) >expect &&
 
-       grep "$(git rev-parse noop ff) refs/heads/ff" dst/push-cert &&
-       grep "$(git rev-parse noop noff) refs/heads/noff" dst/push-cert &&
+       noop=$(git rev-parse noop) &&
+       ff=$(git rev-parse ff) &&
+       noff=$(git rev-parse noff) &&
+       grep "$noop $ff refs/heads/ff" dst/push-cert &&
+       grep "$noop $noff refs/heads/noff" dst/push-cert &&
        test_cmp expect dst/push-cert-status
 '