I'm using git filter-repo to rewrite the emails of the commit authors on a git repository.
The commit.author_email
field is in this format:
AA01\myuserid
Yes, I know that this does not resemble an email address but it is what it is. What I need to achieve is setting the commit author's email to the second part of the commit.author_email
field (e.g. myuserid
)
This is the command I'm executing to split
git filter-repo --force --refs master --commit-callback '
>> commit.author_email_split = commit.author_email.split("\\")
>> '
For now, I just want to let the split work but it fails with the error below:
Traceback (most recent call last):
File "C:\git-filter-repo\git-filter-repo", line 4005, in <module>
main()
File "C:\git-filter-repo\git-filter-repo", line 4001, in main
filter = RepoFilter(args)
File "C:\git-filter-repo\git-filter-repo", line 2760, in __init__
self._handle_arg_callbacks()
File "C:\git-filter-repo\git-filter-repo", line 2865, in _handle_arg_callbacks
handle('commit')
File "C:\git-filter-repo\git-filter-repo", line 2858, in handle
setattr(self, callback_field, make_callback(type, code_string))
File "C:\git-filter-repo\git-filter-repo", line 2841, in make_callback
' '+'\n '.join(str.splitlines()), globals())
File "<string>", line 3
commit.author_email_split = commit.author_email.split(\)
^
SyntaxError: unexpected character after line continuation character
I tried checking an re-checking the command syntax, the presence of hidden chars and so on but nothing works. What can be the problem here?
My problem was that I was using Powershell and this was causing problems with the line continuation char (thanks Joachim Sauer for the tip, very useful!).
After fixing that problem, Python was complaining with the error %b requires a bytes-like object, or an object that implements __bytes__, not 'str'
, so I also added encode()
and decode()
. You can find the final solution that works in git bash (and I think in any bash-like prompt).
git filter-repo --force --refs master --commit-callback '
commit.committer_email = commit.committer_email.decode().split("\\")[1].encode()
commit.author_email = commit.author_email.decode().split("\\")[1].encode()
if commit.author_name:
commit.author_name = commit.author_email
if commit.committer_name:
commit.committer_name = commit.committer_email
'