Skip to content

Commit

Permalink
Exclude empty provider output. Closes #34
Browse files Browse the repository at this point in the history
  • Loading branch information
mtdowling committed Nov 1, 2016
1 parent d23f160 commit 4b5f8de
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
9 changes: 6 additions & 3 deletions git-secrets
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ load_patterns() {
git config --get-all secrets.patterns
# Execute each provider and use their output to build up patterns
git config --get-all secrets.providers | while read -r cmd; do
echo "$(export IFS=$'\n\t '; $cmd)"
local result="$(export IFS=$'\n\t '; $cmd)"
# Do not add empty lines from providers as that would match everything.
if [ -n "${result}" ]; then
echo "$result"
fi
done
}

Expand All @@ -65,8 +69,7 @@ load_allowed() {
load_combined_patterns() {
local patterns=$(load_patterns)
local combined_patterns=''
for pattern in $patterns
do
for pattern in $patterns; do
combined_patterns=${combined_patterns}${pattern}"|"
done
combined_patterns=${combined_patterns%?}
Expand Down
12 changes: 12 additions & 0 deletions test/git-secrets.bats
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,18 @@ load test_helper
echo "$output" | grep -F 'bam'
}

@test "Strips providers that return nothing" {
repo_run git-secrets --add-provider -- 'echo'
[ $status -eq 0 ]
repo_run git-secrets --add-provider -- 'echo 123'
[ $status -eq 0 ]
repo_run git-secrets --list
echo "$output" | grep -F 'echo 123'
echo 'foo' > $TEST_REPO/bad_file
repo_run git-secrets --scan $TEST_REPO/bad_file
[ $status -eq 0 ]
}

@test "--recursive cannot be used with SCAN_*" {
repo_run git-secrets --scan -r --cached
[ $status -eq 1 ]
Expand Down

0 comments on commit 4b5f8de

Please sign in to comment.