Last active
December 3, 2016 13:40
-
-
Save makadev/3e4a00fbca703b5f7cf3779e51e36fca to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
REPO_STORE=/home/git/repo-mirror | |
REPO_POS=${REPO_STORE}/${GL_REPO}.git | |
# change umask such that anyone can read the repositories (read/search for all, rw/search for owner) | |
umask 022; | |
# uncomment for local side information on push | |
#echo "**UPDATE MIRROR** @" ${REPO_POS} | |
# check if mirror repository exists, if not -> create a bare copy | |
if [[ ! -e "$REPO_POS" ]]; then | |
mkdir -p ${REPO_POS} > /dev/null 2>&1 | |
cd ${REPO_POS} > /dev/null 2>&1 | |
git init --bare "--shared=umask" > /dev/null 2>&1 | |
cd - > /dev/null 2>&1 | |
fi | |
# push that data... | |
git push --mirror ${REPO_POS} > /dev/null 2>&1 | |
# make sure we leave with EC 0 | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Gitolite repo-specific bare mirror hook
This creates a readable, bare copy of repositories for which this is enabled and keeps it up to date on every push. F.e. for redmine, gitweb, etc. that can't - and should not - access the main repository.
How to enable repo-specific and make that hook execute for a certain repository
LOCAL_CODE => "$ENV{HOME}/local",
(server only) orLOCAL_CODE => "$rc{GL_ADMIN_BASE}/local",
(push-able via gitolite-admin) in .gitolite.rc'repo-specific-hooks',
in gitolite.rcmkdir -p local/hooks/repo-specific
chmod +x local/hooks/repo-specific/bare-mirror-hook.sh
option hook.post-receive = bare-mirror-hook.sh
for the repositories, add/commit/pushNote
Troubleshooting
.gitolite.rc
for gitolite to reload it (there may be another way with gitolite setup but I didn't test it). Check if the scriptlocal/hooks/multi-hook-driver
was created, It's a sign that it worked.remote: **UPDATE MIRROR** @ /home/git/repo-mirror/testing/testing.git
, if not then the hook is simply not called f.e. due to a typo in the hook option.