I know I give the Python code as a string in the command line for example as:
git-filter-repo --name-callback 'return name.replace(b"Wiliam", b"William")'
but especially as I get into more complex scripts, this will get very clumsy.
Rather, is there a way to do something like:
main.py
import git_filter_repo
def name_callback(name):
return name.replace(b"Wiliam", b"William")
git_filter_repo.name_callback(name_callback)
The project README mentions that it can be used as a library, and I managed to install the Python package with:
python3 -m pip install --user git-filter-repo
but I couldn't easily find documentation on how to do a hello world with the Python API.
The last few lines of the source https://github.com/newren/git-filter-repo/blob/7b3e714b94a6e5b9f478cb981c7f560ef3f36506/git-filter-repo#L3946 were a good starting point, so I can do something like this:
which is intended to be equivalent to:
This also answers: How to substitute text from files in git history?
How to also know the blob's path: How to modify a blob considering both its file path and data with git filter-repo?
Tested in git-filter-repo ac039ecc095d with this test repo: https://github.com/cirosantilli/test-git-filter-repo