aboutsummaryrefslogtreecommitdiff
path: root/git/git-svn-mirror-create
blob: 68a20641ede957530e794cb0ce9f4870aa958e5a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#! /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 <http://www.gnu.org/licenses/>.

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

Return to:

Send suggestions and report system problems to the System administrator.