From e23958ba3b639a24f59c32a018efdbaddd4ca98b Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Sat, 3 Dec 2022 19:10:10 +0100 Subject: make .gitattributes more consistent --- .gitattributes | 2 +- README.md | 2 +- ci | 6 ------ ci.sh | 6 ++++++ scripts/.gitattributes | 1 - scripts/pre-commit | 22 ---------------------- scripts/pre-commit.sh | 22 ++++++++++++++++++++++ scripts/setup-hooks | 16 ---------------- scripts/setup-hooks.sh | 16 ++++++++++++++++ 9 files changed, 46 insertions(+), 47 deletions(-) delete mode 100755 ci create mode 100755 ci.sh delete mode 100644 scripts/.gitattributes delete mode 100755 scripts/pre-commit create mode 100755 scripts/pre-commit.sh delete mode 100755 scripts/setup-hooks create mode 100755 scripts/setup-hooks.sh diff --git a/.gitattributes b/.gitattributes index 1fe0c64..d76765e 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,3 +1,3 @@ * text=auto -/ci text eol=lf +*.sh text eol=lf diff --git a/README.md b/README.md index 1ab9a10..0e585bd 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ directory: ### Code style -Set up the git pre-commit hook by running `./scripts/setup-hook`. +Set up the git pre-commit hook by running `./scripts/setup-hooks.sh`. This depends on `clang-format` and won't allow you to commit code that doesn't pass the formatting check. diff --git a/ci b/ci deleted file mode 100755 index 3261375..0000000 --- a/ci +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env bash - -set -o errexit -o nounset -o pipefail -shopt -s inherit_errexit lastpipe - -docker-compose build --pull diff --git a/ci.sh b/ci.sh new file mode 100755 index 0000000..3261375 --- /dev/null +++ b/ci.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +set -o errexit -o nounset -o pipefail +shopt -s inherit_errexit lastpipe + +docker-compose build --pull diff --git a/scripts/.gitattributes b/scripts/.gitattributes deleted file mode 100644 index fcadb2c..0000000 --- a/scripts/.gitattributes +++ /dev/null @@ -1 +0,0 @@ -* text eol=lf diff --git a/scripts/pre-commit b/scripts/pre-commit deleted file mode 100755 index 8a98a0e..0000000 --- a/scripts/pre-commit +++ /dev/null @@ -1,22 +0,0 @@ -#!/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 )" - -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/pre-commit.sh b/scripts/pre-commit.sh new file mode 100755 index 0000000..8a98a0e --- /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 )" + +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 b/scripts/setup-hooks deleted file mode 100755 index f4d1b1f..0000000 --- a/scripts/setup-hooks +++ /dev/null @@ -1,16 +0,0 @@ -#!/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 )" - -cd -- "$script_dir" - -gitdir="$( git rev-parse --git-dir )" -hooks_dir="$gitdir/hooks" - -symlink_dest="$( realpath "--relative-to=$hooks_dir" -- "$script_dir/pre-commit" )" - -ln -fs -- "$symlink_dest" "$hooks_dir/" diff --git a/scripts/setup-hooks.sh b/scripts/setup-hooks.sh new file mode 100755 index 0000000..6913245 --- /dev/null +++ b/scripts/setup-hooks.sh @@ -0,0 +1,16 @@ +#!/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 )" + +cd -- "$script_dir" + +gitdir="$( git rev-parse --git-dir )" +hooks_dir="$gitdir/hooks" + +symlink_dest="$( realpath "--relative-to=$hooks_dir" -- "$script_dir/pre-commit.sh" )" + +ln -fs -- "$symlink_dest" "$hooks_dir/pre-commit" -- cgit v1.2.3