#!/bin/sh
#  Convert a CVS-based directory to git.
#
#  Unlike the more modern method involving cvs2git and git fast-import,
#  this can be used with an existing CVS working directory, even if it
#  contains locally-modified files.  However, you could use the same
#  trick of creating the clone and moving the resulting git repo into
#  the old CVS tree.

if [ -d CVS ]; then
    root=`cat CVS/Root`
    repo=`cat CVS/Repository`
    #x='$'
    #tree=`perl -e "'$repo' =~ m|$root/(.*)${x}|; print ${x}1"`
    tree=$repo
else
    root=/home/starport/CvsRoot
    cwd=`pwd`
    tree=starport/Web/`basename $cwd`
fi

echo repo=$root tree=$tree

# can't just use "git cvsimport" in a cvs working directory
# -> fails with "unknown error" if there are locally-modified files
mkdir working
cd working
git cvsimport -d $root $tree

cd ..; mv working/.git .; rm -rf working

if [ ! -d .git ]; then
    echo "Sorry about that."
    exit 1
fi

# took out the cleanup because it's a bit risky
echo you might want to run clean-up-old-files

cp ../Tools/.gitignore .
git add .
git commit -m "update after cvsimport"
