diff --git a/man/man1/git-secret-reveal.1.ronn b/man/man1/git-secret-reveal.1.ronn index 5afb1f9a..22d4f150 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 [-f] [-d dir] [-p password] + git secret reveal [-f] [-c] [-d dir] [-p password] ## DESCRIPTION @@ -18,6 +18,7 @@ Under the hood, this uses the `gpg --decrypt` command. -f - forces to overwrite existing files without prompt. -d - specifies `--homedir` option for the `gpg`, basically use this option if you store your keys in a custom location. -p - specifies password for noinput mode, adds `--passphrase` option for `gpg`. + -c - attempts to set decrypted file to same permissions as encrypted file (normally would be -p but that's used above). -h - shows help. diff --git a/src/commands/git_secret_reveal.sh b/src/commands/git_secret_reveal.sh index 633e14eb..a1826441 100644 --- a/src/commands/git_secret_reveal.sh +++ b/src/commands/git_secret_reveal.sh @@ -5,15 +5,18 @@ function reveal { local homedir='' local passphrase='' local force=0 + local chmod=0 OPTIND=1 - while getopts 'hfd:p:' opt; do + while getopts 'chfd:p:' opt; do case "$opt" in h) _show_manual_for 'reveal';; f) force=1;; + c) chmod=1;; + p) passphrase=$OPTARG;; d) homedir=$OPTARG;; @@ -46,6 +49,12 @@ function reveal { _abort "cannot find decrypted version of file: $filename" fi + if [[ "$chmod" ]]; then + local perms + perms=$(stat -f "%Op" "$filename") + chmod "$perms" "$path" + fi + counter=$((counter+1)) done < "$path_mappings" diff --git a/tests/test_reveal.bats b/tests/test_reveal.bats index f8bcba9f..7f4cfb92 100644 --- a/tests/test_reveal.bats +++ b/tests/test_reveal.bats @@ -55,6 +55,16 @@ function teardown { } +@test "run 'reveal' with '-c'" { + rm "$FILE_TO_HIDE" + + local password=$(test_user_password "$TEST_DEFAULT_USER") + run git secret reveal -c -d "$TEST_GPG_HOMEDIR" -p "$password" + + [ "$status" -eq 0 ] + [ -f "$FILE_TO_HIDE" ] +} + @test "run 'reveal' with wrong password" { rm "$FILE_TO_HIDE"