From: "Philippe Mathieu-Daudé" <philmd@redhat.com>
To: devel@edk2.groups.io
Cc: Philippe Mathieu-Daude <philmd@redhat.com>,
Bob Feng <bob.c.feng@intel.com>,
Liming Gao <liming.gao@intel.com>,
Laszlo Ersek <lersek@redhat.com>,
Ard Biesheuvel <ard.biesheuvel@linaro.org>,
Leif Lindholm <leif.lindholm@linaro.org>
Subject: [PATCH 3/6] BaseTools/Scripts: Add GitPostCommitHook.py
Date: Thu, 5 Dec 2019 17:12:31 +0100 [thread overview]
Message-ID: <20191205161234.25071-4-philmd@redhat.com> (raw)
In-Reply-To: <20191205161234.25071-1-philmd@redhat.com>
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.feng@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Signed-off-by: Philippe Mathieu-Daude <philmd@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 <lersek@redhat.com>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Leif Lindholm <leif.lindholm@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
next prev parent reply other threads:[~2019-12-05 16:12 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-12-05 16:12 [PATCH 0/6] BaseTools: Improve PatchCheck and add GitPostCommitHook Philippe Mathieu-Daudé
2019-12-05 16:12 ` [PATCH 1/6] BaseTools/PatchCheck: Stop parsing commit message after --- separator Philippe Mathieu-Daudé
2019-12-05 19:02 ` Laszlo Ersek
2019-12-05 16:12 ` [PATCH 2/6] BaseTools/PatchCheck: Add a --quiet option Philippe Mathieu-Daudé
2019-12-05 16:12 ` Philippe Mathieu-Daudé [this message]
2019-12-05 19:24 ` [PATCH 3/6] BaseTools/Scripts: Add GitPostCommitHook.py Laszlo Ersek
2019-12-05 16:12 ` [PATCH 4/6] BaseTools/PatchCheck: Extract the run_git() function Philippe Mathieu-Daudé
2019-12-05 16:12 ` [PATCH 5/6] BaseTools/PatchCheck: Add printw() function to print warnings Philippe Mathieu-Daudé
2019-12-05 16:12 ` [PATCH 6/6] BaseTools/PatchCheck: Allow to print colored warnings Philippe Mathieu-Daudé
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20191205161234.25071-4-philmd@redhat.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox