diff --git a/man/man1/git-secret-reveal.1.ronn b/man/man1/git-secret-reveal.1.ronn index 3408768e..0c7c2bdf 100644 --- a/man/man1/git-secret-reveal.1.ronn +++ b/man/man1/git-secret-reveal.1.ronn @@ -3,7 +3,7 @@ git-secret-reveal - decrypts all added files. ## SYNOPSIS - git secret reveal [-d dir] [-p password] + git secret reveal [-f] [-d dir] [-p password] ## DESCRIPTION @@ -12,6 +12,7 @@ git-secret-reveal - decrypts all added files. ## OPTIONS + -f - forces to overwrite exisiting files without prompt. -d - specifies `--homedir` option for the `gpg`, basically use this option if your store your keys in a custom location. -p - specifies password for noinput mode, adds `--passphrase` option for `gpg`. -h - shows help. diff --git a/src/commands/git_secret_reveal.sh b/src/commands/git_secret_reveal.sh index ba570a3a..10586ac8 100644 --- a/src/commands/git_secret_reveal.sh +++ b/src/commands/git_secret_reveal.sh @@ -6,11 +6,14 @@ function reveal { OPTIND=1 local homedir="" local passphrase="" + local force=0 - while getopts "hd:p:" opt; do + while getopts "hfd:p:" opt; do case "$opt" in h) _show_manual_for "reveal";; + f) force=1;; + p) passphrase=$OPTARG;; d) homedir=$OPTARG;; @@ -26,7 +29,12 @@ function reveal { while read line; do local encrypted_filename=$(_get_encrypted_filename "$line") - local base="$SECRETS_GPG_COMMAND --use-agent -q --decrypt --yes" + local base="$SECRETS_GPG_COMMAND --use-agent -q --decrypt" + + if [[ "$force" -eq 1 ]]; then + base="$base --yes" + fi + if [[ ! -z "$homedir" ]]; then base="$base --homedir=$homedir" fi diff --git a/tests/test_reveal.bats b/tests/test_reveal.bats index c04b0034..32dde2e7 100644 --- a/tests/test_reveal.bats +++ b/tests/test_reveal.bats @@ -42,6 +42,17 @@ function teardown { } +@test "run 'reveal' with '-f'" { + rm -f "$FILE_TO_HIDE" + + local password=$(test_user_password "$TEST_DEFAULT_USER") + run git secret reveal -f -d "$TEST_GPG_HOMEDIR" -p "$password" + + [ "$status" -eq 0 ] + [ -f "$FILE_TO_HIDE" ] +} + + @test "run 'reveal' with wrong password" { rm -f "$FILE_TO_HIDE"