From 65fe4c4127f4e47dd28062491d61f4a22d600f86 Mon Sep 17 00:00:00 2001 From: Josh Rabinowitz Date: Sat, 26 Jan 2019 22:59:13 -0500 Subject: [PATCH] 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 --- src/commands/git_secret_tell.sh | 13 +++++++++++-- tests/test_tell.bats | 19 +++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/commands/git_secret_tell.sh b/src/commands/git_secret_tell.sh index 2e3cf2ce..a413ac9e 100644 --- a/src/commands/git_secret_tell.sh +++ b/src/commands/git_secret_tell.sh @@ -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" diff --git a/tests/test_tell.bats b/tests/test_tell.bats index b9f8168b..113c34f6 100644 --- a/tests/test_tell.bats +++ b/tests/test_tell.bats @@ -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',