This repository has been archived by the owner on Oct 29, 2019. It is now read-only.
/
mirror-svn-git
executable file
·82 lines (71 loc) · 1.82 KB
/
mirror-svn-git
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
#!/bin/bash
# Script to mirror an SVN project in git.
svn_url=$1
if [ -z "$1" ]; then
echo "Usage: `basename $0` <url> (<localname>)"
exit 1
fi
if [ -z "$2" ]; then
basename_prefix=`basename $svn_url`
else
basename_prefix="$2"
fi
# Make sure we have a trailing / on he URL
[[ $svn_url != */ ]] && svn_url="$svn_url"/
# Check if it looks like a standard repo
svn ls $svn_url > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo Does not appear to be a svn repository $svn_url
exit 1
fi
gitsvn_basename="${basename_prefix}.git-svn"
git_basename="${basename_prefix}.git"
git_root=${HOME}/repos
mirror_root=$git_root/mirror
local_version_root=$git_root/local-version
if [ ! -d $mirror_root ]; then
mkdir -p $mirror_root
echo Created mirror root: $mirror_root
fi
cd $mirror_root
if [ -d $gitsvn_basename ]; then
echo Local folder already exists $gitsvn_basename
exit 1
fi
if [ -d $git_basename ]; then
echo Local folder already exists $git_basename
exit 1
fi
svn ls ${svn_url}trunk > /dev/null 2>&1
if [ $? -eq 0 ]; then
opts="-s"
fi
# Now bail if anything fails
set -e
if [ -d ${gitsvn_basename}-new ]; then
(cd ${gitsvn_basename}-new; git svn fetch)
else
git svn clone $opts $svn_url ${gitsvn_basename}-new
fi
mv ${gitsvn_basename}-new $gitsvn_basename
pushd $gitsvn_basename
src_url=$(git config --get svn-remote.svn.url)
src_trunk=$(git config --get svn-remote.svn.fetch| sed 's/:.*//')
popd
git clone --bare $gitsvn_basename $git_basename
pushd $git_basename
# Add in an origin link
relative_path=`basename $gitsvn_basename`
echo -n "[remote \"origin\"]
url = ../$relative_path
fetch = +refs/remotes/*:refs/heads/*
" >> config
# Make trunk the default branch
echo "ref: refs/heads/trunk" > HEAD
touch git-daemon-export-ok
echo "Clone from SVN of ${src_url}/${src_trunk}" > description
pushd refs/heads
ln -sf trunk master
popd
git fetch
popd