-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdateGitFromSvn.sh
136 lines (120 loc) · 3.52 KB
/
updateGitFromSvn.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
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
########################################
# This script is designed to update
# a git repo from the most recent
# svn revision.
# Author: Nicolas Strike, 2018
########################################
svnSrcDir=svnSourceExport
svnSrcCO=svnSourceCheckout
gitClone=gitClone
########################################
# Process command line arguments
#
# TODO: handle missing/required args
########################################
#forcedelete=0
branch=master
while [ "$1" != "" ]; do
case $1 in
-g | --git-repo-url ) shift
gitrepo=$1
;;
-s | --svn-repo-url ) shift
svnrepo=$1
;;
-b | --branch ) shift
branch=$1
shift
;;
#-f | --force-delete ) forcedelete=1
# ;;
-h | --help ) usage
exit
;;
* ) usage
exit 1
esac
shift
done
########################################
# Ensure the foldernames this script
# uses do not currently exist
########################################
deleteExistingClones(){
echo "Ensuring there are no local clones from previous runs of this script."
rm -rf svnSrcDir
rm -rf svnSrcCO
rm -rf gitClone
}
msg=msg.txt
##########################################
# Clone/Checkout repos into local folders
##########################################
cloneRepos(){
echo "Checkingout/cloning repositories"
echo "Updating git repo: $gitrepo"
echo "from svn repo: $svnrepo"
svn export $svnrepo $svnSrcDir --ignore-keywords
wait
#checkout a diff svn clone so we can get revision info (not included with the export keyword)
svn co $svnrepo $svnSrcCO
wait
git clone $gitrepo $gitClone
wait
}
########################################
# Delete large files before copying to
# prevent conflicts. Hopefully these
# files aren't needed. LFS is a pain.
########################################
#removeLFSfiles(){
#TODO
#}
########################################
# Process command line arguments
########################################
copySvnToGitClone(){
echo "Copying svn files into git clone"
'cp' $svnSrcDir/. $gitClone/ -R
}
########################################
# Generate a semi-useful git commit msg
########################################
generateCommitMsg(){
#Create Git Commit Message
cd $gitClone
printf "Updated from SVN, details below:\n" > ../$gitClone/$msg
svn info >> ../$gitWRFClubbDir/$msg
cd ..
}
########################################
# Commit changes to git
########################################
commitToGit(){
echo "Pushing update to git"
cd $gitClone
git add -A
git commit -a -F $msg
git push --set-upstream origin $branch
cd ..
}
########################################
# Delete the folders created by this script
########################################
deleteClones(){
echo "Deleting local clones/checkouts"
rm -rf $svnSrcDir
rm -rf $svnSrcCO
rm -rf $gitClone
}
########################################
# Run the script
########################################
#processArgs
deleteExistingClones
cloneRepos
#removeLFSfiles
copySvnToGitClone
generateCommitMsg
commitToGit
deleteClones