mirror of
https://github.com/zigzap/zap.git
synced 2025-10-20 23:24:09 +00:00
added precommit-hook script
This commit is contained in:
parent
e9892c8ba0
commit
084d335661
2 changed files with 53 additions and 18 deletions
|
@ -1,23 +1,6 @@
|
||||||
# Contributing to ZAP
|
# Contributing to ZAP
|
||||||
|
|
||||||
## The git pre-commit hook
|
Contributions are welcome! 🙏
|
||||||
|
|
||||||
**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.)
|
|
||||||
|
|
||||||
## Communicating
|
## 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
|
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.
|
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.)
|
||||||
|
|
37
precommit-hook.sh
Executable file
37
precommit-hook.sh
Executable file
|
@ -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
|
||||||
|
|
Loading…
Add table
Reference in a new issue