Skip to content

Rewrapping Commit Message Text Using 'git filter-repo' #370

Answered by newren
RandomDSdevel asked this question in Q&A
Discussion options

You must be logged in to vote

None of the data in git-filter-repo is a string; it uses bytestrings everywhere.

Try this:

textwrap.fill(b'foo bar', width=3)

You'll see the same basic python stack trace. To fix the problem, you need to convert message from bytestring to string, then do the textwrap.fill, then convert back to bytestring. This would look something like (warning: untested):

git filter-repo --force --message-callback '
  import textwrap

  return textwrap.fill(message.decode('utf-8', 'backslashreplace'), width=80).encode()
'

That would work with about all but one of the repositories I've ever worked on. However...the assumption that all commit messages are utf-8 could byte you; if it's wrong, the backslash…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@RandomDSdevel
Comment options

Answer selected by RandomDSdevel
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants