Skip to content

Commit 3180a7a

Browse files
author
Ailin Nemui
committed
Make apply-format respect git config clangformat.{binary,extensions}
1 parent ac35e70 commit 3180a7a

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

apply-format

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,16 @@ fi
180180
#######################################
181181

182182
# clang-format.
183-
declare format="${CLANG_FORMAT:-}"
183+
declare format="$(git config clangformat.binary 2>/dev/null)"
184184
if [ -z "$format" ]; then
185185
format=$(type -p clang-format)
186186
fi
187187

188+
declare extensions="$(git config clangformat.extensions 2>/dev/null)"
189+
if [ -z "$extensions" ]; then
190+
extensions="c,cpp,cxx,cc,h,hpp,m,mm,js,java"
191+
fi
192+
188193
if [ -z "$format" ]; then
189194
error_exit \
190195
$'You need to install clang-format.\n' \
@@ -193,7 +198,7 @@ if [ -z "$format" ]; then
193198
$'older distro versions, clang-format-VERSION.\n' \
194199
$'On Fedora it\'s available in the clang package.\n' \
195200
$'You can also specify your own path for clang-format by setting the\n' \
196-
$'$CLANG_FORMAT environment variable.'
201+
$'git config clangformat.binary config option.'
197202
fi
198203

199204
# clang-format-diff.
@@ -322,9 +327,10 @@ else # Diff-only.
322327

323328
"${git_args[@]}" "$@" \
324329
| "${format_diff_args[@]}" \
330+
-binary="$format" \
325331
-p1 \
326332
-style="$style" \
327-
-iregex="$exclusions_regex"'.*\.(c|cpp|cxx|cc|h|hpp|m|mm|js|java)' \
333+
-iregex="$exclusions_regex"'.*\.('"${extensions//,/|}"')' \
328334
> "$patch_dest" \
329335
|| exit 1
330336

0 commit comments

Comments
 (0)