Skip to content

Commit a35952b

Browse files
tmzullingergitster
authored andcommitted
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>
1 parent 790a17f commit a35952b

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

t/lib-gpg.sh

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
GNUPGHOME="$PWD/gpghome"
1010
export GNUPGHOME
1111

12+
prepare_gnupghome () {
13+
mkdir -p "$GNUPGHOME" &&
14+
chmod 0700 "$GNUPGHOME"
15+
}
16+
1217
test_lazy_prereq GPG '
1318
gpg_version=$(gpg --version 2>&1)
1419
test $? != 127 || exit 1
@@ -38,8 +43,7 @@ test_lazy_prereq GPG '
3843
# To export ownertrust:
3944
# gpg --homedir /tmp/gpghome --export-ownertrust \
4045
# > lib-gpg/ownertrust
41-
mkdir "$GNUPGHOME" &&
42-
chmod 0700 "$GNUPGHOME" &&
46+
prepare_gnupghome &&
4347
(gpgconf --kill all || : ) &&
4448
gpg --homedir "${GNUPGHOME}" --import \
4549
"$TEST_DIRECTORY"/lib-gpg/keyring.gpg &&
@@ -132,8 +136,7 @@ test_lazy_prereq GPGSSH '
132136
test $? = 0 || exit 1;
133137
134138
# Setup some keys and an allowed signers file
135-
mkdir -p "${GNUPGHOME}" &&
136-
chmod 0700 "${GNUPGHOME}" &&
139+
prepare_gnupghome &&
137140
(setfacl -k "${GNUPGHOME}" 2>/dev/null || true) &&
138141
ssh-keygen -t ed25519 -N "" -C "git ed25519 key" -f "${GPGSSH_KEY_PRIMARY}" >/dev/null &&
139142
ssh-keygen -t rsa -b 2048 -N "" -C "git rsa2048 key" -f "${GPGSSH_KEY_SECONDARY}" >/dev/null &&

0 commit comments

Comments
 (0)