-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathgit-svn-synchronizer.sh
executable file
·101 lines (91 loc) · 2.06 KB
/
git-svn-synchronizer.sh
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
#!/bin/sh
# This script synchronizes a Git repository with a given Subversion repository.
# Originally specific to ImageJ2 (before that project switched over to Git),
# it accepts the repository URLs via the command-line, e.g. for use in a
# Jenkins job.
#
# It takes the Subversion URL as first parameter and an arbitrary number of
# Git push URLs after that.
#
# Example:
#
# git-svn-synchronizer.sh \
# https://valelab.ucsf.edu/svn/micromanager2/ \
# github.com:openspim/micromanager \
# fiji.sc:/srv/git/micromanager1.4/.git \
usage () {
echo "Usage: $0 [--force] [--reset] <Subversion-URL> <Git-push-URL>..." >&2
exit 1
}
force=
reset=
while test $# -gt 0
do
case "$1" in
--force)
force=--force
;;
--reset)
git branch -D -r $(git branch -r)
rm -rf .git/svn
git config --remove-section svn-remote.svn
reset=t
;;
-*)
usage
;;
*)
break
;;
esac
shift
done
if test $# -lt 2
then
usage
fi
set -e
SVN_URL="$1"
shift
# initialize repository
if ! test -d .git
then
git init &&
git config core.bare true &&
if test -z "$reset"
then
git remote add -f tmp "$1" &&
# read from remote repository to prevent unnecessary git-svn cloning
git for-each-ref --format '%(refname)' refs/remotes/tmp/svn/ |
while read ref
do
git push . $ref:refs/remotes/${ref#refs/remotes/tmp/svn/}
done &&
git remote rm tmp
fi
fi
# initialize the Subversion URL
if ! test -d .git/svn || test "a${SVN_URL%/}" != "a$(git config svn-remote.svn.url)"
then
# Try standard trunk/branches/tags setup first
git svn init -s "$SVN_URL" &&
git svn fetch &&
git rev-parse refs/remotes/trunk ||
git rev-parse refs/remotes/git-svn || {
rm -rf .git/svn &&
git config --remove-section svn-remote.svn &&
git svn init "$SVN_URL" &&
git svn fetch
}
else
git svn fetch
fi
# push refs/remote/* to refs/heads/svn/*
args="$(git for-each-ref --shell --format '%(refname)' refs/remotes/ |
sed -e "s/^'\(refs\/remotes\/\(.*\)\)'$/'\1:refs\/heads\/svn\/\2'/" \
-e 's/:refs\/heads\/svn\/tags\//:refs\/tags\//')"
git gc --auto
for remote
do
eval git push $force \"$remote\" $args
done