forked from envoyproxy/envoy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlocal_fix_format.sh
executable file
·66 lines (61 loc) · 2.03 KB
/
local_fix_format.sh
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
62
63
64
65
66
#!/bin/bash
#
# Runs the Envoy format fixers on the current changes. By default, this runs on
# changes that are not yet committed. You can also specify:
#
# -all: runs on the entire repository (very slow)
# -main: runs on the changes made from the main branch
# file1 file2 file3...: runs on the specified files.
#
# To effectively use this script, it's best to run the format fixer before each
# call to 'git commit'. If you forget to do that then you can run with "-main"
# and it will run on all changes you've made since branching from main, which
# will still be relatively fast.
#
# To run this script, you must provide several environment variables:
#
# CLANG_FORMAT -- points to the clang formatter binary, perhaps found in
# $CLANG_TOOLCHAIN/bin/clang-format
# BUILDIFIER_BIN -- buildifier location, perhaps found in $HOME/go/bin/buildifier
# BUILDOZER_BIN -- buildozer location, perhaps found in $HOME/go/bin/buildozer
# If DISPLAY is set, then tkdiff pops up for some BUILD changes.
unset DISPLAY
if [[ $# -gt 0 && "$1" == "-verbose" ]]; then
verbose=1
shift
else
verbose=0
fi
# Runs the formatting functions on the specified args, echoing commands
# if -vergbose was supplied to the script.
function format() {
(
if [[ "$verbose" == "1" ]]; then
set -x
fi
./tools/code_format/check_format.py fix "$1"
./tools/spelling/check_spelling_pedantic.py fix "$1"
)
}
if [[ $# -gt 0 && "$1" == "-all" ]]; then
echo "Checking all files in the repo...this may take a while."
format
else
if [[ $# -gt 0 && "$1" == "-main" ]]; then
shift
echo "Checking all files that have changed since the main branch."
args=$(git diff main | grep ^diff | awk '{print $3}' | cut -c 3-)
elif [[ $# == 0 ]]; then
args=$(git status|grep -E '(modified:|added:)'|awk '{print $2}')
args+=$(git status|grep -E 'new file:'|awk '{print $3}')
else
args="$*"
fi
if [[ "$args" == "" ]]; then
echo No files selected. Bailing out.
exit 0
fi
for arg in $args; do
format "$arg"
done
fi