#!/bin/sh # clean git repositories # shellcheck disable=SC2119,SC2120 # shellcheck source=../lib/load-configuration . "${0%/*}/../lib/load-configuration" for repo in ${repo_names}; do eval 'repo_path="${repo_paths__'"${repo}"'}"' while [ "${repo_path}" != "${repo_path%/}" ]; do repo_path="${repo_path%/}" done remote=$( git -C "${repo_path}" remote -v \ | awk '{print $2}' \ | sort -u ) if printf '%s\n' "${remote}" \ | wc -l \ | grep -xqF 1 ; then printf 'recloning %s (%s) ...\n' \ "${repo}" \ "${repo_path}" git clone --bare "${repo_path}" "${repo_path}.new" git -C "${repo_path}.new" remote set-url origin "${remote}" mv "${repo_path}" "${repo_path}.old" mv "${repo_path}.new" "${repo_path}" rm -rf --one-file-system "${repo_path}.old" else printf 'cleaning %s (%s) ...\n' \ "${repo}" \ "${repo_path}" ionice -n 7 git -C "${repo_path}" gc fi printf '... done\n' done