1#!/bin/sh 2# Owner: Hanming Zeng (hanmeow@) 3 4# Please note: this script will override any local pre-commit hooks under ./git/hooks 5 6# This script will create a "precommit" file in ./git/hooks to auto 7# format code before commit using git clang-format 8 9# To undo this script, run "rm .git/hooks/pre-commit" 10 11# directory where this script is in 12DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" 13GIT_ROOT=$(git rev-parse --show-toplevel) 14 15git config --local clangFormat.style file 16git config --local --path clangFormat.stylePath $GIT_ROOT/.clang-format 17 18cp "${DIR}/pre-commit" "${GIT_ROOT}/.git/hooks/pre-commit" 19chmod +x "${GIT_ROOT}/.git/hooks/pre-commit" 20 21# Track Usage 22MY_PATH=${PWD//\//"%2F"} 23curl "https://us-central1-si-sw-eng-prod-team.cloudfunctions.net/trackAutoFormatUsage?user=${USER}&pwd=${MY_PATH}×tamp=$(date +%s)&type=INSTALL" > /dev/null 2>&1 24