Skip to content

Instantly share code, notes, and snippets.

@TopherGopher
Created January 4, 2014 01:10
Show Gist options
  • Save TopherGopher/8250110 to your computer and use it in GitHub Desktop.
Save TopherGopher/8250110 to your computer and use it in GitHub Desktop.
This helps create a new git repo from an existing svn repo. It uses git-svn to create a hybrid of your svn repo, then it creates a clean repo at REPONAME. It should maintain your history for your branch. I've setup the framework so that you can add more branches, but I never implemented the logic because we didn't need it. It should be extensibl…
#!/bin/bash
#What is the name of your repo? This will serve as the folder name.
REPO_NAME="my-repo"
# Do NOT point to the trunk
URL_OF_REPO="https://myserver.example.com/svn/roommate-agreement"
# This is probably just "trunk"
TRUNK_LOCATION="trunk"
BRANCH_LOCATION="branches"
# ex) "/branches/production", if no production branch, put "NONE"
PRODUCTION_LOCATION="branches/production"
PRODUCTION_NAME="production"
# If no second branch, put "NONE"
BRANCH2_LOCATION="/branches/playground"
BRANCH2_NAME="playground"
PATH_TO_USER_FILE="/home/user/Desktop/users.txt"
#------STOP EDITING-----
mkdir $REPO_NAME"_tmp"
cd $REPO_NAME"_tmp"
git svn init $URL_OF_REPO --trunk=$TRUNK_LOCATION --branches=$PRODUCTION_LOCATION --no-metadata
git config svn.authorsfile $PATH_TO_USER_FILE
git svn fetch
#Trunk is now mapped to the master branch
if [ "$PRODUCTION_LOCATION" == "NONE" ]; then
echo "No production branch exists. Nothing to be done."
else
git config --add svn-remote.$PRODUCTION_NAME.url $URL_OF_REPO$PRODUCTION_LOCATION
git config --add svn-remote.$PRODUCTION_NAME.fetch :refs/remotes/$PRODUCTION_NAME
git svn fetch $PRODUCTION_NAME
git checkout -b $PRODUCTION_NAME -t $PRODUCTION_NAME
git svn rebase $PRODUCTION_NAME
fi
if [ "$BRANCH2_LOCATION" == "NONE" ]; then
echo "No second branch"
else
echo "Second branch exists"
fi
cd ..
git clone $REPO_NAME"_tmp" $REPO_NAME
echo "A new GIT repository has been created at "$REPO_NAME
rm -rf $REPO_NAME"_tmp"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment