aboutsummaryrefslogtreecommitdiff
path: root/git/git-svn-mirror-synch
blob: 95bf13cf4b9a2aaa4f6069cbbf3ee435b51922ab (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
#! /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/>.

GITROOT=/gitroot
HEADPFX=

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 GIT-REPO
EOT
}       

while [ $# -ne 0 ]
do
  case $1 in
  -h|--help)
    usage
    exit 0;;
  -*)
    echo >&2 "$0: unknown option $1"
    exit 1;;
  *)
    break;;
  esac
done

if [ $# -ne 1 ]; then
  echo >&2 "$0: required argument missing"
  exit 1
fi

BRANCHLIST=/tmp/$$.branch
TAGLIST=/tmp/$$.tag
trap 'rm -f $BRANCHLIST $TAGLIST' 1 2 3 6 13 15

cd $GITROOT/$1 || exit 1
git branch | sed 's/^\*//' | tr -d ' ' | tee $BRANCHLIST |
 while read branch
 do
   echo "Synching $branch"
   git checkout $branch
   git svn fetch
   git svn rebase -l
 done
git checkout master
git reset --hard refs/remotes/trunk

echo "Checking for new branches & tags..."
git tag > $TAGLIST
git branch -r |
 while read tag
 do
   case $tag in
   tags/*) localtag=${tag##tags/}
           if ! grep -q "^${localtag}\$" $TAGLIST; then
	     echo "Mapping $tag to $localtag"
	     git tag $localtag $tag
	   fi;;
   trunk)  ;;
   *)      if ! grep -q "^${HEADPFX}${tag}\$" $BRANCHLIST; then
             echo "Tracking $tag as ${HEADPFX}$tag"
             git branch --track ${HEADPFX}$tag $tag
	   fi;;
   esac
 done
echo "Done."
rm -f $BRANCHLIST $TAGLIST

Return to:

Send suggestions and report system problems to the System administrator.