re-creation of #638 fix, removing dup email keys (#700)

* re-creation of #638 fix, removing dup email keys
* Update CHANGELOG.md
pull/757/head
Josh Rabinowitz 2 years ago committed by GitHub
parent 7814b8f2e7
commit b6711e2ac5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -12,6 +12,7 @@
- Fix adding newlines to `.gitignore` entries (#643)
- Fix `cat` and `reveal` on named files while in repo subdir (#710)
- Fix for `removeperson` if same email is present multiple times (#638)
### Misc

@ -637,6 +637,14 @@ function _assert_keyring_doesnt_contain_emails {
_assert_keyring_emails "$homedir" "$keyring_name" "$emails" 0
}
function _assert_keyring_contains_emails_at_least_once {
local homedir=$1
local keyring_name=$2
local emails=$3
_assert_keyring_emails "$homedir" "$keyring_name" "$emails" 1 1 # expect the email at least once in the keyring
}
function _assert_keyring_emails {
local homedir="$1"
@ -646,6 +654,7 @@ function _assert_keyring_emails {
# 0 to not expect the email in the keyring;
# 1 to expect the email in the keyring
local expected="$4"
local allow_duplicates=$5 # set this to 0 to not allow duplicate emails in the keyring when processing assertion (optional)
local gpg_uids
gpg_uids=$(_get_users_in_gpg_keyring "$homedir")
@ -663,7 +672,9 @@ function _assert_keyring_emails {
if [[ $emails_found -eq 0 ]]; then
_abort "no key found in gpg $keyring_name for: $email"
elif [[ $emails_found -gt 1 ]]; then
_abort "$emails_found keys found in gpg $keyring_name for: $email"
if [[ $allow_duplicates -ne 1 ]]; then
_abort "$emails_found keys found in gpg $keyring_name for: $email"
fi
fi
else
if [[ $emails_found -gt 0 ]]; then

@ -28,7 +28,7 @@ function removeperson {
local secrets_dir_keys
secrets_dir_keys=$(_get_secrets_dir_keys)
_assert_keyring_contains_emails "$secrets_dir_keys" "git-secret keyring" "${emails[@]}"
_assert_keyring_contains_emails_at_least_once "$secrets_dir_keys" "git-secret keyring" "${emails[@]}"
for email in "${emails[@]}"; do
# see https://github.com/bats-core/bats-core#file-descriptor-3-read-this-if-bats-hangs for info about 3>&-

Loading…
Cancel
Save