diff --git a/man/man1/git-secret-hide.1 b/man/man1/git-secret-hide.1 index bf7e14f9..581be2e9 100644 --- a/man/man1/git-secret-hide.1 +++ b/man/man1/git-secret-hide.1 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "GIT\-SECRET\-HIDE" "1" "March 2016" "" "" +.TH "GIT\-SECRET\-HIDE" "1" "February 2017" "" "" . .SH "NAME" \fBgit\-secret\-hide\fR \- encrypts all added files with the inner keyring\. @@ -26,6 +26,7 @@ It is possible to modify the names of the encrypted files by setting \fBSECRETS_ \-v \- verbose, shows extra information\. \-c \- deletes encrypted files before creating new ones\. +\-d \- deletes unencrypted files after encryption\. \-h \- shows help\. . .fi diff --git a/man/man1/git-secret-hide.1.ronn b/man/man1/git-secret-hide.1.ronn index 30c3545c..0998df84 100644 --- a/man/man1/git-secret-hide.1.ronn +++ b/man/man1/git-secret-hide.1.ronn @@ -16,6 +16,7 @@ It is possible to modify the names of the encrypted files by setting `SECRETS_EX -v - verbose, shows extra information. -c - deletes encrypted files before creating new ones. + -d - deletes unencrypted files after encryption. -h - shows help. diff --git a/src/commands/git_secret_hide.sh b/src/commands/git_secret_hide.sh index ec781bc7..5d0fc05c 100644 --- a/src/commands/git_secret_hide.sh +++ b/src/commands/git_secret_hide.sh @@ -6,7 +6,7 @@ function _optional_clean { local clean=0 local opt_string='' - while getopts 'cvh' opt; do + while getopts 'cdvh' opt; do case "$opt" in c) clean=1;; @@ -27,6 +27,40 @@ function _optional_clean { } +function _optional_delete { + local verbose='' + local delete=0 + + OPTIND=1 + + while getopts 'vd' opt; do + case "$opt" in + d) delete=1;; + + v) verbose="v";; + esac + done + + shift $((OPTIND-1)) + [ "$1" = '--' ] && shift + + if [[ $delete -eq 1 ]]; then + if [[ ! -z "$verbose" ]]; then + echo && echo 'removing unencrypted files:' + fi + + while read -r line; do + find . -name "*$line" -type f -print0 | xargs -0 rm -f$verbose + done < "$SECRETS_DIR_PATHS_MAPPING" + + if [[ ! -z "$verbose" ]]; then + echo + fi + fi + +} + + function hide { _optional_clean "$@" @@ -45,5 +79,7 @@ function hide { counter=$((counter+1)) done < "$SECRETS_DIR_PATHS_MAPPING" + _optional_delete "$@" + echo "done. all $counter files are hidden." } diff --git a/tests/test_hide.bats b/tests/test_hide.bats index 45cd29bb..5196a0c3 100644 --- a/tests/test_hide.bats +++ b/tests/test_hide.bats @@ -31,12 +31,19 @@ function teardown { } -@test "run 'hide' with params" { +@test "run 'hide' with -c param" { run git secret hide -v -c [ "$status" -eq 0 ] } +@test "run 'hide' with -d param" { + run git secret hide -v -d + [ "$status" -eq 0 ] + [ ! -f "$FILE_TO_HIDE" ] +} + + @test "run 'hide' for multiple users" { local new_user="user2"