Rewrapping Commit Message Text Using 'git filter-repo
'
#370
-
I forgot to set Git's 'core.editor' configuration variable globally for/on the machine I'm working on at the moment to '
at the root of my repository, but this resulted in the following error:
and that internal '
This error suggests I'm missing a type conversion (via ' |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
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):
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 backslashreplace will put escape codes into the resulting string, and they'll be transliterated back into ascii characters of the escape sequence -- i.e. it will not be the same as the original. If your commit messages are not all utf-8, you could do a little better here by using a commit callback together with both commit.message and commit.encoding. So long as any non-utf-8 commit message has the correct encoding recorded in the commit object and has only valid characters from such encodings in the commit message, then you'd be safe. Personally, I've only ever seen one repo use a non-utf-8 encoding for any commits, and it only did so for I think 1, maybe 2 commits in its many thousands of commits history. So, in practice, just assuming utf-8 is likely good enough. |
Beta Was this translation helpful? Give feedback.
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):
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…