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
pull/326/head^2
Josh Rabinowitz 6 years ago committed by GitHub
parent 6e43cd310f
commit 65fe4c4127
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -21,13 +21,16 @@ function tell {
local emails
local self_email=0
local homedir
local verbose=0
# A POSIX variable
# Reset in case getopts has been used previously in the shell.
OPTIND=1
while getopts "hmd:" opt; do
while getopts "vhmd:" opt; do
case "$opt" in
v) verbose=1;;
h) _show_manual_for "tell";;
m) self_email=1;;
@ -95,7 +98,13 @@ function tell {
# Importing public key to the local keychain:
local 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=$?
if [[ "$exit_code" -ne 0 ]]; then
_abort "problem importing public key for '$email' with gpg: exit code $exit_code"

@ -17,6 +17,25 @@ function teardown {
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" {
run git secret tell -d "$TEST_GPG_HOMEDIR" user
# this should give an error because there is no user named 'user',

Loading…
Cancel
Save