Skip to content

Instantly share code, notes, and snippets.

@TopherGopher
Created January 4, 2014 01:10

Revisions

  1. Chris Sterling created this gist Jan 4, 2014.
    48 changes: 48 additions & 0 deletions convert_svn_to_git
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,48 @@
    #!/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"