deleted: cronjob-update-packages-list.new deleted: cronjob-updatedb-mirrors renamed: rsync-notify-upload -> notify-rsync-upload modified: colour-changelog modified: cronjob-clean-php modified: cronjob-dehydrated modified: cronjob-fix-log-acls modified: cronjob-rotate-logs-today-symlink modified: cronjob-update-mirrors-search-db modified: cronjob-update-packages-list modified: cronjob-warn-git-status modified: cronjob-warn-smtp-queue modified: do-backup modified: dovecot-service-checksuspended modified: firewall-initscript modified: git-auto-merge modified: mirror modified: mirror-new-slackware-release.gpg modified: mirror-wrapper modified: notify-rsync-upload modified: sbosrcarch-wrapper
64 lines
2.6 KiB
Bash
Executable file
64 lines
2.6 KiB
Bash
Executable file
#!/bin/bash
|
|
# Automatically fetch and merge (if possible) upstream changes into a local git repository.
|
|
|
|
# What platform we're running on.
|
|
PLATFORM="$(uname -s)"
|
|
|
|
# Only operate on repositories that are set for maintenance work in ~/.gitconfig.
|
|
while IFS= read -r REPO; do
|
|
# Get into the working directory.
|
|
pushd "$REPO" >/dev/null 2>&1 || {
|
|
printf "%s: %s\\n" "${0##*/}" "failed to change to working directory '$REPO'" >&2
|
|
RET=1
|
|
continue
|
|
}
|
|
|
|
# Skip processing if auto-merging is disabled in this repository.
|
|
[[ "$(git config --local --get --type bool script.AutoMergeDisabled 2>/dev/null)" != "true" ]] && {
|
|
# Fetch the latest updates.
|
|
if git fetch --all --atomic --tags >/dev/null 2>&1; then
|
|
# Try to merge using fast-forward only, so no clobbering is done.
|
|
if MERGE="$(git merge --ff-only 2>/dev/null)"; then
|
|
[[ "$(printf "%s" "$MERGE" | awk '{ print $1; exit }')" == "Updating" ]] && {
|
|
if [[ "$PLATFORM" == "Linux" ]]; then
|
|
# Linux, how I love thee.
|
|
NOW="$(date +'%s%3N')"
|
|
elif [[ "$PLATFORM" == "Darwin" ]]; then
|
|
# This sucks... but so does Darwin.
|
|
NOW="$(perl -e 'use Time::HiRes; printf "%.3f", Time::HiRes::time();')"
|
|
NOW="${NOW/.}"
|
|
else
|
|
printf "%s: %s\\n" "${0##*/}" "unsupported platform: $PLATFORM" >&2
|
|
RET=2
|
|
break
|
|
fi
|
|
git config --local --replace-all --type int script.AutoMergeLast "$NOW" >/dev/null 2>&1 || {
|
|
printf "%s: %s\\n" "${0##*/}" "updating AutoMergeLast timestamp failed for '$REPO'" >&2
|
|
RET=1
|
|
}
|
|
git config --local --replace-all --type bool script.AutoMergeSuccess true >/dev/null 2>&1 || {
|
|
printf "%s: %s\\n" "${0##*/}" "updating AutoMergeSuccess marker failed for '$REPO'" >&2
|
|
RET=1
|
|
}
|
|
}
|
|
else
|
|
git config --local --replace-all --type bool script.AutoMergeSuccess false >/dev/null 2>&1 || {
|
|
printf "%s: %s\\n" "${0##*/}" "updating AutoMergeSuccess marker failed for '$REPO'" >&2
|
|
RET=1
|
|
}
|
|
fi
|
|
else
|
|
# Mark that the auto-merge failed.
|
|
printf "%s: %s\\n" "${0##*/}" "git fetch failed for '$REPO'" >&2
|
|
git config --local --replace-all --type bool script.AutoMergeSuccess false >/dev/null 2>&1 || {
|
|
printf "%s: %s\\n" "${0##*/}" "updating AutoMergeSuccess marker failed for '$REPO'" >&2
|
|
RET=1
|
|
}
|
|
fi
|
|
}
|
|
|
|
# Back to where we started...
|
|
popd >/dev/null 2>&1 || continue
|
|
done < <(git config --global --get-all maintenance.repo 2>/dev/null)
|
|
|
|
exit "${RET:-0}"
|