Skip to content

Make apply-format respect git config clangformat.{binary,extensions} #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions apply-format
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,16 @@ fi
#######################################

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

declare extensions="$(git config clangformat.extensions 2>/dev/null)"
if [ -z "$extensions" ]; then
extensions="c,cpp,cxx,cc,h,hpp,m,mm,js,java"
fi

if [ -z "$format" ]; then
error_exit \
$'You need to install clang-format.\n' \
Expand All @@ -193,7 +198,7 @@ if [ -z "$format" ]; then
$'older distro versions, clang-format-VERSION.\n' \
$'On Fedora it\'s available in the clang package.\n' \
$'You can also specify your own path for clang-format by setting the\n' \
$'$CLANG_FORMAT environment variable.'
$'git config clangformat.binary config option.'
fi

# clang-format-diff.
Expand Down Expand Up @@ -326,9 +331,10 @@ else # Diff-only.

"${git_args[@]}" "$@" \
| "${format_diff_args[@]}" \
-binary="$format" \
-p1 \
-style="$style" \
-iregex="$exclusions_regex"'.*\.(c|cpp|cxx|cc|h|hpp|m|mm|js|java)' \
-iregex="$exclusions_regex"'.*\.('"${extensions//,/|}"')' \
> "$patch_dest"
# Starting with version 18, clang-format-diff exits with status 1 when there
# are diffs, but other non-zero statuses indicate errors.
Expand Down