Wrapper script to convert CVS project to Git

dale's picture

I have an old CVSROOT of several projects on an archive host, and I want to create a git version of the relevant projects without bothering to copy more than I need to. Here is a script to do that. It uses rsync to copy just the relevant project and then converts it with cvs2git AKA cvs2svn.

#!/bin/bash
#######################################################################
# cvs3git - # Convert a CVS project to git.
#######################################################################
CVSROOT=archivehost:/var/cvs
GITOUTDIR=~/src
USERNAME=$USER

if [ -z "$1" ]; then
        echo "Usage: $0 <cvsproject>"
        exit 1
fi
pkg=$1

# make a home for the new git project
if [ ! -e "$GITOUTDIR/$pkg" ]; then
        mkdir "$GITOUTDIR/$pkg"
else
        echo "$GITOUTDIR/$pkg exists already! refusing to continue"
        exit 1
fi

# make a clean nest to work in
tempdir=`mktemp -d $PWD/cvs2git.XXXXXX`
if [ ! -d "$tempdir" ]; then
        echo "problem creating tempdir"
        exit 1
fi

# cvs2git is rather insistent on seeing a CVSROOT dir somewhere in the path
mkdir $tempdir/CVSROOT

# my old cvs  repo is on another host, so copy it here
rsync -avzr -e ssh $CVSROOT/$pkg $tempdir/CVSROOT/
# you might use something like this or just rewrite around all this
#cp -ar $CVSROOT/$pkg $tempdir/CVSROOT/

# convert cvs project to blob and dump files
cvs2git \
          --blobfile=$tempdir/$pkg.blob \
          --dumpfile=$tempdir/$pkg.dump \
          --username= $USERNAME \
          $tempdir/CVSROOT/$pkg

# now create the git project and import the cvs dump
cd $GITOUTDIR/$pkg
git init
cat $tempdir/$pkg.blob $tempdir/$pkg.dump | git fast-import
git checkout master

# empty the nest
rm -rf "$tempdir"

Comments

Hacker

!