From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.61]) by mx.groups.io with SMTP id smtpd.web12.11650.1575562374646797441 for ; Thu, 05 Dec 2019 08:12:54 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=hUbX71RI; spf=pass (domain: redhat.com, ip: 205.139.110.61, mailfrom: philmd@redhat.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1575562373; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BdTfXX3wX+pjZtUX89Q8KWSTYYyO99ghijDn0rlshJc=; b=hUbX71RIb1FRLQnaTw+XlH+vRGieRPNq3iiuVFavbnYzvIOmw8REMRh1ab/BUloYQk9sKZ nqDFs/jcIc7Zg3j4CokrVYdB7JHl1RVPCW1Z0c+cak+1DJ3fiNDIywzsLZjqGb5Iu5z1Zh vIAJ/2/GKiBoNKOMvtMC4K6J6kFVX7k= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-362-pWhh5QBNMP2O-7j4bI1DRw-1; Thu, 05 Dec 2019 11:12:49 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B0C9112D6581; Thu, 5 Dec 2019 16:12:48 +0000 (UTC) Received: from x1w.redhat.com (ovpn-205-76.brq.redhat.com [10.40.205.76]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E366110013D9; Thu, 5 Dec 2019 16:12:45 +0000 (UTC) From: =?UTF-8?B?UGhpbGlwcGUgTWF0aGlldS1EYXVkw6k=?= To: devel@edk2.groups.io Cc: Philippe Mathieu-Daude , Bob Feng , Liming Gao , Laszlo Ersek , Ard Biesheuvel , Leif Lindholm Subject: [PATCH 3/6] BaseTools/Scripts: Add GitPostCommitHook.py Date: Thu, 5 Dec 2019 17:12:31 +0100 Message-Id: <20191205161234.25071-4-philmd@redhat.com> In-Reply-To: <20191205161234.25071-1-philmd@redhat.com> References: <20191205161234.25071-1-philmd@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-MC-Unique: pWhh5QBNMP2O-7j4bI1DRw-1 X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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 Cc: Liming Gao Signed-off-by: Philippe Mathieu-Daude --- 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 Cc: Ard Biesheuvel Cc: Leif Lindholm --- 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/Git= PostCommitHook.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__ =3D=3D '__main__': + sys.path.append(os.path.join(os.environ['EDK_TOOLS_PATH'], 'Scripts')) + from PatchCheck import CheckGitCommits, Verbose + Verbose.level =3D Verbose.QUIET + GIT_REFERENCE =3D 'HEAD' + COMMIT_COUNT =3D 1 + sys.exit(CheckGitCommits(GIT_REFERENCE, COMMIT_COUNT).ok) --=20 2.21.0