Skip to content

Commit 89b311c

Browse files
committed
Fix for not scanned except the first file #66
- filenames are treated as array (whitespace/newline consideration)
1 parent 6312039 commit 89b311c

1 file changed

Lines changed: 11 additions & 9 deletions

File tree

git-secrets

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,15 @@ load_combined_patterns() {
8181

8282
# Scans files or a repo using patterns.
8383
scan() {
84-
local files="$1" options=""
84+
local files=("${@}") options=""
8585
[ "${SCAN_CACHED}" == 1 ] && options+="--cached"
8686
[ "${SCAN_UNTRACKED}" == 1 ] && options+=" --untracked"
8787
[ "${SCAN_NO_INDEX}" == 1 ] && options+=" --no-index"
8888
# Scan using git-grep if there are no files or if git options are applied.
89-
if [ -z "${files}" ] || [ ! -z "${options}" ]; then
90-
output=$(git_grep $options $files)
89+
if [ ${#files[@]} -eq 0 ] || [ ! -z "${options}" ]; then
90+
output=$(git_grep $options "${files[@]}")
9191
else
92-
output=$(regular_grep $files)
92+
output=$(regular_grep "${files[@]}")
9393
fi
9494
process_output $? "${output}"
9595
}
@@ -110,18 +110,19 @@ scan_history() {
110110
# Note: this function returns 1 on success, 0 on error.
111111
git_grep() {
112112
local options="$1"; shift
113-
local files=$@ combined_patterns=$(load_combined_patterns)
113+
local files=("${@}") combined_patterns=$(load_combined_patterns)
114+
114115
[ -z "${combined_patterns}" ] && return 1
115-
GREP_OPTIONS= LC_ALL=C git grep -nwHEI ${options} "${combined_patterns}" -- $files
116+
GREP_OPTIONS= LC_ALL=C git grep -nwHEI ${options} "${combined_patterns}" -- "${files[@]}"
116117
}
117118

118119
# Performs a regular grep, taking into account patterns and recursion.
119120
# Note: this function returns 1 on success, 0 on error.
120121
regular_grep() {
121-
local files=$@ patterns=$(load_patterns) action='skip'
122+
local files=("${@}") patterns=$(load_patterns) action='skip'
122123
[ -z "${patterns}" ] && return 1
123124
[ ${RECURSIVE} -eq 1 ] && action="recurse"
124-
GREP_OPTIONS= LC_ALL=C grep -d "${action}" -nwHEI "${patterns}" $files
125+
GREP_OPTIONS= LC_ALL=C grep -d "${action}" -nwHEI "${patterns}" "${files[@]}"
125126
}
126127

127128
# Process the given status ($1) and output variables ($2).
@@ -172,7 +173,8 @@ pre_commit_hook() {
172173
# Diff against HEAD if this is not the first commit in the repo.
173174
git rev-parse --verify HEAD >/dev/null 2>&1 && rev="HEAD"
174175
# Filter out deleted files using --diff-filter
175-
IFS=$'\n' scan_with_fn_or_die "scan" "$(git diff-index --diff-filter 'ACMU' --name-only --cached $rev --)"
176+
readarray -t files <<< $(git diff-index --diff-filter 'ACMU' --name-only --cached $rev --)
177+
scan_with_fn_or_die "scan" "${files[@]}"
176178
}
177179

178180
# Determines if merging in a commit will introduce tainted history.

0 commit comments

Comments
 (0)