Add verbose option to 'git secret tell' showing output of key imports (#321)

* add 'git secret tell -v' option to show output of key imports
* add tests for tell with/without -v
* remove unneeded test code and bats diagnostic output
This commit is contained in:
Josh Rabinowitz 2019-01-26 22:59:13 -05:00 committed by GitHub
parent 6e43cd310f
commit 65fe4c4127
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 2 deletions

View File

@ -21,13 +21,16 @@ function tell {
local emails local emails
local self_email=0 local self_email=0
local homedir local homedir
local verbose=0
# A POSIX variable # A POSIX variable
# Reset in case getopts has been used previously in the shell. # Reset in case getopts has been used previously in the shell.
OPTIND=1 OPTIND=1
while getopts "hmd:" opt; do while getopts "vhmd:" opt; do
case "$opt" in case "$opt" in
v) verbose=1;;
h) _show_manual_for "tell";; h) _show_manual_for "tell";;
m) self_email=1;; m) self_email=1;;
@ -95,7 +98,13 @@ function tell {
# Importing public key to the local keychain: # Importing public key to the local keychain:
local secrets_dir_keys local secrets_dir_keys
secrets_dir_keys=$(_get_secrets_dir_keys) secrets_dir_keys=$(_get_secrets_dir_keys)
$SECRETS_GPG_COMMAND --homedir "$secrets_dir_keys" --no-permission-warning --import "$keyfile" > /dev/null 2>&1
local args=( --homedir "$secrets_dir_keys" --no-permission-warning --import "$keyfile" )
if [[ "$verbose" -ne 0 ]]; then
$SECRETS_GPG_COMMAND "${args[@]}"
else
$SECRETS_GPG_COMMAND "${args[@]}" > /dev/null 2>&1
fi
exit_code=$? exit_code=$?
if [[ "$exit_code" -ne 0 ]]; then if [[ "$exit_code" -ne 0 ]]; then
_abort "problem importing public key for '$email' with gpg: exit code $exit_code" _abort "problem importing public key for '$email' with gpg: exit code $exit_code"

View File

@ -17,6 +17,25 @@ function teardown {
unset_current_state unset_current_state
} }
@test "run 'tell' with '-v'" {
run git secret tell -d "$TEST_GPG_HOMEDIR" -v "$TEST_DEFAULT_USER"
#echo "$output" | sed "s/^/# '$BATS_TEST_DESCRIPTION' output: /" >&3
[[ "$output" == *"created"* ]]
[[ "$output" == *"gpg:"* ]]
[[ "$output" == *"$TEST_DEFAULT_USER"* ]]
[ "$status" -eq 0 ]
}
@test "run 'tell' without '-v'" {
run git secret tell -d "$TEST_GPG_HOMEDIR" "$TEST_DEFAULT_USER"
#echo "$output" | sed "s/^/# '$BATS_TEST_DESCRIPTION' output: /" >&3
[[ "$output" != *"imported:"* ]]
[[ "$output" == *"$TEST_DEFAULT_USER"* ]]
[ "$status" -eq 0 ]
}
@test "run 'tell' on substring of emails" { @test "run 'tell' on substring of emails" {
run git secret tell -d "$TEST_GPG_HOMEDIR" user run git secret tell -d "$TEST_GPG_HOMEDIR" user
# this should give an error because there is no user named 'user', # this should give an error because there is no user named 'user',