cgal/Scripts/developer_scripts/cgal_git_svn_clone

220 lines
5.2 KiB
Bash
Executable File

#!/bin/bash
### Usage
# TODO remove -g xor -c and replace by last argument?
usage()
{
echo "Usage: `basename $0` [-u userName] [-e userEmail] [-l userLogin] [-c cloneLocation] [-v] [-h] [-g gitname=cgal.git]" >&2
echo >&2
echo " -v the version" >&2
echo " -h this info screen" >&2
echo >&2
}
# echo " -m svnLocation
# echo " -r gives revision to start from. Other options than a number: LAST, BASE" >&2
# echo " -f skip fetch" >&2
# echo " -t skip tags" >&2
### Config
userName="Eric Berberich"
userEmail=eric@mpi-inf.mpg.de
userLogin=eric
svnGforge=svn+ssh://$userLogin@scm.gforge.inria.fr/svn/cgal
#fromSvn=file://$HOME/CGAL/gforge/cgal-m
fromSvn=$svnGforge
fromRev=1
gitName=cgal.git
skipTags=0
skipFetch=0
cloneLocation=
# parse command line arguments
while getopts "u:e:l:r:m:g:c:fth" OPT; do
case "$OPT" in
# for developers
u) userName=$OPTARG
;;
e) userEmail=$OPTARG
;;
l) userLogin=$OPTARG
;;
c) cloneLocation=$OPTARG
;;
g) gitName=$OPTARG
;;
h) usage
exit 0
;;
v) echo "`basename $0` version 0.1"
exit 0
;;
# for svn2git cloners
m) fromSvn=$OPTARG
;;
r) fromRev=$OPTARG
;;
f) skipFetch=1
;;
t) skipTags=1
;;
# for all
\?) # getopts issues an error message
usage
exit 1
;;
esac
done
#shift `expr $OPTIND - 1`
if [ "$userName" = "" ]; then
echo "No username with -u parameter given"
exit 1
fi
if [ "$userEmail" = "" ]; then
echo "No useremail with -e parameter given"
exit 1
fi
if [ "$userLogin" = "" ]; then
echo "No userlogin with -l parameter given"
exit 1
fi
# TODO define tags-behavior for developers, maybe as own svn-remote of git-remote that can be deleted and, if needed, reintegrated; OR: Convert to GIT tags?
### Create repo
echo "Create new directory $gitname"
rm -fr ./$gitName
mkdir ./$gitName
cd ./$gitName
echo
if [ "$cloneLocation" != "" ]; then
echo "Cloning repo with svn-remotes from $cloneLocation"
git init
git remote add sorigin $cloneLocation
git config --replace-all remote.sorigin.fetch '+refs/remotes/*:refs/remotes/*'
git fetch sorigin
git config --remove-section remote.sorigin
echo "Checking out remotes/svn/branches/next"
git checkout -b local/next remotes/svn/next
# TODO: git svn rebase --local
fi
# rewrite root
rewriteRoot=--rewrite-root=$svnGforge
#rewriteRoot=
# options to speedup
# TODO internal-releases only >= 3.7
internalReleasesTags="--tags tags/internal-releases"
internalReleasesTags=
debianTags="--tags tags/debian"
debianTags=
echo "Init repository: $CMD"
git svn init $fromSvn $rewriteRoot --prefix=svn/next/ --trunk branches/next
git svn init $fromSvn $rewriteRoot --prefix=svn/ --trunk trunk
git svn init $fromSvn $rewriteRoot --prefix=svn/features/ --branches branches/features
git svn init $fromSvn $rewriteRoot --prefix=svn/releases/ --branches branches/releases
# rename ref
# TODO remove 'stable' for developers?
sed -e 's|next/trunk|next|g' -e 's|svn/trunk|svn/stable|g' -i "" .git/config
if [ $skipTags = 0 ]; then
git svn init $fromSvn $rewriteRoot --prefix=svn/tags/releases/ --tags tags/releases
sed -e 's|tags/releases/tags|tags/releases|g' -i "" .git/config
if [ "$internalReleasesTags" != "" ]; then
git svn init $fromSvn $rewriteRoot --prefix=svn/tags/internal-releases/ $internalReleasesTags
sed -e 's|tags/internal-releases/tags|tags/internal-releases|g' -i "" .git/config
fi
if [ "$debianTags" != "" ]; then
git svn init $fromSvn $rewriteRoot --prefix=svn/tags/debian/ $debianTags
sed -e 's|tags/debian/tags|tags/debian|g' -i "" .git/config
fi
fi
echo
# add author
echo "Add author to $gitName/.git/config"
git config user.name "$userName"
git config user.email "$userEmail"
echo
echo "Using config $gitName/.git/config:"
cat .git/config
### Fetch
if [ $skipFetch = 0 ]; then
if [ "$cloneLocation" != "" ]; then
echo "Fetch from real SVN server"
git svn fetch
echo "Checkout 'local/next'"
git checkout local/next
echo "Rebase from real SVN server"
git svn rebase
else
### Authors file
echo "Get authors file with svn"
svn cat $fromSvn/branches/next/Maintenance/git/authors-file.txt > /tmp/cgal-authors-file.txt
echo
# fetch from svn server
# TODO fetch each branch from its creation-revision only with
echo "Fetch from SVN repository: git svn fetch -r$fromRev:HEAD "
if [ "$fromRev" = "LAST" ]; then
# last revision on next
fromRev=$(svn info $fromSvn/branches/next | grep "Last Changed Rev: " | tr -d 'Last Changed Rev: ')
echo "Last Revision: $fromRev"
fi
git svn fetch --authors-file=/tmp/cgal-authors-file.txt -r$fromRev:HEAD
echo
rm -f /tmp/cgal-authors-files.txt
### Branch names
# rename master next
echo "Rename main branch to local/next"
git branch -m master local/next
fi
fi
# What about?
## git config svn-remote.svn.url $svncgal (or $svncgal/trunk if you are doing trunk only)
### http://translate.org.za/blogs/wynand/en/content/changing-your-svn-repository-address-git-svn-setup
## unhandled.log (which lists all svn properties, such as svn:eol, that has not been converted).