Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/bin/change-git-remotes
diff options
context:
space:
mode:
Diffstat (limited to 'bin/change-git-remotes')
-rwxr-xr-xbin/change-git-remotes94
1 files changed, 94 insertions, 0 deletions
diff --git a/bin/change-git-remotes b/bin/change-git-remotes
new file mode 100755
index 0000000..f4573b2
--- /dev/null
+++ b/bin/change-git-remotes
@@ -0,0 +1,94 @@
+#!/bin/sh
+
+# shellcheck source=../lib/load-configuration
+. "${0%/*}/../lib/load-configuration"
+
+if [ $# -eq 1 ] && [ "x$1" = 'x-q' ]; then
+ quiet=true
+elif [ $# -ne 0 ]; then
+ printf 'change-git-remotes [-q]\n'
+ exit 1
+else
+ quiet=false
+fi
+
+{
+ # shellcheck disable=SC2016
+ eval "$(
+ printf '%s\n' "${repo_names}" \
+ | tr ' ' '\n' \
+ | sed '
+ s/^.*$/echo "\0 ${repo_paths__\0}"/
+ '
+ )"
+ printf '%s\n' "builder ${base_dir}"
+} \
+| while read -r git_name git_dir; do
+ if ! remotes=$(
+ git -C "${git_dir}" remote 2>/dev/null
+ ); then
+ ${quiet} \
+ || >&2 printf '"%s" (%s) seems to be no git directory.\n' \
+ "${git_dir}" \
+ "${git_name}"
+ continue
+ fi
+ if [ "${remotes}" != 'origin' ]; then
+ ${quiet} \
+ || >&2 printf '"%s" (%s) has multiple remotes - skipping.\n' \
+ "${git_dir}" \
+ "${git_name}"
+ continue
+ fi
+ if git -C "${git_dir}" fetch >/dev/null 2>&1; then
+ ${quiet} \
+ || >&2 printf '"%s" (%s) can fetch normally - skipping.\n' \
+ "${git_dir}" \
+ "${git_name}"
+ continue
+ fi
+ url=$(
+ git -C "${git_dir}" remote get-url origin
+ )
+ case "${git_name}" in
+ 'archlinux32')
+ new_urls=$(
+ printf 'https://git%s.archlinux32.org/archlinux32/packages\n' \
+ '' 2 3 4
+ )
+ ;;
+ 'builder')
+ new_urls=$(
+ printf 'https://git%s.archlinux32.org/archlinux32/builder\n' \
+ '' 2 3 4
+ )
+ ;;
+ *)
+ new_urls="${url}"
+ ;;
+ esac
+ if [ "${new_urls}" = "${url}" ]; then
+ ${quiet} \
+ || printf 'No alternative remotes are known for %s - skipping.\n' \
+ "${git_name}"
+ continue
+ fi
+ printf '%s\n' "${new_urls}" \
+ | while read -r new_url; do
+ if [ "${new_url}" = "${url}" ]; then
+ continue
+ fi
+ git -C "${git_dir}" remote set-url origin "${new_url}"
+ git -C "${git_dir}" remote set-url origin "${new_url}"
+ if git -C "${git_dir}" fetch >/dev/null 2>&1; then
+ ${quiet} \
+ || >&2 printf '"%s" (%s): remote changed: "%s" -> "%s".\n' \
+ "${git_dir}" \
+ "${git_name}" \
+ "${url}" \
+ "${new_url}"
+ break
+ fi
+ git -C "${git_dir}" remote set-url origin "${url}"
+ done
+done