From 369cdf3ee0908b13acb0c1bd9a17e02289d43491 Mon Sep 17 00:00:00 2001 From: Bernhard Scheirle Date: Sat, 9 Mar 2024 11:02:57 +0100 Subject: [PATCH] Silently ignore changes without change-id, typically merges --- git_gerrit/utils/branch.py | 5 +++-- git_gerrit/utils/localchange.py | 9 ++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/git_gerrit/utils/branch.py b/git_gerrit/utils/branch.py index c30a843..ca43456 100644 --- a/git_gerrit/utils/branch.py +++ b/git_gerrit/utils/branch.py @@ -21,8 +21,9 @@ def get_changes(self) -> list[LocalChange]: return [] commit_hashes = git["log", "--first-parent", "--pretty=%H", f"{self.remote_ref}..{self.local_name}"]().splitlines() - return [LocalChange.from_hash(hash, self.local_name, self.remote_name) - for hash in commit_hashes] + changes = [LocalChange.from_hash(hash, self.local_name, self.remote_name) + for hash in commit_hashes] + return [c for c in changes if c is not None] @classmethod def from_head(cls): diff --git a/git_gerrit/utils/localchange.py b/git_gerrit/utils/localchange.py index 220c263..060a8f1 100644 --- a/git_gerrit/utils/localchange.py +++ b/git_gerrit/utils/localchange.py @@ -19,16 +19,19 @@ def _get_commit_info(cls, hash: str) -> tuple[str, str, datetime.datetime]: """ Returns the commit message, the change id and the timestamp of the commit. """ change_id_prefix = "Change-Id: " out = git["log", "--format=%ct%n%B", "-n", 1, hash]().splitlines() - change_ids = [x for x in out if x.startswith(change_id_prefix)] - assert len(change_ids) != 0, f"Change {hash} has no change id" date = datetime.datetime.fromtimestamp(int(out[0])) subject = out[1] - change_id = change_ids[-1][len(change_id_prefix):] + change_id = "" + change_ids = [x for x in out if x.startswith(change_id_prefix)] + if len(change_ids) != 0: + change_id = change_ids[-1][len(change_id_prefix):] return (subject, change_id, date) @classmethod def from_hash(cls, hash: str, branch_local:str, branch_remote:str): subject, change_id, date = cls._get_commit_info(hash) + if change_id == "": + return None return cls( branch_local=branch_local, branch_remote=branch_remote,