Skip to content

Fix up the commit trailers functionality #1576

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 23, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Deprecate Commit.trailers.
  • Loading branch information
itsluketwist committed Apr 22, 2023
commit 78424b56654ad476da4bd2faf88d3875c5265e0d
18 changes: 0 additions & 18 deletions git/objects/commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,24 +335,6 @@ def stats(self) -> Stats:
text = self.repo.git.diff(self.parents[0].hexsha, self.hexsha, "--", numstat=True, no_renames=True)
return Stats._list_from_string(self.repo, text)

@property
def trailers(self) -> Dict[str, str]:
"""Get the trailers of the message as a dictionary

Git messages can contain trailer information that are similar to RFC 822
e-mail headers (see: https://git-scm.com/docs/git-interpret-trailers).

WARNING: This function only returns the latest instance of each trailer key
and will be deprecated soon. Please see either ``Commit.trailers_list`` or ``Commit.trailers_dict``.

:return:
Dictionary containing whitespace stripped trailer information.
Only the latest instance of each trailer key.
"""
return {
k: v[0] for k, v in self.trailers_dict.items()
}

@property
def trailers_list(self) -> List[str]:
"""Get the trailers of the message as a list
Expand Down
6 changes: 0 additions & 6 deletions test/test_commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,10 +523,6 @@ def test_trailers(self):
KEY_1: [VALUE_1_1, VALUE_1_2],
KEY_2: [VALUE_2],
}
assert commit.trailers == {
KEY_1: VALUE_1_1,
KEY_2: VALUE_2,
}

# check that trailer stays empty for multiple msg combinations
msgs = [
Expand All @@ -543,14 +539,12 @@ def test_trailers(self):
commit.message = msg
assert commit.trailers_list == []
assert commit.trailers_dict == {}
assert commit.trailers == {}

# check that only the last key value paragraph is evaluated
commit = copy.copy(self.rorepo.commit("master"))
commit.message = f"Subject\n\nMultiline\nBody\n\n{KEY_1}: {VALUE_1_1}\n\n{KEY_2}: {VALUE_2}\n"
assert commit.trailers_list == [f"{KEY_2}: {VALUE_2}"]
assert commit.trailers_dict == {KEY_2: [VALUE_2]}
assert commit.trailers == {KEY_2: VALUE_2}

def test_commit_co_authors(self):
commit = copy.copy(self.rorepo.commit("4251bd5"))
Expand Down