diff --git a/git-secrets b/git-secrets index 11be153..2be7337 100755 --- a/git-secrets +++ b/git-secrets @@ -111,18 +111,39 @@ 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[@]}" + # let xargs watch for system limit on arg count for us + GREP_OPTIONS= LC_ALL=C xargs git grep -nwHEI ${options} "${combined_patterns}" -- \ + <<<${files[@]} + status=$? + + # xargs returns 123 if any invocations exit with status 1-125 + if [ $status -eq 123 ]; then + return 1 + else + return $status + 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[@]}" + # let xargs watch for system limit on arg count for us + GREP_OPTIONS= LC_ALL=C xargs grep -d "${action}" -nwHEI "${patterns}" <<<${files[@]} + status=$? + + # xargs returns 123 if any invocations exit with status 1-125 + if [ $status -eq 123 ]; then + return 1 + else + return $status + fi } # Process the given status ($1) and output variables ($2).