#! /bin/sh # Copyright (C) 2009 Sergey Poznyakoff # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3, or (at your option) # any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . SVNROOT=file:///svnroot GITROOT=/gitroot AUTHORS=/etc/mirror/git/authors RCVHOOK= HEADPFX= GUESS_GROUP= GROUP= if [ -r /etc/mirror/git/config ]; then . /etc/mirror/git/config fi if [ -r $HOME/.git-mirror ]; then . $HOME/.git-mirror fi usage() { cat <<-EOT usage: $0 [OPTIONS] REPO OPTIONS are: -A, --authors=FILE use FILE as an authors file -h, --help display this help summary EOT } set -- `echo $* | sed -r 's/-[Ag]([^ ]+)/-A \1/g;s/(--[^ =]+)=/\1 /g'` while [ $# -ne 0 ] do case $1 in -h|--help) usage exit 0;; -A|--authors) if [ $# -eq 1 ]; then echo >&2 "$0: $1 requires an argument" exit 1 fi shift AUTHORS=$1 shift;; -g|--group) if [ $# -eq 1 ]; then echo >&2 "$0: $1 requires an argument" exit 1 fi shift GROUP=$1 shift;; -G|--guess-group) GUESS_GROUP=yes shift;; -*) echo >&2 "$0: unknown option $1" exit 1;; *) break;; esac done if [ $# -ne 1 ]; then echo >&2 "$0: required argument missing" exit 1 fi if [ -d $GITROOT/$1 ]; then echo >&2 "$0: target repository $GITROOT/$1 already exists" exit 1 fi if [ "$GUESS_GROUP" = "yes" ]; then GROUP=$1 fi if [ -n "$GROUP" ]; then sg $GROUP -c "git svn clone --shared=group -A$AUTHORS -s $SVNROOT/$1 $GITROOT/$1" else git svn clone --shared=group -A$AUTHORS -s $SVNROOT/$1 $GITROOT/$1 fi test $? -eq 0 || exit 1 cd $GITROOT/$1 || exit 1 git config svn.authorsfile $AUTHORS git branch -r | while read tag do case $tag in tags/*) localtag=${tag##tags/} git tag $localtag $tag ;; trunk) ;; *) git branch --track ${HEADPFX}$tag $tag ;; esac done if test -n "$RCVHOOK" && test -r "$RCVHOOK"; then cp $RCVHOOK .git/hooks/pre-receive chmod +x .git/hooks/pre-receive fi