Skip to content

Commit

Permalink
Fix appending trailers to git commits
Browse files Browse the repository at this point in the history
Previously trailers were not properly added to end of git commit
messages. Apparently, trailers were overwriting the entire message
because the file was not opened and flushed properly.

Signed-off-by: Brendan Higgins <brendanhiggins@google.com>
  • Loading branch information
bjh83 authored and dlatypov committed Jun 17, 2022
1 parent fdd1830 commit dac3754
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,9 @@ def _set_trailers(self, patch: Patch) -> str:
# Add trailers, changing them if they exist.
# It's _highly_ unlikely that they'd exist, but this seems to be the
# most sane way of handling that edge case.
with tempfile.NamedTemporaryFile(mode='wt') as f:
with tempfile.NamedTemporaryFile(mode='w+') as f:
f.write(original_message)
f.flush() # Flush before we write to the file externally below
self._git('interpret-trailers', '--in-place', '--if-exists=addIfDifferent',
'--trailer', change_id_trailer, '--trailer', lore_trailer, f.name)
return self._git.commit('--amend', '-F', f.name)
Expand Down

0 comments on commit dac3754

Please sign in to comment.