Skip to content

Commit 9d453ce

Browse files
committed
Abort signature configuration if there is no key
Sometimes happens that there is no GPG key for the given email. In this case, the configuration will be successfully completed. #243
1 parent 6e2ec1e commit 9d453ce

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

libexec/git-elegant-acquire-repository

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@ default() {
4646
info-box "Configuring signature..."
4747
local listkeys="gpg --list-secret-keys --keyid-format long $(git config --local user.email)"
4848
command-text ${listkeys}
49-
${listkeys}
49+
${listkeys} 2>/dev/null || {
50+
info-text "There is no gpg key for the given email."
51+
info-text "A signature is not configured."
52+
return 0
53+
}
5054
info-text "From the list of GPG keys above, copy the GPG key ID you'd like to use."
5155
info-text "It will be"
5256
info-text " 3AA5C34371567BD2"

tests/git-elegant-acquire-repository.bats

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,3 +157,22 @@ teardown() {
157157
[[ ! ${lines[@]} =~ "==>> git config --local tag.gpgSign true" ]]
158158
[[ ! ${lines[@]} =~ "The signature is not configured as the empty key is provided." ]]
159159
}
160+
161+
@test "'acquire-repository': does not configure a signature if there is no key for the email" {
162+
read-answer "The User"
163+
read-answer "the@email"
164+
read-answer "someeditor"
165+
read-answer ""
166+
fake-fail "gpg --list-secret-keys --keyid-format long the@email" "gpg: error reading key: No secret key"
167+
check git-elegant acquire-repository
168+
[[ ${status} -eq 0 ]]
169+
[[ ${lines[@]} =~ "Configuring signature..." ]]
170+
[[ ${lines[@]} =~ "There is no gpg key for the given email." ]]
171+
[[ ${lines[@]} =~ "A signature is not configured." ]]
172+
[[ ! ${lines[@]} =~ "==>> git config --local user.signingkey" ]]
173+
[[ ! ${lines[@]} =~ "==>> git config --local gpg.program /tmp/elegant-git-fakes/gpg" ]]
174+
[[ ! ${lines[@]} =~ "==>> git config --local commit.gpgsign true" ]]
175+
[[ ! ${lines[@]} =~ "==>> git config --local tag.forceSignAnnotated true" ]]
176+
[[ ! ${lines[@]} =~ "==>> git config --local tag.gpgSign true" ]]
177+
[[ ! ${lines[@]} =~ "The signature is not configured as the empty key is provided." ]]
178+
}

0 commit comments

Comments
 (0)