-
Notifications
You must be signed in to change notification settings - Fork 0
/
git-svn-clone-externals
executable file
·144 lines (122 loc) · 3.82 KB
/
git-svn-clone-externals
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/bin/bash
#Taken from Andre Pang's github: https://github.com/andrep/git-svn-clone-externals
# -kurtis
set -e
toplevel_directory="$(git rev-parse --show-cdup)"
[ -n "$toplevel_directory" ] && { echo "please run from the toplevel directory"; exit 1; }
function call()
{
cmd="$@"
echo "$cmd"
eval "$cmd"
return "$?"
}
function do_clone()
{
test -d .git_externals || return 1
module=`echo $remote_url|sed 's,\(.*\)\(/trunk\|/branch.*\|/tag.*\),\1,'`
branch=`echo $remote_url|sed 's,\(.*\)\(/trunk\|/branch.*\|/tag.*\),\2,'|sed 's,^/,,'`
if [[ $branch = $remote_url ]]; then
branch=""
fi
(
cd .git_externals
if [ -d "$local_directory" ]; then
(
cd "$local_directory"
call git svn fetch --all
)
else
tags="tags"
brch="branches"
branchpath=$(echo $branch|cut -f1 -d/)
echo $tags|grep $branchpath >/dev/null 2>&1 && tags=$branchpath
echo $brch|grep $branchpath >/dev/null 2>&1 && brch=$branchpath
if [ "$module" = "$remote_url" ]; then
# URL does not contains any trunk, branches or tags part, so we dont need
# additional options for git-svn
call git svn clone "$revision" "$module" "$local_directory"
else
call git svn clone "$revision" "$module" -T trunk -b $brch -t $tags "$local_directory"
fi
fi
(
branch="$(echo ${branch}|sed 's,/$,,')"
if [ -n "$branch" ]; then
cd "$local_directory"
call git reset --hard $branch
fi
)
)
}
function do_link()
{
dir="$1"
base="$(dirname $dir)"
(
mkdir -p "$base"
cd $base
rel=$(git rev-parse --show-cdup)
ln -sf ${rel}.git_externals/"$dir"
)
}
function do_excludes()
{
dir="$1"
git_excludes_path=.git/info/exclude
if ! grep -q '^.git_externals$' "$git_excludes_path"
then
echo .git_externals >> "$git_excludes_path"
fi
if ! grep -q '^'"$dir"'$' "$git_excludes_path"
then
echo "$dir" >> "$git_excludes_path"
fi
}
function is_excluded()
{
local result=0
if [ -f .git_externals_exclude ] ; then
matches=`grep -v "^#" .git_externals_exclude|grep "^/$1$"|wc -l`
if [ $matches -gt 0 ] ; then
local result=1
fi
fi
echo $result
return
}
git svn show-externals | grep -vE '#|^$' | \
sed 's/\(-r\)[ ]*\([0-9]\{1,\}\)/\1\2/' | \
while read svn_externals
do
number_fields="$(echo ${svn_externals}|awk '{print NF}')"
case $number_fields in
2)
local_directory="$(echo ${svn_externals} | awk '{print $1}' | sed 's,^/,,')"
revision=""
remote_url="$(echo ${svn_externals} | awk '{print $2}')"
;;
3)
local_directory="$(echo ${svn_externals} | awk '{print $1}' | sed 's,^/,,')"
revision=""$(echo ${svn_externals} | awk '{print $2}')
remote_url="$(echo ${svn_externals} | awk '{print $3}')"
;;
*) continue ;;
esac
check_excluded=$(is_excluded $local_directory)
if [ $check_excluded -eq 0 ] ; then
if [ -n "$USE_SSH" ]; then
echo "Rewriting url to use SVN+SSH."
shopt -s extglob
remote_url="${remote_url/+(http|https)/svn+ssh}"
fi
[ -z "${remote_url}" ] && continue
export local_directory revision remote_url
echo "$local_directory -> $remote_url"
dir=`dirname $local_directory`
[ -d ".git_externals/$dir" ] || mkdir -p ".git_externals/$dir"
do_clone "$revision" "$remote_url" "$local_directory" || exit
do_link "$local_directory"
do_excludes "$local_directory"
fi
done