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

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

Commit Message

Paul Elder Feb. 27, 2023, 12:15 p.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. 27, 2023, 2:43 p.m. UTC | #1
Hi Paul,

Thank you for the patch.

On Mon, Feb 27, 2023 at 09:15:46PM +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..84f0f50f 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 title == 'Staged changes':
> +            return []
> +

The idea is good, but checking the title seems a bit of a hack. You can
instead check if the commit is an instance of the StagedChanges class.

>          # 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..84f0f50f 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 title == 'Staged changes':
+            return []
+
         # Ignore release commits, they don't need a prefix.
         if TitleChecker.release_regex.fullmatch(title):
             return []