-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathgitmodule2svn
executable file
·131 lines (116 loc) · 5.03 KB
/
gitmodule2svn
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
#!/bin/bash
#set -x
executed=${0}
this=$(basename ${0})
modulepath=$(pwd |awk -F'/' '{print $1"/"$2"/"$3"/"$4"/"$5}')
modulename=$(echo "${modulepath}" |awk -F'/' '{print $NF}')
warnings=""
infos="Trying to sync git module: '${modulename}' accross all svn repositories in workspace..\n"
function process {
local dir=${1}
apppath=$(echo "${dir}" |awk -F'/' '{print $1"/"$2"/"$3"/"$4"/"$5}')
appname=$(subd "${apppath}")
vendorpath=$(echo "${dir}" |awk -F'/' '{print $1"/"$2"/"$3"/"$4"/"$5"/"$6}')
if [ -d "${apppath}/.git" ]; then
if [ -d "${dir}/.git" ]; then
set -x
cd ${apppath}
git submodule update
cd -
set +x
infos="${infos}'${modulename}' synced to '${dir}; using submodule'\n"
else
infos="${infos}'${modulename}' not synced to '${dir}; git repositories can use submodule'\n"
gitsuggest ${apppath} ${modulename} ${dir}
fi
elif [ "$(svn propget svn:externals ${apppath} |grep "${modulename}" |wc -l)" -eq 1 ]; then
infos="${infos}'${modulename}' not synced to '${dir}; lose svn:external first'\n"
propsuggest ${apppath} ${modulename} ${dir}
elif [ "$(svn propget svn:externals ${vendorpath} |grep "${modulename}" |wc -l)" -eq 1 ]; then
infos="${infos}'${modulename}' not synced to '${dir}; lose svn:external first'\n"
propsuggest ${vendorpath} ${modulename} ${dir}
else
svn up ${apppath}
cmd="/usr/bin/rsync -a -i --size-only --exclude '*.git*' --exclude '.git' --exclude ${this} --exclude 'gitup.dat' --exclude 'up.sh' $modulepath/ ${dir}"
echo "${cmd}"
y=$(${cmd})
if [ -d "${dir}/.git" ]; then
cmd="rm -rf ${dir}/.git"
#echo "${cmd}"
#z=$(${cmd})
fi
if [ $(echo -e "${y}" |wc -l) -lt 2 ]; then
infos="${infos}'${modulename}' was up to date in '${dir}'\n"
else
echo -e "'${y}'"
x=$(svn ls ${dir})
if [ ${?} -eq 1 ]; then
svn add ${dir}
fi
svn commit -m "AutoIncluded internal module: ${modulename}" ${apppath}
svn up ${apppath}
infos="${infos}'${modulename}' was synced to '${dir}'\n"
fi
fi
}
function subd {
echo "${1}" |awk -F'/' '{k=NF-1; print $k"/"$NF}'
}
function gitsuggest {
local apppath=${1}
local appname=$(subd "${apppath}")
local modulename=${2}
local dir=${3}
local inpath=$(echo "${dir}" |sed "s#${apppath}/##g")
warnings="${warnings}Git repositories can use submodules. You probably need to: \n"
warnings="${warnings} cd ${apppath} \n"
warnings="${warnings} rmdir ${dir} \n"
warnings="${warnings} git rm --cached -r ${dir} \n"
warnings="${warnings} git submodule add git://github.com/kvz/${modulename}.git ${inpath} \n"
warnings="${warnings} git submodule update --init \n"
warnings="${warnings} cd - \n"
warnings="${warnings}\n"
warnings="${warnings} OR, for Cake Plugins: \n"
warnings="${warnings}\n"
warnings="${warnings} cd ${apppath} \n"
warnings="${warnings} rmdir ${dir} \n"
warnings="${warnings} git rm --cached -r ${dir} \n"
warnings="${warnings} git submodule add git://github.com/kvz/cakephp-${modulename}-plugin.git ${inpath} \n"
warnings="${warnings} git submodule update --init \n"
warnings="${warnings} cd - \n"
warnings="${warnings}\n"
}
function propsuggest {
local apppath=${1}
local appname=$(subd "${apppath}")
local modulename=${2}
local dir=${3}
local remain=$(svn propget svn:externals ${apppath} |grep -v ${modulename})
warnings="${warnings}'${modulename}' is still an svn:external of '${appname}'. You probably need to: \n"
warnings="${warnings} svn up ${apppath} \n"
if [ -z "${remain}" ]; then
warnings="${warnings} svn propdel svn:externals ${apppath} \n"
else
warnings="${warnings} svn propset svn:externals \"${remain}\" ${apppath} \n"
fi
warnings="${warnings} svn commit -m \"Removed reference to external module: ${modulename}\" ${apppath} \n"
warnings="${warnings} svn up ${apppath} \n"
warnings="${warnings} svn rm ${dir} --force \n"
warnings="${warnings} rm -rf ${dir} \n"
warnings="${warnings} svn cleanup ${apppath} \n"
warnings="${warnings} svn commit -m \"Removed external module: ${modulename}\" ${apppath} \n"
warnings="${warnings} svn up ${apppath} \n"
warnings="${warnings} mkdir ${dir} \n"
warnings="${warnings} ${executed} \n"
warnings="${warnings}\n"
}
# Vendor & Ext dirs that match modulename
for dir in $(find ~/workspace -mindepth 3 -maxdepth 3 -regextype posix-extended -iregex ".*(code|ext|vendors|vendor)/${modulename}" -type d |egrep -v '(\.svn)'); do
process "${dir}"
done
# Cake Plugins that match modulename
for dir in $(find ~/workspace -mindepth 4 -maxdepth 5 -regextype posix-extended -iregex ".*(plugins)/${modulename}" -type d |egrep -v '(\.svn)'); do
process "${dir}"
done
echo -e "${infos}"
echo -e "${warnings}"