File: clang-format-diff.sh

package info (click to toggle)
binaryen 120-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 41,284 kB
  • sloc: cpp: 189,449; javascript: 62,189; ansic: 14,087; python: 5,379; pascal: 441; sh: 77; makefile: 30; asm: 27
file content (27 lines) | stat: -rwxr-xr-x 770 bytes parent folder | download
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
#!/bin/bash

set -o errexit
set -o pipefail

if [ -n "$1" ]; then
  BRANCH="$1"
elif [ -n "$GITHUB_BASE_REF" ]; then
  BRANCH="origin/$GITHUB_BASE_REF"
else
  BRANCH="@{upstream}"
fi

LLVM_VERSION=${LLVM_VERSION:=17}

MERGE_BASE=$(git merge-base $BRANCH HEAD)
FORMAT_ARGS="--binary=clang-format-${LLVM_VERSION} ${MERGE_BASE}"
FORMAT_MSG=$(git clang-format ${FORMAT_ARGS} -q --diff)
if [ -n "$FORMAT_MSG" -a "$FORMAT_MSG" != "no modified files to format" ]
then
  echo "Please run git clang-format with clang-format-${LLVM_VERSION} before committing, or apply this diff:"
  echo
  # Run git clang-format again, this time without capruting stdout.  This way
  # clang-format format the message nicely and add color.
  git clang-format ${FORMAT_ARGS} -q --diff
  exit 1
fi