From e7152301dddc91c7667f544d57664f2b01b28e43 Mon Sep 17 00:00:00 2001 From: bom Date: Thu, 23 Feb 2023 15:33:00 +0100 Subject: [PATCH] Add utility functions to git_repository --- git_repository.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/git_repository.py b/git_repository.py index 4fdfc64..a448847 100644 --- a/git_repository.py +++ b/git_repository.py @@ -16,9 +16,14 @@ class GitRepository(): inst.latest_commit = commit_string return inst + def get_latest_n_commits(self, n: int): + self.system_repository.run_checked('git', 'log', '--oneline', '--format="%s %b"', f'-n {n}') + return self.system_repository.stdout + def get_latest_commit(self): - self.system_repository.run_checked('git', 'log', '--oneline', '--format="%s %b"', '-n 1') - self.latest_commit = " ".join(self.system_repository.stdout) # returns a list of strings otherwise + output = self.get_latest_n_commits(1) + self.latest_commit = " ".join(output) # returns a list of strings otherwise + return self.latest_commit def get_release_type_from_latest_commit(self): if self.latest_commit is None: @@ -38,6 +43,9 @@ class GitRepository(): def tag_annotated(self, annotation: str, message: str): self.system_repository.run_checked('git', 'tag', '-a', annotation, '-m', message) + def tag_annotated(self, annotation: str, message: str, count: int): + self.system_repository.run_checked('git', 'tag', '-a', annotation, '-m', message, f'HEAD~{count}') + def get_current_branch(self): self.system_repository.run_checked('git', 'branch', '--show-current')