1#!/bin/bash 2# Copyright (c) 2017 Google Inc. 3 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15# 16# Script to determine if source code in Pull Request is properly formatted. 17# Exits with non 0 exit code if formatting is needed. 18# 19# This script assumes to be invoked at the project root directory. 20 21RED='\033[0;31m' 22GREEN='\033[0;32m' 23NC='\033[0m' # No Color 24 25FILES_TO_CHECK=$(git diff --name-only master | grep -v -E "^include/vulkan" | grep -E ".*\.(cpp|cc|c\+\+|cxx|c|h|hpp)$") 26 27if [ -z "${FILES_TO_CHECK}" ]; then 28 echo -e "${GREEN}No source code to check for formatting.${NC}" 29 exit 0 30fi 31 32FORMAT_DIFF=$(git diff -U0 master -- ${FILES_TO_CHECK} | python ./scripts/clang-format-diff.py -p1 -style=file) 33 34if [ -z "${FORMAT_DIFF}" ]; then 35 echo -e "${GREEN}All source code in PR properly formatted.${NC}" 36 exit 0 37else 38 echo -e "${RED}Found formatting errors!${NC}" 39 echo "${FORMAT_DIFF}" 40 exit 1 41fi 42