Skip to content

Instantly share code, notes, and snippets.

@styrken
Last active December 16, 2015 13:29
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 styrken/5442407 to your computer and use it in GitHub Desktop.
Save styrken/5442407 to your computer and use it in GitHub Desktop.
Simple bash scripts to import svn repository into a git "bare" repository. 1. Run svn-authors.sh to generate an authors-file for git 2. Run the svn-to-git.sh script 3. Copy the new "bare" repo somewhere 4. Clone your new "bare" repo and start working Both scripts can be run without arguments to print out a usage line.
#!/bin/sh
# Url for the svn repo, example: svn://svn.domain.com/libs/libaes/trunk
SVN_URL=$1
SVN_TEMP_DIR=tempsvn
if [ -z $SVN_URL ]
then
echo "Not enough arguments..\n"
echo "Usage: ./svn-authors.sh svn-url [> authors.txt]"
exit
fi
svn checkout ${SVN_URL} ${SVN_TEMP_DIR} >> /dev/null
cd ${SVN_TEMP_DIR}
svn log -q | awk -F '|' '/^r/ {sub("^ ", "", $2); sub(" $", "", $2); print $2" = "$2" <"$2">"}' | sort -u
cd ..
rm -rf ${SVN_TEMP_DIR}
#!/bin/sh
# Url for the svn repo, example: svn://svn.domain.com/libs/libaes/ (without trunk. This script assumes standard layout in url, ie trunk, tags, branches)
SVN_URL=$1
# New git repo name.
GIT_NAME=$2
# Authors file. Should be a textfile containing names in the following format:
#
# rts = Rasmus Styrk <rasmus@appvaerk.dk>
# svn-name = Real Name <email@example.com>
#
AUTHORS_FILE=$3
# Other configuration stuff
NEW_NAME=${GIT_NAME}.git
SVN_LAYOUT=--stdlayout
if [ -z $SVN_URL ] || [ -z $GIT_NAME ] || [ -z $AUTHORS_FILE ]
then
echo "Not enough arguments. Needs all 3.\n"
echo "Usage: ./svn-to-git.sh svn-url new-git-name authors-file"
exit
fi
echo ""
echo "\033[33mBeginning importing of ${SVN_URL} into ${NEW_NAME}\033[0m"
git svn clone ${SVN_URL} --no-metadata -A "${AUTHORS_FILE}" ${SVN_LAYOUT} temp
cd temp
git svn show-ignore > .gitignore
git add .
git commit -m "Initial import"
echo ""
echo "\033[33mCreating bare repository\033[0m"
cd ..
git init --bare ${NEW_NAME}
cd ${NEW_NAME}
git symbolic-ref HEAD refs/heads/trunk
echo ""
echo "\033[33mPushing temp to new bare\033[0m"
cd ../temp
git remote add bare ../${NEW_NAME}
git config remote.bare.push 'refs/remotes/*:refs/heads/*'
git push bare
echo ""
echo "\033[33mCleaning up, renaming trunk to master etc\033[0m"
cd ..
rm -rf temp
cd ${NEW_NAME}
git branch -m trunk master
git for-each-ref --format='%(refname)' refs/heads/tags |
cut -d / -f 4 |
while read ref
do
git tag "$ref" "refs/heads/tags/$ref";
git branch -D "tags/$ref";
done
echo "\033[33mDone importing ${SVN_URL} into ${NEW_NAME}\033[0m"
echo ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment