Skip to content

Instantly share code, notes, and snippets.

@marek-saji
Created March 24, 2013 16:57
Show Gist options
  • Save marek-saji/5232629 to your computer and use it in GitHub Desktop.
Save marek-saji/5232629 to your computer and use it in GitHub Desktop.
Change authors in git-svn repository basing on git-svn's authorfile.
#!/bin/sh
if [ -z "$1" ]
then
cat <<< HELP
(c) Marek 'saji' Augustynowicz
USAGE
change-git-svn-authors.sh RELATIVE_PATH_TO_AUTHORS_FILE
Obtaining authors.txt for your repository
-----------------------------------------
svn log -q SVN_REPO_URL | awk -F '|' '/^r/ {sub("^ ", "", $2); sub(" $", "", $2); print $2" = "$2" <"$2">"}' | sort -u > ../authors.txt
It produces file with lines:
svn_username = svn_username <svn_username>
You have to manually change it into:
svn_username = Name Surname <e.mail@example.com>
HELP
exit 1
fi
if ! [ -e "$1" ]
then
echo "File `$1' does not exist."
exit 2
fi
export AUTHORSFILE="$PWD/$1"
if ! [ -e "$AUTHORSFILE" ]
then
echo "File `$AUTHORSFILE' does not exist."
exit 3
fi
git-filter-branch --env-filter '
LINE=$( grep -P "^$GIT_AUTHOR_NAME = " "$AUTHORSFILE" )"
if [ -n "$LINE" ]
then
eval "$( sed -re 's/^([^ ]*) *= *(.*?) +<(.*)>$/SVN_USERNAME="\1" NAME="\2" EMAIL="\3"/' "$AUTHORSFILE" )"
if [ -n "$NAME" ]
then
export GIT_AUTHOR_NAME="$NAME"
fi
if [ -n "$EMAIL" ]
then
export GIT_AUTHOR_EMAIL="$EMAIL"
fi
else
echo "$GIT_AUTOR_NAME not found."
fi
'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment