blob: 7abdab86116d57c123b8431c791b26e127157eea [file] [log] [blame]
Martin Rothd81debd2022-06-03 00:06:57 -06001#!/usr/bin/env sh
2#
3# SPDX-License-Identifier: GPL-2.0-only
4
5# This file is sourced by the linters so that each one doesn't have to
6# specify these routines individually
7
8LC_ALL=C export LC_ALL
9
10if [ -z "$GIT" ]; then
11 GIT="$(command -v git)"
12else
13 # If git is specified, Do a basic check that it runs and seems like
14 # it's actually git
15 if ! "${GIT}" --version | grep -q git; then
16 echo "Error: ${GIT} does not seem to be valid."
17 exit 1;
18 fi
19fi
20
21if [ "$(${GIT} rev-parse --is-inside-work-tree 2>/dev/null)" = "true" ]; then
22 IN_GIT_TREE=1
23else
24 IN_GIT_TREE=0
25fi
26
27if [ "${IN_GIT_TREE}" -eq 1 ] && [ -z "${GIT}" ]; then
28 echo "This test needs git to run. Please install it, then run this test again."
29 exit 1
30fi
31
32# Use git ls-files if the code is in a git repo, otherwise use find.
33if [ "${IN_GIT_TREE}" -eq 1 ]; then
34 FIND_FILES="${GIT} ls-files"
35else
Martin Roth95b5b022022-10-17 07:53:16 -060036 FIND_FILES="find "
37 FINDOPTS="-type f"
Martin Rothd81debd2022-06-03 00:06:57 -060038fi
39
40# Use git grep if the code is in a git repo, otherwise use grep.
41if [ "${IN_GIT_TREE}" -eq 1 ]; then
42 GREP_FILES="${GIT} grep"
43else
44 GREP_FILES="grep -r"
45fi