Add -d option to hide command to remove unencrypted files.

pull/62/head
Tim Churchard 8 years ago
parent 73526644e0
commit 1f8a9809a2

@ -1,7 +1,7 @@
.\" generated with Ronn/v0.7.3 .\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.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" .SH "NAME"
\fBgit\-secret\-hide\fR \- encrypts all added files with the inner keyring\. \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\. \-v \- verbose, shows extra information\.
\-c \- deletes encrypted files before creating new ones\. \-c \- deletes encrypted files before creating new ones\.
\-d \- deletes unencrypted files after encryption\.
\-h \- shows help\. \-h \- shows help\.
. .
.fi .fi

@ -16,6 +16,7 @@ It is possible to modify the names of the encrypted files by setting `SECRETS_EX
-v - verbose, shows extra information. -v - verbose, shows extra information.
-c - deletes encrypted files before creating new ones. -c - deletes encrypted files before creating new ones.
-d - deletes unencrypted files after encryption.
-h - shows help. -h - shows help.

@ -6,7 +6,7 @@ function _optional_clean {
local clean=0 local clean=0
local opt_string='' local opt_string=''
while getopts 'cvh' opt; do while getopts 'cdvh' opt; do
case "$opt" in case "$opt" in
c) clean=1;; 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 { function hide {
_optional_clean "$@" _optional_clean "$@"
@ -45,5 +79,7 @@ function hide {
counter=$((counter+1)) counter=$((counter+1))
done < "$SECRETS_DIR_PATHS_MAPPING" done < "$SECRETS_DIR_PATHS_MAPPING"
_optional_delete "$@"
echo "done. all $counter files are hidden." echo "done. all $counter files are hidden."
} }

@ -31,12 +31,19 @@ function teardown {
} }
@test "run 'hide' with params" { @test "run 'hide' with -c param" {
run git secret hide -v -c run git secret hide -v -c
[ "$status" -eq 0 ] [ "$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" { @test "run 'hide' for multiple users" {
local new_user="user2" local new_user="user2"

Loading…
Cancel
Save