From: Hugo Villeneuve Date: Thu, 5 Feb 2015 04:15:32 +0000 (-0500) Subject: Add script to clean and update multiple git repos X-Git-Url: http://gitweb.hugovil.com/?a=commitdiff_plain;h=3104f7d42a0424c764c1aa483bc0349ab3900e40;p=hvutilities.git Add script to clean and update multiple git repos --- diff --git a/scripts/Makefile.am b/scripts/Makefile.am index 43a94ca..7e069fa 100644 --- a/scripts/Makefile.am +++ b/scripts/Makefile.am @@ -23,6 +23,7 @@ dist_bin_SCRIPTS = \ hv-hg-functions.sh \ hg-format-patch hg-update-subrepos \ git-hg-sub-import git-hg-sub-update \ + git-repos-update-clean \ source-code-stats \ flac2ogg flac2mp3 \ hv-scan \ diff --git a/scripts/git-repos-update-clean b/scripts/git-repos-update-clean new file mode 100755 index 0000000..3ea50c2 --- /dev/null +++ b/scripts/git-repos-update-clean @@ -0,0 +1,31 @@ +#!/bin/bash + +function repos_update_clean() +{ + # Make sure directory exists + if [ ! -d "${1}" ]; then + return + fi + + # Update only git repos + if [ ! -d "${1}/.git" ]; then + return + fi + + echo "Updating repos: ${1}" + pushd "${1}" 1> /dev/null + git remote update + git gc --aggressive + + # Iterate over all remotes and clean (prune) + for r in $(git remote); do + echo " Cleaning remote: ${r}" + git remote prune ${r} + done + + popd 1> /dev/null +} + +export -f repos_update_clean + +find . -maxdepth 1 -type d -exec bash -c 'repos_update_clean "$0"' {} \;