summaryrefslogtreecommitdiff
path: root/gitolite-sync.in
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2019-05-29 15:28:11 +0200
committerErich Eckner <git@eckner.net>2019-05-29 15:28:11 +0200
commit7a3ad858d96ddaf13d4664426301b10307e4688e (patch)
tree6cfb417e4c213b33d25db119d7e245f537d689a1 /gitolite-sync.in
parent2fd966d1ce652f8bb71aa2ea0e6f313e06bab641 (diff)
downloadgitolite-sync-7a3ad858d96ddaf13d4664426301b10307e4688e.tar.xz
Makefile new
Diffstat (limited to 'gitolite-sync.in')
-rw-r--r--gitolite-sync.in97
1 files changed, 97 insertions, 0 deletions
diff --git a/gitolite-sync.in b/gitolite-sync.in
new file mode 100644
index 0000000..adc67bd
--- /dev/null
+++ b/gitolite-sync.in
@@ -0,0 +1,97 @@
+#!/bin/bash
+
+if [ $# -eq 1 ]; then
+ if [ "$1" == "--help" ]; then
+ >&2 echo \
+'Usage: gitolite-sync [options]
+Synchronize the configured git repositories.
+
+Options:
+#HELPTEXT# #'
+ exit
+ elif [ "$1" == "--version" ]; then
+ echo '#VERSION#'
+ exit
+ fi
+fi
+
+if [ $# -ne 0 ]; then
+ >&2 echo 'too many arguments'
+ exit 1
+fi
+
+. "#ETCDIR#/gitolite-sync.conf"
+
+if [ ${#repository_dirs[@]} -eq 0 ]; then
+ >&2 echo 'no repository_dirs defined'
+ exit 1
+fi
+
+for repository_dir in "${repository_dir[@]}"; do
+ if [ -z "${repository_dir}" ] || [ ! -d "${repository_dir}" ]; then
+ >&2 printf 'cannot find "%s"\n' \
+ "${repository_dir}"
+ exit 1
+ fi
+done
+
+for repository_dir in "${repository_dir[@]}"; 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}" ]; then
+ >&2 printf 'Repository "%s" has no backup remotes.\n' \
+ "${path}"
+ continue
+ fi
+ for remote in ${remotes}; do
+ git -C "${path}" fetch "${remote}" -p
+ done
+ branches=$(
+ git -C "${path}" branch --all \
+ | sed '
+ s,^.\sremotes/[^/[:space:]]\+/,,
+ t
+ d
+ '
+ )
+ if [ -n "$(git -C "${path}" tag -l)" ]; then
+ has_tags=true
+ else
+ has_tags=false
+ fi
+ if [ -z "${branches}" ] && ! ${has_tags}; then
+ >&2 printf 'Repository "%s" has no branches and no tags.\n' \
+ "${path}"
+ continue
+ fi
+ for remote in ${remotes}; do
+ if ${has_tags}; then
+ git -C "${path}" push "${remote}" --tags
+ fi
+ if [ -z "${branches}" ]; then
+ continue
+ fi
+ for branch in ${branches}; do
+ if ! git -C "${path}" branch \
+ | sed 's/^.\s//' \
+ | grep -qxF "${branch}"; then
+ git -C "${path}" branch "${branch}" --track "${remote}/${branch}"
+ fi
+ git -C "${path}" pull --ff-only "${remote}" "${branch}" 2>/dev/null
+ git -C "${path}" push "${remote}" "${branch}"
+ done
+ done
+ done
+done