[libcamera-devel,v2] utils: checkstyle.py: Don't run commit title checker on staged commits
diff mbox series

Message ID 20230228061859.2957748-1-paul.elder@ideasonboard.com
State Accepted
Headers show
Series
  • [libcamera-devel,v2] utils: checkstyle.py: Don't run commit title checker on staged commits
Related show

Commit Message

Paul Elder Feb. 28, 2023, 6:18 a.m. UTC
When creating a new commit, there is no title, so the title checker
complains that the title isn't compliant and the commit cannot be
created if checkstyle is run as a pre-commit hook. Fix this by skipping
the title checker when run on staged changes.

Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
---
 utils/checkstyle.py | 3 +++
 1 file changed, 3 insertions(+)

Comments

Laurent Pinchart Feb. 28, 2023, 1:35 p.m. UTC | #1
Hi Paul,

Thank you for the patch.

On Tue, Feb 28, 2023 at 03:18:59PM +0900, Paul Elder via libcamera-devel wrote:
> When creating a new commit, there is no title, so the title checker
> complains that the title isn't compliant and the commit cannot be
> created if checkstyle is run as a pre-commit hook. Fix this by skipping
> the title checker when run on staged changes.
> 
> Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
> ---
>  utils/checkstyle.py | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/utils/checkstyle.py b/utils/checkstyle.py
> index 78645410..eb62e4ab 100755
> --- a/utils/checkstyle.py
> +++ b/utils/checkstyle.py
> @@ -360,6 +360,9 @@ class TitleChecker(CommitChecker):
>      def check(cls, commit, top_level):
>          title = commit.title
>  

A comment here would be nice.

        # Skip the check when validating staged changes (as done through a
	# pre-commit hook) as there is no title to check in that case.

With that,

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> +        if isinstance(commit, StagedChanges):
> +            return []
> +
>          # Ignore release commits, they don't need a prefix.
>          if TitleChecker.release_regex.fullmatch(title):
>              return []

Patch
diff mbox series

diff --git a/utils/checkstyle.py b/utils/checkstyle.py
index 78645410..eb62e4ab 100755
--- a/utils/checkstyle.py
+++ b/utils/checkstyle.py
@@ -360,6 +360,9 @@  class TitleChecker(CommitChecker):
     def check(cls, commit, top_level):
         title = commit.title
 
+        if isinstance(commit, StagedChanges):
+            return []
+
         # Ignore release commits, they don't need a prefix.
         if TitleChecker.release_regex.fullmatch(title):
             return []