diff options
author | Kieran Bingham <kieran.bingham@ideasonboard.com> | 2023-07-10 17:35:09 +0100 |
---|---|---|
committer | Kieran Bingham <kieran.bingham@ideasonboard.com> | 2023-07-18 09:26:31 +0100 |
commit | baaad1bf9e2acb3ab721945041ef46496951c04c (patch) | |
tree | e1f0af024fbcd9487ff411d5ba05577e46805250 /utils/checkstyle.py | |
parent | e2f0ad27b18b1502f59268bda2eeff4a7a21055c (diff) |
utils: checkstyle.py: Check trailers for Amendment commits
The commit trailers are checked as part of processing the commit message
with the newly introduced TrailersChecker.
This relies on the trailers property being correctly exposed by the
Commit object, and is implemented for the base Commit but not processed
for Amendment commits.
Refactor the trailer property handling to a helper function in the base
Commit class and make use of it with a newly added call to obtain the
existing Trailers from the most recent commit when using Amendment.
Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
Tested-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Diffstat (limited to 'utils/checkstyle.py')
-rwxr-xr-x | utils/checkstyle.py | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/utils/checkstyle.py b/utils/checkstyle.py index 5663af81..214509bc 100755 --- a/utils/checkstyle.py +++ b/utils/checkstyle.py @@ -208,6 +208,17 @@ class Commit: self.commit = commit self._parse() + def _parse_trailers(self, lines): + self._trailers = [] + for index in range(1, len(lines)): + line = lines[index] + if not line: + break + + self._trailers.append(line) + + return index + def _parse(self): # Get the commit title and list of files. ret = subprocess.run(['git', 'show', '--format=%s%n%(trailers:only,unfold)', '--name-status', @@ -217,14 +228,7 @@ class Commit: self._title = lines[0] - self._trailers = [] - for index in range(1, len(lines)): - line = lines[index] - if not line: - break - - self._trailers.append(line) - + index = self._parse_trailers(lines) self._files = [CommitFile(f) for f in lines[index:] if f] def files(self, filter='AMR'): @@ -283,6 +287,12 @@ class Amendment(Commit): stdout=subprocess.PIPE).stdout.decode('utf-8') self._files = [CommitFile(f) for f in ret.splitlines()] + # Parse trailers from the existing commit only. + ret = subprocess.run(['git', 'show', '--format=%n%(trailers:only,unfold)', + '--no-patch'], + stdout=subprocess.PIPE).stdout.decode('utf-8') + self._parse_trailers(ret.splitlines()) + def get_diff(self, top_level, filename): diff = subprocess.run(['git', 'diff', '--staged', 'HEAD~', '--', '%s/%s' % (top_level, filename)], |