-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.sh
More file actions
executable file
·61 lines (51 loc) · 1.52 KB
/
run.sh
File metadata and controls
executable file
·61 lines (51 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/bash
# run.sh
#
# The run script for pre-commit hooks that performs pre-commit check
# in a repository within a current working path.
#
# Usage:
# run [--config CONFIG]
#
# --config CONFIG
# Path to a pre-commit configuration YAML file.
# If set, the script will use it instead of the default one.
set -euo pipefail
custom_config=""
while [[ $# -gt 0 ]]; do
case "$1" in
--config=*)
custom_config="${1#--config=}"
shift
;;
--config)
if [[ $# -lt 2 ]]; then
echo >&2 "Error: --config requires a value"
exit 1
fi
custom_config="${2}"
shift 2
;;
*)
echo >&2 "Error: unknown argument '${1}'"
exit 1
;;
esac
done
precommit_root="$(dirname "${0}")"
if [ ! -f "${precommit_root}/.pre-commit-config.path" ]; then
echo >&2 "${0}: pre-commit not installed: run '${precommit_root}/install.sh' first"
exit 1
fi
# Default to legacy isolated venv location for backward compatibility
# with installs that pre-date the VENV argument support.
precommit_venv="${precommit_root}/.venv"
# shellcheck disable=SC1091
source "${precommit_root}/.pre-commit-config.path"
if [ ! -d "${precommit_venv}" ]; then
echo >&2 "${0}: pre-commit not installed: run '${precommit_root}/install.sh' first"
exit 1
fi
# shellcheck disable=SC1091
source "${precommit_venv}/bin/activate"
pre-commit run --all-files --config="${custom_config:-${precommit_config}}"