diff options
-rw-r--r-- | Makefile | 6 | ||||
-rw-r--r-- | gitolite-sync.conf.in | 20 | ||||
-rw-r--r-- | gitolite-sync.in | 55 | ||||
-rw-r--r-- | man.commons.in | 9 |
4 files changed, 25 insertions, 65 deletions
@@ -27,12 +27,11 @@ GITUSER = gitolite LIBDIR = /usr/lib MANDIR = /usr/share/man -VERSION = 0.3.3 +VERSION = 0.4 all: man.commons \ gitolite-sync.conf \ - gitolite-sync gitolite-sync.1 \ - gitolite-sync.service gitolite-sync.timer + gitolite-sync gitolite-sync.1 %: %.in sed " \ @@ -52,7 +51,6 @@ all: man.commons \ install: all install -D -m0755 -t $(DESTDIR)$(BINDIR) gitolite-sync - install -D -m0644 -t $(DESTDIR)$(LIBDIR)/systemd/system gitolite-sync.service gitolite-sync.timer install -D -m0644 -t $(DESTDIR)$(MANDIR)/man1 gitolite-sync.1 install -D -m0644 -t $(DESTDIR)$(ETCDIR) gitolite-sync.conf diff --git a/gitolite-sync.conf.in b/gitolite-sync.conf.in index 3ba06be..0fd7de9 100644 --- a/gitolite-sync.conf.in +++ b/gitolite-sync.conf.in @@ -1,19 +1,7 @@ #!/bin/bash -# this regex must match the to-be-synchronized remotes (or their url) -remote_regex='[@.]eckner\.net:' +# these remotes will be synced +sync_remotes=('ecknernet') -# these directories contain the to-be-synchronized repositories -repository_dirs=( - $( - getent passwd #GITUSER# \ - | cut -d: -f6 \ - | sed 's,$,/repositories,' - ) -) - -# name and path of default remote -default_remote_name='ecknernet' -default_remote_path_substitution=' - s#^'"${repository_dirs[0]}"'#gitolite@eckner.net:# -' +# these remotes will be created, if they do not yet exist +default_remotes['ecknernet']='gitolite@git.eckner.net:' 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 diff --git a/man.commons.in b/man.commons.in index c56a2f8..a0d8efa 100644 --- a/man.commons.in +++ b/man.commons.in @@ -7,8 +7,9 @@ gitolite-conf(1) [CONFIG] The configfile \fB#ETCDIR#/gitolite.conf\fP is a bash script, which defines the following variables: .TP -.B "remote_regex" -regular expression for remotes that should be synchronized +.B "sync_remotes" +list of to-be-synced remotes. +A non-existing remote will be ignored. .TP -.B "home_dirs" -array of directories to be synchronized by \fBgitolite-sync\fP +.B "default_remotes" +these remotes will be added if they do not exist |