I’m trying to rename some committers in a git repository, using git filter-branch. I’d quite like to use some more complex logic, but I don’t really understand bash. The (working) script I’m currently using looks like this:
git filter-branch -f --tag-name-filter cat --env-filter '
cn="$GIT_COMMITTER_NAME"
cm="$GIT_COMMITTER_EMAIL"
if [ $cn = "ew" ]
then
cn="Eric"
cm="my.email@provider.com"
fi
export GIT_COMMITTER_NAME="$cn"
export GIT_COMMITTER_EMAIL="$cm"
' -- --all
Is it possible for me to use a python script as the --env-filter argument? If so, how would I get access to $GIT_COMMITTER_NAME to read and write it?
How would I do the equivalent of that bash string in a python file?
In python, you need to
import os, after whichos.environis a dictionary with the incoming environment in it. Changes toos.environare exported automatically. The real problem here is that git’s –filter-* filters are run, as it says:So it’s actually using the shell, and if you have the shell invoke Python, you wind up with a subprocess of the shell and any changes made in the Python process do not affect that shell. You’d have to
evalthe output of a Python script:where foo.py outputs the appropriate
exportcommands:(all of the above is untested).