◐ Shell
reader mode source ↗
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
File filter
Conversations
Jump to
Diff view
Apply and reload
Show whitespace
Diff view
Apply and reload
40 changes: 23 additions & 17 deletions git/objects/commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,14 +450,7 @@ def trailers_list(self) -> List[Tuple[str, str]]:
:return:
List containing key-value tuples of whitespace stripped trailer information.
"""
cmd = ["git", "interpret-trailers", "--parse"]
proc: Git.AutoInterrupt = self.repo.git.execute( # type: ignore[call-overload]
cmd,
as_process=True,
istream=PIPE,
)
trailer: str = proc.communicate(str(self.message).encode())[0].decode("utf8")
trailer = trailer.strip()

if not trailer:
return []
Expand All @@ -469,6 +462,27 @@ def trailers_list(self) -> List[Tuple[str, str]]:

return trailer_list

@property
def trailers_dict(self) -> Dict[str, List[str]]:
"""Get the trailers of the message as a dictionary.
Expand Down Expand Up @@ -699,15 +713,7 @@ def create_from_tree(
trailer_args.append("--trailer")
trailer_args.append(f"{key}: {val}")

cmd = [repo.git.GIT_PYTHON_GIT_EXECUTABLE, "interpret-trailers"] + trailer_args
proc: Git.AutoInterrupt = repo.git.execute( # type: ignore[call-overload]
cmd,
as_process=True,
istream=PIPE,
)
stdout_bytes, _ = proc.communicate(str(message).encode())
finalize_process(proc)
message = stdout_bytes.decode("utf8")
# END apply trailers

# CREATE NEW COMMIT
65 changes: 65 additions & 0 deletions test/test_commit.py
Original file line number Diff line number Diff line change
@@ -622,6 +622,71 @@ def test_create_from_tree_with_trailers_list(self, rw_dir):
"Issue": ["456"],
}

@with_rw_directory
def test_index_commit_with_trailers(self, rw_dir):
"""Test that IndexFile.commit() supports adding trailers."""
Expand Down
Loading
Toggle all file notes Toggle all file annotations