Skip to content

Instantly share code, notes, and snippets.

@lepistone
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lepistone/724c3d7269745a8c91f9 to your computer and use it in GitHub Desktop.
Save lepistone/724c3d7269745a8c91f9 to your computer and use it in GitHub Desktop.
fix-people-name.sh
#!/bin/bash
# This is rough script I used to fix authors and committers with the correct
# email but the name "unknown" from the account-analytic project.
#
# That situation happened because with bzr we committed merges with
# --author email@example.com, without specifying the author name. This caused
# those commits to show up as "unknown" when migrated to git.
#
# Improved by @yvaucher.
#
# I figured that since this operation rewrites history, the migration to
# github is a good time to do that.
#
# I started only with and empty "people-list" file, and as soon as the
# "Unknown # email" errors showed up, I added lines to people-list.
#
# Another way to address similar problems is .mailcap.
#
# This originated as PR https://github.com/OCA/maintainers-tools/pull/18
# that we decided not to merge.
filter='
found_author=true
found_commiter=true
if [ "$GIT_AUTHOR_NAME" = "unknown" ]
then
found_author=false
echo
echo Gocha author $GIT_AUTHOR_EMAIL
fi
if [ "$GIT_COMMITTER_NAME" = "unknown" ]
then
found_commiter=false
echo
echo Gocha committer $GIT_COMMITTER_EMAIL
fi
'
while read someone
do
email=$(echo $someone | awk -F"|" '{print $1;}')
name=$(echo $someone | awk -F"|" '{print $2;}')
filter="$filter"'
email="'"$email"'"
name="'"$name"'"
if [ "$GIT_AUTHOR_NAME" = "unknown" ]; then
is_email=$(echo $GIT_AUTHOR_EMAIL | grep "$email")
if [ -n "$is_email" ]
then
export GIT_AUTHOR_NAME="$name"
echo Author real name is $GIT_AUTHOR_NAME
found_author=true
fi
fi
if [ "$GIT_COMMITTER_NAME" = "unknown" ]; then
is_email=$(echo $GIT_COMMITTER_EMAIL | grep "$email")
if [ -n "$is_email" ]; then
export GIT_COMMITTER_NAME="$name"
echo Commiter real name is $GIT_COMMITTER_NAME
found_commiter=true
fi
fi
'
done < people-list
filter="$filter"'
if [ "$found_author" = false ]; then
echo "Unknown author email: $GIT_AUTHOR_EMAIL"
exit 1
fi
if [ "$found_commiter" = false ]; then
echo "Unknown committer email: $GIT_COMMITTER_EMAIL"
exit 1
fi
'
git filter-branch --env-filter "$filter"
leonardo.pistone@camptocamp.com|Leonardo Pistone
yannick.vaucher@camptocamp.com|Yannick Vaucher
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment