From 084d3356618214481086a1da51a9df667ca1d375 Mon Sep 17 00:00:00 2001 From: Rene Schallner Date: Mon, 16 Jan 2023 01:34:27 +0100 Subject: [PATCH] added precommit-hook script --- CONTRIBUTING.md | 34 ++++++++++++++++------------------ precommit-hook.sh | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 18 deletions(-) create mode 100755 precommit-hook.sh diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f83ac89..e0cc9d0 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,23 +1,6 @@ # Contributing to ZAP -## The git pre-commit hook - -**NOTE**: The discussed pre-commit hook doesn't exist yet. I plan to introduce -it soon. At least the (mental) note is typed into existence now. - -git hook for add / commit, checking for src/deps/facilio in the file list that -only lets you go through with the operation if a specific env var is set - -why is that? we don't use a fork of facilio. we use their repo as submodule. on -build, we apply a patch to the submodule. after applying, the submodule is -dirty. it refers to a new head only present on the current machine. if we were -to commit the submodule now and push those changes, future git submodule update ---init calls will fail on fresh clones of the repo. We want to avoid this -mistake that easily happens if you use a `git add . && git commit` workflow. On -the other hand, if upstream facilio changes, we still want to be able to upgrade -to it by pulling the changes and recording the new head via git commit to our -own repo. Hence, just ignoring the submodule via `.gitignore` is not an option. -That's why we introduced the hook (// that gets installed on build.) +Contributions are welcome! 🙏 ## Communicating @@ -34,3 +17,18 @@ server](https://discord.gg/CBzE3VMb) under the handle renerocksai Pull-requests and issues are, of course, welcome, too - and may be, for the time being, the most both sane and GitHub-friendly way of communicating. +## The git pre-commit hook + +This hook is checking for src/deps/facilio in the file list that +only lets you go through with the operation if a specific env var is set + +why is that? we don't use a fork of facilio. we use their repo as submodule. on +build, we apply a patch to the submodule. after applying, the submodule is +dirty. it refers to a new head only present on the current machine. if we were +to commit the submodule now and push those changes, future git submodule update +--init calls will fail on fresh clones of the repo. We want to avoid this +mistake that easily happens if you use a `git add . && git commit` workflow. On +the other hand, if upstream facilio changes, we still want to be able to upgrade +to it by pulling the changes and recording the new head via git commit to our +own repo. Hence, just ignoring the submodule via `.gitignore` is not an option. +That's why we introduced the hook (// that gets installed on build.) diff --git a/precommit-hook.sh b/precommit-hook.sh new file mode 100755 index 0000000..0d2b616 --- /dev/null +++ b/precommit-hook.sh @@ -0,0 +1,37 @@ +#!/bin/sh + +# this file is installed in the repository as file: .git/hooks/pre-commit + +# we check for `./src/deps/facilio` in the list of files to be committed and +# only allow to proceed if the IKNOWWHATIMDOING env var is set + +if git rev-parse --verify HEAD >/dev/null 2>&1 +then + against=HEAD +else + # Initial commit: diff against an empty tree object + against=$(git hash-object -t tree /dev/null) +fi + +# Redirect output to stderr. +exec 1>&2 + + +if git diff --name-only --cached --diff-filter=M | grep 'src/deps/facilio' > /dev/null; then + if [ "$IKNOWWHATIMDOING" = "" ] ; then + cat <<\EOF +Error: src/deps/facilio is staged for commit. + +This is most likely unintentional. Pease consider if this is what you want. + +See `CONTRIBUTING.md` for an explaination. + +If you know what you are doing you can disable this check using: + + IKNOWWHATIMDOING=true git commit ... +EOF + exit 1 + fi + echo "WARNING: src/deps/facilio is staged for commit. See CONTRIBUTING.md" +fi +