Last active
December 15, 2015 18:19
-
-
Save BPScott/5303186 to your computer and use it in GitHub Desktop.
SVN to git migration script for when SVN author names are X.509 subjects * Converts svn -> git
* Migrates tags and branches to proper git styling
* Converts commit author names to proper name/email pairs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Runs an SVN to GIT migration and changes SVN commit authors which are X.509 | |
# subjects to proper authors. | |
# | |
# Usage | |
# ./svn2git.sh SVN_REPO_URL NEW_GIT_FOLDER_NAME | |
REPO=$1 | |
REPO_NAME=$2 | |
if [ ! -d "$REPO_NAME" ]; then | |
git svn clone $REPO --stdlayout --no-metadata --log-window-size=5000 $REPO_NAME | |
fi; | |
# SVN Tags become proper tags | |
(cd $REPO_NAME && git for-each-ref refs/remotes/tags | cut -d / -f 4- | grep -v @ | while read tagname; do git tag "$tagname" "tags/$tagname"; git branch -r -d "tags/$tagname"; done) | |
# SVN remotes to proper branches | |
(cd $REPO_NAME && git for-each-ref refs/remotes | cut -d / -f 3- | grep -v @ | while read branchname; do git branch "$branchname" "refs/remotes/$branchname"; git branch -r -d "$branchname"; done) | |
# Rewrite Authors by extracting cert owner and emails from the current author | |
# which is the X.509 subject. We can't do this with an --authors-file on clone | |
# as authors-file's chokes on authors with = in the name. | |
if [ ! -z $(cd $REPO_NAME && git log --oneline --author=emailAddress) ]; then | |
(cd $REPO_NAME && git filter-branch -f --commit-filter 'if [[ $GIT_AUTHOR_NAME == \/emailAddress* ]]; then | |
NAME=$( echo $GIT_AUTHOR_NAME | grep -o -P "(?<=CN\=)(([^\/])+)(?=\/)" ); | |
EMAIL=$( echo $GIT_AUTHOR_NAME | grep -o -P "(?<=emailAddress\=)(([^\/])+)(?=\/)" ); | |
export GIT_AUTHOR_NAME=$NAME; | |
export GIT_AUTHOR_EMAIL=$EMAIL; | |
export GIT_COMMITTER_NAME=$NAME; | |
export GIT_COMMITTER_EMAIL=$EMAIL; | |
fi; git commit-tree "$@"') | |
fi; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment