Skip to content

Instantly share code, notes, and snippets.

@PandaEox
Created June 3, 2014 11:12
Show Gist options
  • Save PandaEox/42a9f27bff9d0515b51c to your computer and use it in GitHub Desktop.
Save PandaEox/42a9f27bff9d0515b51c to your computer and use it in GitHub Desktop.
Rewrite SVN User to git user
#!/bin/bash
raw=`cat users.txt`
IFS=$'\n'
arr=($raw)
output=""
for i in "${arr[@]}"
do
IFS='=' read -a line <<< "$i"
svn_user=`echo "${line[0]}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//'`
git_name=`echo "${line[1]}" | egrep -o '(\w.*)\s*<' | egrep -o '\w.*\w'`
git_mail=`echo "${line[1]}" | egrep -o '<(.+)>' | egrep -o '[^<>]+'`
echo "Processing $svn_user who is really name ($git_name) with mail ($git_mail)"
output=$( cat <<EOF
$output
if [ "\$GIT_COMMITTER_EMAIL" = "$svn_user" ]
then
cn="$git_name"
cm="$git_mail"
fi
if [ "\$GIT_AUTHOR_EMAIL" = "$svn_user" ]
then
an="$git_name"
am="$git_mail"
fi
EOF
)
done
git filter-branch -f --env-filter "
an=\"\$GIT_AUTHOR_NAME\"
am=\"\$GIT_AUTHOR_EMAIL\"
cn=\"\$GIT_COMMITTER_NAME\"
cm=\"\$GIT_COMMITTER_EMAIL\"
$output
export GIT_AUTHOR_NAME=\"\$an\"
export GIT_AUTHOR_EMAIL=\"\$am\"
export GIT_COMMITTER_NAME=\"\$cn\"
export GIT_COMMITTER_EMAIL=\"\$cm\"
"
DaPanda = Da Panda <gist@eox.ch>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment