diff --git a/apply-format b/apply-format index 5e74807..e5b9a17 100755 --- a/apply-format +++ b/apply-format @@ -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' \ @@ -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. @@ -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.