I know I’ve written about this in the past (here and here), but I needed to do another conversion the other day that was similar, yet different. Previous posts talked about pulling parts of a subversion repository into a git repo — effectively taking one svn repo apart into multiple git repos. This time I just needed to do a straight conversion, however I needed to exclude one single directory from ever being a part of the history of the repo.

Since this was a fairly important repo to convert, I did a few trial runs first and ended up scripting it since there isn’t just a single command to do what I needed. Essentially, we are doing a git clone from a subversion repository (a standard one with trunk/, tags/, branches/ this time), but excluding one directory (we’ll call it private). I also wanted to convert the svn branches to tags since that’s effectively what they were. Also, since the git repository was not local, and for the sake of expediency I didn’t want to tar something up and email it, we’re taking our converted-and-cleaned-up new git repo, changing the upstream, and then pushing the whole thing to a remote bare repository.

Ready? (Note: a few lines are manually wrapped with ‘' below)

#!/bin/sh
WORKDIR="/srv/svn2git/git"
REMOTE="git+ssh://remote.git.host/myrepo.git"
mkdir -p ${WORKDIR}

pushd ${WORKDIR}
git svn clone https://remote.svn.host/repos/myrepo --no-metadata \
  -A /srv/svn2git/authors-transform.txt --stdlayout \
  --ignore-paths="^trunk/private" ${WORKDIR}/from-svn
cd from-svn
git init --bare ../bare.git
cd ../bare.git
git symbolic-ref HEAD refs/heads/trunk
cd ../from-svn
git remote add bare ../bare.git
git config remote.bare.push 'refs/remotes/*:refs/heads/*'
git push bare
cd ../bare.git
git branch -m trunk master
for x in branch_one branch_two branch_three; do
    git tag "${x}" refs/heads/${x}
    git branch -D ${x}
done

cd ..
git clone bare.git myrepo
cd myrepo
git remote rm origin
git remote add origin ${REMOTE}
git config remote.origin.push 'refs/remotes/*:refs/heads/*'
git config master.remote origin
git config master.merge refs/head/master
git push --set-upstream origin master

And that is all there was too it. The svn authors file was created ny using:

$ svn log -q | awk -F '|' '/^r/ {sub("^ ", "", $2); sub(" $", "", $2); \
print $2" = "$2" <"$2">"}' | sort -u > authors-transform.txt

in the existing copy of the subversion repository that I had (and then mangling it to suit my needs, particularly changing it to add the committers’ real names and email addresses as well).

Share on: TwitterLinkedIn


Published

Category

Linux

Stay in touch