xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

git hooks All In One

git hooks All In One

$ xgqfrms git:(main) cd .git/
$ .git git:(main) ls
COMMIT_EDITMSG HEAD           branches       description    index          logs           packed-refs
FETCH_HEAD     ORIG_HEAD      config         hooks          info           objects        refs
$ .git git:(main) cd hooks
$ hooks git:(main) ls -al
total 112
drwxr-xr-x  14 xgqfrms-mbp  staff   448 Dec  7 00:01 .
drwxr-xr-x  16 xgqfrms-mbp  staff   512 Dec 26 21:29 ..
-rwxr-xr-x   1 xgqfrms-mbp  staff   478 Dec  7 00:01 applypatch-msg.sample
-rwxr-xr-x   1 xgqfrms-mbp  staff   896 Dec  7 00:01 commit-msg.sample
-rwxr-xr-x   1 xgqfrms-mbp  staff  4655 Dec  7 00:01 fsmonitor-watchman.sample
-rwxr-xr-x   1 xgqfrms-mbp  staff   189 Dec  7 00:01 post-update.sample
-rwxr-xr-x   1 xgqfrms-mbp  staff   424 Dec  7 00:01 pre-applypatch.sample
-rwxr-xr-x   1 xgqfrms-mbp  staff  1643 Dec  7 00:01 pre-commit.sample
-rwxr-xr-x   1 xgqfrms-mbp  staff   416 Dec  7 00:01 pre-merge-commit.sample
-rwxr-xr-x   1 xgqfrms-mbp  staff  1348 Dec  7 00:01 pre-push.sample
-rwxr-xr-x   1 xgqfrms-mbp  staff  4898 Dec  7 00:01 pre-rebase.sample
-rwxr-xr-x   1 xgqfrms-mbp  staff   544 Dec  7 00:01 pre-receive.sample
-rwxr-xr-x   1 xgqfrms-mbp  staff  1492 Dec  7 00:01 prepare-commit-msg.sample
-rwxr-xr-x   1 xgqfrms-mbp  staff  3635 Dec  7 00:01 update.sample

pre-commit

$ code pre-commit.sample

#!/bin/sh
#
# An example hook script to verify what is about to be committed.
# Called by "git commit" with no arguments.  The hook should
# exit with non-zero status after issuing an appropriate message if
# it wants to stop the commit.
#
# To enable this hook, rename this file to "pre-commit".

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

# If you want to allow non-ASCII filenames set this variable to true.
allownonascii=$(git config --type=bool hooks.allownonascii)

# Redirect output to stderr.
exec 1>&2

# Cross platform projects tend to avoid non-ASCII filenames; prevent
# them from being added to the repository. We exploit the fact that the
# printable range starts at the space character and ends with tilde.
if [ "$allownonascii" != "true" ] &&
	# Note that the use of brackets around a tr range is ok here, (it's
	# even required, for portability to Solaris 10's /usr/bin/tr), since
	# the square bracket bytes happen to fall in the designated range.
	test $(git diff --cached --name-only --diff-filter=A -z $against |
	  LC_ALL=C tr -d '[ -~]\0' | wc -c) != 0
then
	cat <<\EOF
Error: Attempt to add a non-ASCII file name.

This can cause problems if you want to work with people on other platforms.

To be portable it is advisable to rename the file.

If you know what you are doing you can disable this check using:

  git config hooks.allownonascii true
EOF
	exit 1
fi

# If there are whitespace errors, print the offending file names and fail.
exec git diff-index --check --cached $against --


husky

Git hooks made easy 🐶 woof!

https://typicode.github.io/husky/#/

https://github.com/typicode/husky

refs

husky

https://www.cnblogs.com/xgqfrms/p/11650177.html

https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks

https://git-scm.com/docs/githooks

https://www.atlassian.com/git/tutorials/git-hooks



©xgqfrms 2012-2021

www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!

原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!


posted @ 2020-12-26 21:27  xgqfrms  阅读(84)  评论(4编辑  收藏  举报