forked from pramodk/nrn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
repository_mirror
executable file
·168 lines (136 loc) · 4.83 KB
/
repository_mirror
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
#!/bin/bash
#github master branch and bitbucket trunk branch mirror each other
# keep neuron.yale.edu up to date with respect to bitbucket
#list of repositories to mirror.
repositories="iv nrn"
#crontab -e
#0 */3 * * * /home/hines/neuron/repository_mirror/repository_mirror
# bitbucket and github settings have ssh keys to allow push without
# password.
# https://github.com/felipec/git-remote-hg software is used to make
# a git clone of the bitbucket hg repository using 'git clone hg::ssh:...'
# and track the remote origin/branches/trunk with the local branches/trunk.
# Also, the git repository on github has its remote git/master branch
# tracked by the local master branch.
# It is asserted that only one remote repository can be ahead of the local
# repository. If both are ahead, the merges must be done manually.
# If bitbucket is ahead of github, then the branches/trunk is (fast forward)
# merged to master and the latter is pushed to github.
# If github is ahead of bitbucket, then master is (fast forward) merged to
# branches/trunk and the latter is pushed to bitbucket.
# original bootstrapping requires a bitbucket hg repository and a
# github git repository with the same name (manually
# created from an earlier version of the hg repository). If the git
# repository is empty, this script will create a master branch and push
# an example of how to re-establish consistency when both hg and git
# repositories are different is
if false ; then
git clone http://github.com/nrnhines/nrn nrngit
hg clone http://bitbucket.org/nrnhines/nrn nrnhg
git clone hg::nrnhg temp
cd temp
git fetch
git checkout -b branches/trunk origin/branches/trunk
git config core.notesRef refs/notes/hg
git remote add nrngit /home/hines/neuron/hggit/nrngit
git fetch nrngit
git checkout branches/trunk
git merge nrngit/master #and fix conflicts
git commit
git push origin
git checkout master
git merge branches/trunk
cd ../nrngit
git pull ../temp
fi
local=$HOME/neuron/hggit
hgmastersite=ssh://[email protected]/nrnhines
gitmastersite=ssh://[email protected]/nrnhines
hgcopysite=ssh://[email protected]//home/hg/neuron
mkdir -p $local
cd $local
for rep in $repositories ; do
echo -e "\n\n\n${rep}\n"
cd $local
if test ! -d ${rep}hggit ; then
git clone hg::$hgmastersite/${rep} ${rep}hggit
cd ${rep}hggit
git fetch
git checkout -b branches/trunk origin/branches/trunk
git config core.notesRef refs/notes/hg
# is the github just initialized with no commits or can
# its master be checked out
git remote add git $gitmastersite/$rep
if ! git fetch git ; then
echo "$gitmastersite/$rep does not exist. Initialize it on github"
exit 1
fi
if ! git checkout -b master git/master ; then
echo "github empty so create master branch and push"
git branch master
git checkout master
git push -u git master
elif test "`git status -b --porcelain`" != "## master...git/master" ; then
echo "not on branch master...git/master"
echo "$gitmastersite/$rep has no commits"
exit 1
fi
echo "on branch master...git/master"
cd ..
fi
cd ${rep}hggit
# verify validity
git branch --list -vv
oldhg="`git log branches/trunk --format=\"%h\" -n 1`"
oldgit="`git log master --format=\"%h\" -n 1`"
git checkout branches/trunk
git pull
git checkout master
git pull
newhg="`git log branches/trunk --format=\"%h\" -n 1`"
newgit="`git log master --format=\"%h\" -n 1`"
echo oldhg $oldhg
echo oldgit $oldgit
echo newhg $newhg
echo newgit $newgit
if test "$newgit" != "$newhg" ; then
# they are the different.
# pull from the one ahead and push to the one behind.
m2t=`git log -n 1 --format="%h" master..branches/trunk`
t2m=`git log -n 1 --format="%h" branches/trunk..master`
if test "$m2t" = "" ; then # empty means master ahead of trunk
echo "merge $rep master to trunk and push to bitbucket"
git checkout branches/trunk
git merge master branches/trunk
git push origin
elif test "$t2m" = "" ; then
echo "merge $rep trunk to master and push to github"
git checkout master
git merge branches/trunk master
git push git
else
echo "Both github and bitbucket for $rep have changes. Resolve manually."
continue
fi
fi
cd $local
# update neuron.yale.edu if necessary
hgcopyid=`hg identify -i $hgcopysite/$rep`
err=$?
if test "$err" != 0 ; then # if the repository does not exist
echo "$hgcopysite/$rep does not exist"
continue
fi
hgmasterid=`hg identify -i $hgmastersite/$rep`
if test "$hgmasterid" = "$hgcopyid" ; then
continue
fi
if test ! -d "$local/${rep}hg" ; then
echo "cloning bitbucket repository into the local ${rep}hg"
hg clone $hgmastersite/$rep ${rep}hg
fi
echo $repname $hgmasterid $hgcopyid
cd $local/${rep}hg
hg pull -u
hg push $hgcopysite/$rep
done