Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/bin/clean-git
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2019-05-04 20:47:39 +0200
committerErich Eckner <git@eckner.net>2019-05-04 20:49:27 +0200
commit7cc5d3d75699376bf9f0df78f437143f0cb3b65d (patch)
treebe0623239a2166df27ccf00e6ee8b62ef09474a5 /bin/clean-git
parent0947701cd9dc60a9c8dced9e8ddebc53c64c4d5d (diff)
bin/clean-git: reclone in case we honly have one remote
Diffstat (limited to 'bin/clean-git')
-rwxr-xr-xbin/clean-git29
1 files changed, 25 insertions, 4 deletions
diff --git a/bin/clean-git b/bin/clean-git
index d8f5166..0b892a2 100755
--- a/bin/clean-git
+++ b/bin/clean-git
@@ -9,9 +9,30 @@
for repo in ${repo_names}; do
eval 'repo_path="${repo_paths__'"${repo}"'}"'
- printf 'cleaning %s (%s) ...\n' \
- "${repo}" \
- "${repo_path}"
- ionice -n 7 git -C "${repo_path}" gc
+ 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