Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
J
JenkinsConfiguration
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ChimeraTK Mirror
JenkinsConfiguration
Commits
e266a84a
Commit
e266a84a
authored
2 years ago
by
Martin Christoph Hierholzer
Browse files
Options
Downloads
Patches
Plain Diff
add script to mirror gitlab to github
parent
07ceff0f
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
scripts/github-to-gitlab-mirror.sh
+93
-0
93 additions, 0 deletions
scripts/github-to-gitlab-mirror.sh
with
93 additions
and
0 deletions
scripts/github-to-gitlab-mirror.sh
0 → 100755
+
93
−
0
View file @
e266a84a
#!/bin/bash -e
REPOLIST
=
`
gh repo list ChimeraTK
-L
300 |
grep
'^ChimeraTK/'
|
sed
-e
's_^ChimeraTK/__'
-e
's_[[:space:]].*$__'
`
export
GITLAB_HOST
=
gitlab.desy.de
NMIRRORS
=
0
ERROR
=
0
for
repo
in
$REPOLIST
;
do
NMIRRORS
=
$((
NMIRRORS
+
1
))
echo
"=== Mirroring
$repo
"
if
[[
"
$repo
"
==
"chimeratk.github.io"
]]
;
then
echo
"(Skipping, big and easy to recreate so no backup necessary)"
continue
fi
mirrorname
=
"gitlab.desy.de/chimeratk-mirror/
${
repo
}
"
if
!
glab repo view
"
${
mirrorname
}
"
>
/dev/null 2>&1
;
then
rm
-rf
temp-checkout
mkdir
temp-checkout
cd
temp-checkout
git init
.
NO_PROMPT
=
1 glab repo create
-P
"
${
mirrorname
}
"
cd
..
fi
rm
-rf
temp-checkout
mkdir
temp-checkout
cd
temp-checkout
git init
--bare
git remote add origin
--mirror
=
fetch
"https://github.com/ChimeraTK/
$repo
"
git remote add gitlab
--mirror
=
push
"git@gitlab.desy.de:chimeratk-mirror/
${
repo
}
"
# Configure which refs to fetch, to exclude GitHub pull requests. Including them would lead to an error message
# when trying to push the pull request refs to GitLab ("deny updating a hidden ref").
FETCH
=
'\tfetch = +refs/heads/*:refs/heads/*\n\tfetch = +refs/tags/*:refs/tags/*'
sed
-i
config
-e
's_^[[:space:]]*fetch = +refs/\*:refs/\*$_'
"
$FETCH
"
'_'
git remote update
# Make sure the master branch is protected, just in case a previous run of this script was interrupted in the wrong place
glab api projects/chimeratk-mirror%2F
$repo
/protected_branches/master
-F
allow_force_push
=
false
-X
PATCH
PUSHFAIL
=
0
git push
--mirror
gitlab
||
PUSHFAIL
=
1
echo
"HIER PUSHFAIL =
$PUSHFAIL
"
if
[
"
$PUSHFAIL
"
!=
"0"
]
;
then
# Pushing to protected master might fail if upstream had force-pushed changes to master
# First create a backup of the previous master branch with a new, unique name and protect it
MASTER_BACKUP_NAME
=
"master-
`
date
+%Y-%m-%d_%H.%M.%S
`
"
git remote add gitlab_nomirror
"git@gitlab.desy.de:chimeratk-mirror/
${
repo
}
"
git remote update
git branch
$MASTER_BACKUP_NAME
gitlab_nomirror/master
git push gitlab_nomirror
$MASTER_BACKUP_NAME
git remote remove gitlab_nomirror
glab api projects/chimeratk-mirror%2F
$repo
/protected_branches/
-F
name
=
$MASTER_BACKUP_NAME
-F
allow_force_push
=
false
-X
POST
git remote update
# Now unprotect the master branch, retry push and finally protect the branch again
glab api projects/chimeratk-mirror%2F
$repo
/protected_branches/master
-F
allow_force_push
=
false
-X
PATCH
PUSHFAIL
=
0
git push
--mirror
gitlab
||
PUSHFAIL
=
1
glab api projects/chimeratk-mirror%2F
$repo
/protected_branches/master
-F
allow_force_push
=
true
-X
PATCH
# Check for error during push
if
[
"
$PUSHFAIL
"
!=
"0"
]
;
then
echo
"*** ERROR: Pushing still failed. Continue with other repos and fail later."
ERROR
=
1
fi
fi
cd
..
rm
-rf
temp-checkout
done
if
[
$NMIRRORS
-lt
10
]
;
then
echo
"Only
$NMIRRORS
repos have been mirrored. Something probably went wrong..."
exit
1
fi
if
[
"
$ERROR
"
!=
"0"
]
;
then
echo
"Errors have occurred before!"
exit
1
fi
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment