-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathge-svn-import
executable file
·191 lines (163 loc) · 4.63 KB
/
ge-svn-import
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#!/bin/bash
current_dir=`pwd`
git_svn_init_args=""
git_svn_fetch_args=""
interactive_mode=0
log_file="./svn_import_`date '+%Y-%m-%d_%H.%M.%S'`.log"
svn_authors_files=""
svn_destination_dir=""
svn_repo_url=""
svn_start_revision=1
svn_username=""
function ge_svn_import() {
touch $log_file
(ge_svn_import_steps $@) | tee $log_file
}
function ge_svn_import_steps() {
if [ -z "$svn_repo_url" ]; then
echo "FATAL: No SVN repository URL was provided."
exit 1
fi
echo "Importing SVN repository from $svn_repo_url into Git at $svn_destination_dir"
if [ -z "$svn_authors_file" ]; then
echo "WARN: No SVN authors file was found. Your new Git history will be incomplete."
elif [ ! -f "$svn_authors_file" ]; then
echo "FATAL: The SVN authors file ($svn_authors_file) does not exist or is not readable."
exit 1
else
echo "Using $svn_authors_file to import SVN history."
fi
echo "Listing contents of SVN repository URL..."
svn ls $svn_repo_url
if [ 1 -eq $? ]; then
echo "FATAL: The SVN repository URL $svn_repo_url is incorrect or does not exist."
exit 1
else
echo "The SVN repository URL $svn_repo_url exists."
fi
if [ -d $svn_destination_dir ]; then
echo "WARN: Destination directory already exists. Deleting the destination directory..."
echo "rm -rf $svn_destination_dir"
rm -rf $svn_destination_dir
fi
echo "Creating destination directory $svn_destination_dir..."
echo "mkdir -vp $svn_destination_dir"
mkdir -vp $svn_destination_dir
if [ ! -d $svn_destination_dir ]; then
echo "FATAL: Failed to create $svn_destination_dir."
exit 1
else
echo "Destination directory created at $svn_destination_dir"
fi
echo "Initializing the Git-SVN repository..."
echo "git svn init --stdlayout --no-metadata $svn_repo_url $svn_destination_dir"
git svn init --stdlayout --no-metadata $svn_repo_url $svn_destination_dir
echo "Git-SVN repository initialized."
echo "Begin fetching commits..."
echo "cd $svn_destination_dir"
cd $svn_destination_dir
echo "git svn fetch --authors-file=$svn_authors_file -r $svn_start_revision:HEAD"
git svn fetch --authors-file=$svn_authors_file -r $svn_start_revision:HEAD
echo "Finished fetching commits."
ge_svn_convert_tags_to_branches
echo "Finished importing into Git."
}
function ge_svn_import_interactive() {
ge_svn_import_read_repo_url
ge_svn_import_read_destination_dir
ge_svn_import_read_username
ge_svn_import_read_authors_file
ge_svn_import_read_revision
ge_svn_import $@
}
function ge_svn_import_read_repo_url() {
echo -n "SVN repo URL: "
read svn_repo_url
echo "# SVN repo located at $svn_repo_url"
}
function ge_svn_import_read_username() {
echo -n "SVN username: "
read svn_username
echo "# SVN username is $svn_username"
}
function ge_svn_import_read_authors_file() {
read -e -p "SVN authors file: " svn_authors_file
eval svn_authors_file=$svn_authors_file
echo "# SVN authors file located at $svn_authors_file"
}
function ge_svn_import_read_revision() {
echo -n "Start import at revision: "
read svn_start_revision
if [ -z "$svn_start_revision" ]; then
svn_start_revision=1
fi
echo "# Starting import at revision $svn_start_revision"
}
function ge_svn_import_read_destination_dir() {
read -e -p "Destination directory: " svn_destination_dir
eval svn_destination_dir=$svn_destination_dir
echo "# Creating Git repo in $svn_destination_dir"
}
function ge_svn_debug_convert_tags_to_branches() {
ge_svn_convert_tags_to_branches
}
function ge_svn_debug_git_branch() {
echo " origin/foo"
echo " origin/master"
echo " tags/1"
echo " tags/2"
echo " tags/abc"
}
function ge_svn_convert_tags_to_branches() {
tag_branches=`git branch -r | grep -E '^ tags'`
echo "Convert SVN tags to Git tags. SVN tags get imported to Git as Git branches. Transform the following Git branches into Git tags:"
echo "$tag_branches"
for branch in $tag_branches; do
tag=`echo $branch | sed -E 's/tags\/([-_a-zA-Z0-9]+)/\1/'`
echo "Convert Git-SVN branch $branch to Git tag $tag"
echo " git tag $tag $branch"
git tag $tag $branch
echo " git branch -r -d $branch"
git branch -r -d $branch
done
echo "git tag"
git tag
echo "Finished converting SVN tags to Git tags."
}
if [ -z "$1" ]; then
interactive_mode=1
else
while [ ! -z "$1" ]; do
case $1 in
'--svn-authors-file')
shift
svn_authors_file=$1
shift
;;
'--revision')
shift
svn_start_revision=$1
shift
;;
'--username')
shift
svn_username=$1
shift
;;
*)
break
;;
esac
done
fi
if [ $interactive_mode -eq 1 ]; then
echo "Entering interactive mode..."
ge_svn_import_interactive $@
else
svn_repo_url=$1
shift
svn_destination_dir=$1
shift
ge_svn_import $@
fi
exit $?