Last active
December 16, 2015 13:29
-
-
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.
This file contains hidden or 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 | |
# 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 <[email protected]> | |
# svn-name = Real Name <[email protected]> | |
# | |
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