@@ -81,15 +81,15 @@ load_combined_patterns() {
8181
8282# Scans files or a repo using patterns.
8383scan () {
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.
111111git_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.
120121regular_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).
@@ -168,11 +169,14 @@ commit_msg_hook() {
168169# Scans all files that are about to be committed.
169170pre_commit_hook () {
170171 SCAN_CACHED=1
171- local file found_match=0 rev=" 4b825dc642cb6eb9a060e54bf8d69288fbee4904"
172+ local files=() file found_match=0 rev=" 4b825dc642cb6eb9a060e54bf8d69288fbee4904"
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+ while IFS= read -r file; do
177+ [ -n " $file " ] && files+=(" $file " )
178+ done <<< " $(git diff-index --diff-filter 'ACMU' --name-only --cached $rev --)"
179+ scan_with_fn_or_die " scan" " ${files[@]} "
176180}
177181
178182# Determines if merging in a commit will introduce tainted history.
0 commit comments