t/lib-gpg: add prepare_gnupghome() to create GNUPGHOME dir
We create the $GNUPGHOME directory in both the GPG and GPGSSH prereqs. Replace the redundancy with a function. Use `mkdir -p` to ensure we do not fail if a test includes more than one of these prereqs. Signed-off-by: Todd Zullinger <tmz@pobox.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Todd Zullinger committed
Jul 3, 2024 at 11:37 UTC
a35952b493f24941ad47233ac01ac9fea305d07f
1 file changed
+7
-4
t/lib-gpg.sh
+7
-4
@@ -9,6 +9,11 @@
9
GNUPGHOME="$PWD/gpghome"
10
export GNUPGHOME
11
12
+prepare_gnupghome () {
13
+ mkdir -p "$GNUPGHOME" &&
14
+ chmod 0700 "$GNUPGHOME"
15
+}
16
+
17
test_lazy_prereq GPG '
18
gpg_version=$(gpg --version 2>&1)
19
test $? != 127 || exit 1
@@ -38,8 +43,7 @@ test_lazy_prereq GPG '
43
# To export ownertrust:
44
# gpg --homedir /tmp/gpghome --export-ownertrust \
45
# > lib-gpg/ownertrust
41
- mkdir "$GNUPGHOME" &&
42
- chmod 0700 "$GNUPGHOME" &&
46
+ prepare_gnupghome &&
47
(gpgconf --kill all || : ) &&
48
gpg --homedir "${GNUPGHOME}" --import \
49
"$TEST_DIRECTORY"/lib-gpg/keyring.gpg &&
@@ -132,8 +136,7 @@ test_lazy_prereq GPGSSH '
136
test $? = 0 || exit 1;
137
138
# Setup some keys and an allowed signers file
135
- mkdir -p "${GNUPGHOME}" &&
136
- chmod 0700 "${GNUPGHOME}" &&
139
+ prepare_gnupghome &&
140
(setfacl -k "${GNUPGHOME}" 2>/dev/null || true) &&
141
ssh-keygen -t ed25519 -N "" -C "git ed25519 key" -f "${GPGSSH_KEY_PRIMARY}" >/dev/null &&
142
ssh-keygen -t rsa -b 2048 -N "" -C "git rsa2048 key" -f "${GPGSSH_KEY_SECONDARY}" >/dev/null &&