33import os
44import re
55import sys
6- from typing import Any
6+ from typing import Any , TypedDict
77
88from commitizen import factory , git , out
99from commitizen .config import BaseConfig
1414)
1515
1616
17+ class CheckArgs (TypedDict , total = False ):
18+ commit_msg_file : str
19+ commit_msg : str
20+ rev_range : str
21+ allow_abort : bool
22+ message_length_limit : int
23+ allowed_prefixes : list [str ]
24+ message : str
25+ default_range : bool
26+ verbose : bool
27+
28+
1729class Check :
1830 """Check if the current commit msg matches the commitizen format."""
1931
@@ -31,7 +43,9 @@ def __init__(self, config: BaseConfig, arguments: dict[str, Any], cwd=os.getcwd(
3143 self .allow_abort : bool = bool (
3244 arguments .get ("allow_abort" , config .settings ["allow_abort" ])
3345 )
34- self .max_msg_length : int = arguments .get ("message_length_limit" , 0 )
46+ self .default_range = bool (arguments .get ("default_range" ))
47+ self .verbose = bool (arguments .get ("verbose" ))
48+ self .max_msg_length = arguments .get ("message_length_limit" , 0 )
3549
3650 # we need to distinguish between None and [], which is a valid value
3751
@@ -48,10 +62,14 @@ def __init__(self, config: BaseConfig, arguments: dict[str, Any], cwd=os.getcwd(
4862 self .encoding = config .settings ["encoding" ]
4963 self .cz = factory .committer_factory (self .config )
5064
51- def _valid_command_argument (self ):
52- num_exclusive_args_provided = sum (
65+ def _valid_command_argument (self ) -> None :
66+ num_exclusive_args_provided = self . default_range + sum (
5367 arg is not None
54- for arg in (self .commit_msg_file , self .commit_msg , self .rev_range )
68+ for arg in (
69+ self .commit_msg_file ,
70+ self .commit_msg ,
71+ self .rev_range ,
72+ )
5573 )
5674 if num_exclusive_args_provided == 0 and not sys .stdin .isatty ():
5775 self .commit_msg = sys .stdin .read ()
@@ -102,7 +120,10 @@ def _get_commits(self):
102120 return [git .GitCommit (rev = "" , title = "" , body = self ._filter_comments (msg ))]
103121
104122 # Get commit messages from git log (--rev-range)
105- return git .get_commits (end = self .rev_range or "HEAD" )
123+ return git .get_commits (
124+ git .get_default_branch () if self .default_range else None ,
125+ self .rev_range or "HEAD" ,
126+ )
106127
107128 @staticmethod
108129 def _filter_comments (msg : str ) -> str :
@@ -136,6 +157,9 @@ def _filter_comments(msg: str) -> str:
136157 return "\n " .join (lines )
137158
138159 def validate_commit_message (self , commit_msg : str , pattern : str ) -> bool :
160+ if self .verbose :
161+ out .info (commit_msg )
162+
139163 if not commit_msg :
140164 return self .allow_abort
141165
0 commit comments