diff --git a/git-secrets b/git-secrets index 11be153..3e2be47 100755 --- a/git-secrets +++ b/git-secrets @@ -111,18 +111,50 @@ scan_history() { git_grep() { local options="$1"; shift local files=("${@}") combined_patterns=$(load_combined_patterns) + local status=0 [ -z "${combined_patterns}" ] && return 1 - GREP_OPTIONS= LC_ALL=C git grep -nwHEI ${options} "${combined_patterns}" -- "${files[@]}" + if [ ${#files[@]} -eq 0 ]; then + GREP_OPTIONS= LC_ALL=C git grep -nwHEI ${options} "${combined_patterns}" -- + status=$? + else + for file in "${files[@]}" + do + GREP_OPTIONS= LC_ALL=C git grep -nwHEI ${options} "${combined_patterns}" -- "${file}" + (( status += $? )) + done + fi + + if [ $status -gt 0 ]; then + return 1 + else + return 0 + fi } # Performs a regular grep, taking into account patterns and recursion. # Note: this function returns 1 on success, 0 on error. regular_grep() { local files=("${@}") patterns=$(load_patterns) action='skip' + local status=0 [ -z "${patterns}" ] && return 1 [ ${RECURSIVE} -eq 1 ] && action="recurse" - GREP_OPTIONS= LC_ALL=C grep -d "${action}" -nwHEI "${patterns}" "${files[@]}" + if [ ${#files[@]} -eq 0]; then + GREP_OPTIONS= LC_ALL=C grep -d "${action}" -nwHEI "${patterns}" + status=$? + else + for file in "${files[@]}" + do + GREP_OPTIONS= LC_ALL=C grep -d "${action}" -nwHEI "${patterns}" "${file}" + (( status += $? )) + done + fi + + if [ $status -gt 0 ]; then + return 1 + else + return 0 + fi } # Process the given status ($1) and output variables ($2).