diff options
| author | Egor Tensin <egor@tensin.name> | 2026-06-12 23:10:11 +0200 |
|---|---|---|
| committer | Egor Tensin <egor@tensin.name> | 2026-06-12 23:10:11 +0200 |
| commit | 3fb4c7a44e294a13754267e3ebe9cbfdb74e4a77 (patch) | |
| tree | 1a9c04b599345568036f3538001cae307072e907 | |
| parent | add .git-blame-ignore-revs (diff) | |
| download | winapi-debug-3fb4c7a44e294a13754267e3ebe9cbfdb74e4a77.tar.gz winapi-debug-3fb4c7a44e294a13754267e3ebe9cbfdb74e4a77.zip | |
add scripts to setup git hooks
Diffstat (limited to '')
| -rw-r--r-- | .gitattributes | 2 | ||||
| -rwxr-xr-x | scripts/pre-commit.sh | 22 | ||||
| -rwxr-xr-x | scripts/setup-hooks.sh | 31 |
3 files changed, 55 insertions, 0 deletions
diff --git a/.gitattributes b/.gitattributes index 176a458..d76765e 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1 +1,3 @@ * text=auto + +*.sh text eol=lf diff --git a/scripts/pre-commit.sh b/scripts/pre-commit.sh new file mode 100755 index 0000000..fd1f7dd --- /dev/null +++ b/scripts/pre-commit.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash + +set -o errexit -o nounset -o pipefail +shopt -s inherit_errexit lastpipe + +if ! command -v git-clang-format &> /dev/null; then + echo 'Please make sure git-clang-format is available.' >&2 + exit 1 +fi + +output="$( git clang-format --style file --diff )" || true + +ok1='no modified files to format' +ok2='clang-format did not modify any files' + +if [ "$output" != "$ok1" ] && [ "$output" != "$ok2" ]; then + echo "$output" + echo + echo 'clang-format required some formatting fixes.' + echo 'Please stage your changes, run `git clang-format`, review the formatting fixes, and commit.' + exit 1 +fi diff --git a/scripts/setup-hooks.sh b/scripts/setup-hooks.sh new file mode 100755 index 0000000..0530bd5 --- /dev/null +++ b/scripts/setup-hooks.sh @@ -0,0 +1,31 @@ +#!/usr/bin/env bash + +set -o errexit -o nounset -o pipefail +shopt -s inherit_errexit lastpipe + +script_dir="$( dirname -- "${BASH_SOURCE[0]}" )" +script_dir="$( cd -- "$script_dir" && pwd )" + +setup_clang_format_hook() { + local gitdir + gitdir="$( git rev-parse --git-dir )" + local hooks_dir + hooks_dir="$gitdir/hooks" + + local symlink_dest + symlink_dest="$( realpath "--relative-to=$hooks_dir" -- "$script_dir/pre-commit.sh" )" + + ln -fs -- "$symlink_dest" "$hooks_dir/pre-commit" +} + +setup_git_blame() { + git config blame.ignoreRevsFile .git-blame-ignore-revs +} + +main() { + cd -- "$script_dir" + setup_clang_format_hook + setup_git_blame +} + +main |
