Git allows the use of various hooks (see [*]). In particular it provides the 'post-commit' hook, which is a convenient place to run the PatchCheck script.
[*] https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks Cc: Bob Feng <bob.c.f...@intel.com> Cc: Liming Gao <liming....@intel.com> Signed-off-by: Philippe Mathieu-Daude <phi...@redhat.com> --- I'm hitting a egg/chicken problem here. If I add this script without CRLF, PatchCheck complains: Code format is not valid: * Line ending ('\n') is not CRLF File: BaseTools/Scripts/GitPostCommitHook.py Line: #!/usr/bin/python However if I convert it to CRLF, then Linux does not recognize the shebang, and if I symlink the script, when the hook is executed I get: fatal: cannot run .git/hooks/post-commit: No such file or directory Because the interpreter expects the shebang line with Unix line ending (linefeed only). As a kludge I'm happy using: $ echo > .git/hooks/post-commit #!/bin/sh test -e BaseTools/Scripts/GitPostCommitHook.py && exec python3 BaseTools/Scripts/GitPostCommitHook.py EOF $ chmod +x .git/hooks/post-commit (The 'test' allow to checkout to older references where the script is not available). Cc: Laszlo Ersek <ler...@redhat.com> Cc: Ard Biesheuvel <ard.biesheu...@linaro.org> Cc: Leif Lindholm <leif.lindh...@linaro.org> --- BaseTools/Scripts/GitPostCommitHook.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100755 BaseTools/Scripts/GitPostCommitHook.py diff --git a/BaseTools/Scripts/GitPostCommitHook.py b/BaseTools/Scripts/GitPostCommitHook.py new file mode 100755 index 000000000000..4ea933a7eedf --- /dev/null +++ b/BaseTools/Scripts/GitPostCommitHook.py @@ -0,0 +1,21 @@ +#!/usr/bin/python +## @file +# Run PatchCheck on the last commit. +# +# Copyright (c) 2019, Red Hat, Inc. +# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +# To have git run this script after each commit, create a symbolic +# link or copy it to .git/hooks/post-commit in your EDK2 repository. + +import os +import sys + +if __name__ == '__main__': + sys.path.append(os.path.join(os.environ['EDK_TOOLS_PATH'], 'Scripts')) + from PatchCheck import CheckGitCommits, Verbose + Verbose.level = Verbose.QUIET + GIT_REFERENCE = 'HEAD' + COMMIT_COUNT = 1 + sys.exit(CheckGitCommits(GIT_REFERENCE, COMMIT_COUNT).ok) -- 2.21.0 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#51789): https://edk2.groups.io/g/devel/message/51789 Mute This Topic: https://groups.io/mt/67004028/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-