diff options
author | Erich Eckner <git@eckner.net> | 2021-07-29 22:03:59 +0200 |
---|---|---|
committer | Erich Eckner <git@eckner.net> | 2021-07-29 22:03:59 +0200 |
commit | 919b714d8f3fc08f9600053abb063c98ae560356 (patch) | |
tree | 050584c8be3a374f49e2f04bd056e95f53e03ade /gitolite-sync.in | |
parent | fe598d432cf8bc1a1ed1f62f8bd95739f3dd4f27 (diff) | |
download | gitolite-sync-919b714d8f3fc08f9600053abb063c98ae560356.tar.xz |
Diffstat (limited to 'gitolite-sync.in')
-rw-r--r-- | gitolite-sync.in | 55 |
1 files changed, 14 insertions, 41 deletions
diff --git a/gitolite-sync.in b/gitolite-sync.in index d22151c..efd85ab 100644 --- a/gitolite-sync.in +++ b/gitolite-sync.in @@ -4,7 +4,9 @@ if [ $# -eq 1 ]; then if [ "$1" == "--help" ]; then >&2 echo \ 'Usage: gitolite-sync [options] -Synchronize the configured git repositories. +Synchronize the git repository $GL_REPO in $GIT_DIR. + +This can be used as a post-receive hook in gitolite to sync with other repositories. Options: #HELPTEXT# #' @@ -20,49 +22,20 @@ if [ $# -ne 0 ]; then exit 1 fi +declare -A default_remotes . "#ETCDIR#/gitolite-sync.conf" -if [ ${#repository_dirs[@]} -eq 0 ]; then - >&2 echo 'no repository_dirs defined' - exit 1 -fi - -for repository_dir in "${repository_dirs[@]}"; do - if [ -z "${repository_dir}" ] || [ ! -d "${repository_dir}" ]; then - >&2 printf 'cannot find "%s"\n' \ - "${repository_dir}" - exit 1 +for remote in "${!default_remotes[@]}"; do + if git -C "${GIT_DIR}" remote \ + | grep -qxF "${remote}"; then + continue fi + git -C "${GIT_DIR}" remote add "${remote}" "${default_remotes["${remote}"]}${GL_REPO}.git" done -for repository_dir in "${repository_dirs[@]}"; do - find "${repository_dir}" \ - -type d \ - -name '*.git' \ - -printf '%p\n' \ - -prune \ - | while read -r path; do - >&2 printf 'synchronizing "%s" ...\n' \ - "${path}" - remotes=$( - git -C "${path}" remote -v \ - | grep "${remote_regex}" \ - | awk '{print $1}' \ - | sort -u - ) - if [ -z "${remotes}" ] \ - && ! git -C "${path}" remote get-url "${default_remote_name}" >/dev/null 2>&1; then - >&2 printf 'adding default remote "%s", because no remote was found so far\n' \ - "${default_remote_name}" - git -C "${path}" remote add "${default_remote_name}" "$( - printf '%s\n' "${path}" \ - | sed "${default_remote_path_substitution}" - )" - remotes="${default_remote_name}" - fi - for remote in ${remotes}; do - git -C "${path}" fetch "${remote}" 'refs/heads/*:refs/heads/*' 'refs/tags/*:refs/tags/*' - git -C "${path}" push "${remote}" 'refs/heads/*:refs/heads/*' 'refs/tags/*:refs/tags/*' - done - done +for remote in "${sync_remotes[@]}"; do + git -C "${GIT_DIR}" remote \ + | grep -qxF "${remote}" \ + || continue + git -C "${GIT_DIR}" push "${remote}" 'refs/heads/*:refs/heads/*' 'refs/tags/*:refs/tags/*' done |