@@ -88,24 +88,21 @@ def __call__(self):
8888 )
8989 out .success ("Commit validation: successful!" )
9090
91+ def _get_commit_message (self ) -> str | None :
92+ if self .commit_msg_file is None :
93+ # Get commit message from command line (--message)
94+ return self .commit_msg
95+ 96+ with open (self .commit_msg_file , encoding = self .encoding ) as commit_file :
97+ # Get commit message from file (--commit-msg-file)
98+ return commit_file .read ()
99+ 91100 def _get_commits (self ):
92- msg = None
93- # Get commit message from file (--commit-msg-file)
94- if self .commit_msg_file is not None :
95- # Enter this branch if commit_msg_file is "".
96- with open (self .commit_msg_file , encoding = self .encoding ) as commit_file :
97- msg = commit_file .read ()
98- # Get commit message from command line (--message)
99- elif self .commit_msg is not None :
100- msg = self .commit_msg
101- if msg is not None :
102- msg = self ._filter_comments (msg )
103- return [git .GitCommit (rev = "" , title = "" , body = msg )]
101+ if (msg := self ._get_commit_message ()) is not None :
102+ return [git .GitCommit (rev = "" , title = "" , body = self ._filter_comments (msg ))]
104103
105104 # Get commit messages from git log (--rev-range)
106- if self .rev_range :
107- return git .get_commits (end = self .rev_range )
108- return git .get_commits ()
105+ return git .get_commits (end = self .rev_range or "HEAD" )
109106
110107 @staticmethod
111108 def _filter_comments (msg : str ) -> str :
0 commit comments