Git fork

lib-gpg: allow tests with GPGSM or GPGSSH prereq first

When the 'GPG' prereq is lazily tested, `mkdir "$GNUPGHOME"` could
fail if the "$GNUPGHOME" directory already exists. This can happen if
the 'GPGSM' or the 'GPGSSH' prereq has been lazily tested before as they
already create "$GNUPGHOME".

To allow the GPGSM or the GPGSSH prereq to appear before the GPG prereq
in some test scripts, let's refactor the creation and setup of the
"$GNUPGHOME"` directory in a new prepare_gnupghome() function that uses
`mkdir -p "$GNUPGHOME"`.

This will be useful in a following commit.

Unfortunately the new prepare_gnupghome() function cannot be used when
lazily testing the GPG2 prereq, because that would expose existing,
hidden bugs in "t1016-compatObjectFormat.sh", so let's just document
that with a NEEDSWORK comment.

Helped-by: Todd Zullinger <tmz@pobox.com>
Helped-by: Collin Funk <collin.funk1@gmail.com>
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

authored by

Christian Couder and committed by
Junio C Hamano
e204a167 db674095

+20 -4
+20 -4
t/lib-gpg.sh
··· 9 9 GNUPGHOME="$(pwd)/gpghome" 10 10 export GNUPGHOME 11 11 12 + # All the "test_lazy_prereq GPG*" below should use 13 + # `prepare_gnupghome()` either directly or through a call to 14 + # `test_have_prereq GPG*`. That's because `gpg` and `gpgsm` 15 + # only create the directory specified using "$GNUPGHOME" or 16 + # `--homedir` if it's the default (usually "~/.gnupg"). 17 + prepare_gnupghome() { 18 + mkdir -p "$GNUPGHOME" && 19 + chmod 0700 "$GNUPGHOME" 20 + } 21 + 12 22 test_lazy_prereq GPG ' 13 23 gpg_version=$(gpg --version 2>&1) 14 24 test $? != 127 || exit 1 ··· 38 48 # To export ownertrust: 39 49 # gpg --homedir /tmp/gpghome --export-ownertrust \ 40 50 # > lib-gpg/ownertrust 41 - mkdir "$GNUPGHOME" && 42 - chmod 0700 "$GNUPGHOME" && 51 + prepare_gnupghome && 43 52 (gpgconf --kill all || : ) && 44 53 gpg --homedir "${GNUPGHOME}" --import \ 45 54 "$TEST_DIRECTORY"/lib-gpg/keyring.gpg && ··· 63 72 ;; 64 73 *) 65 74 (gpgconf --kill all || : ) && 75 + 76 + # NEEDSWORK: prepare_gnupghome() should definitely be 77 + # called here, but it looks like it exposes a 78 + # pre-existing, hidden bug by allowing some tests in 79 + # t1016-compatObjectFormat.sh to run instead of being 80 + # skipped. See: 81 + # https://lore.kernel.org/git/ZoV8b2RvYxLOotSJ@teonanacatl.net/ 82 + 66 83 gpg --homedir "${GNUPGHOME}" --import \ 67 84 "$TEST_DIRECTORY"/lib-gpg/keyring.gpg && 68 85 gpg --homedir "${GNUPGHOME}" --import-ownertrust \ ··· 132 149 test $? = 0 || exit 1; 133 150 134 151 # Setup some keys and an allowed signers file 135 - mkdir -p "${GNUPGHOME}" && 136 - chmod 0700 "${GNUPGHOME}" && 152 + prepare_gnupghome && 137 153 (setfacl -k "${GNUPGHOME}" 2>/dev/null || true) && 138 154 ssh-keygen -t ed25519 -N "" -C "git ed25519 key" -f "${GPGSSH_KEY_PRIMARY}" >/dev/null && 139 155 ssh-keygen -t rsa -b 2048 -N "" -C "git rsa2048 key" -f "${GPGSSH_KEY_SECONDARY}" >/dev/null &&