Skip to content

Commit

Permalink
Silently ignore changes without change-id, typically merges
Browse files Browse the repository at this point in the history
  • Loading branch information
Scheirle committed Mar 9, 2024
1 parent 488382a commit 369cdf3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
5 changes: 3 additions & 2 deletions git_gerrit/utils/branch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
9 changes: 6 additions & 3 deletions git_gerrit/utils/localchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 369cdf3

Please sign in to comment.