From 3104f7d42a0424c764c1aa483bc0349ab3900e40 Mon Sep 17 00:00:00 2001 From: Hugo Villeneuve Date: Wed, 4 Feb 2015 23:15:32 -0500 Subject: [PATCH] Add script to clean and update multiple git repos --- scripts/Makefile.am | 1 + scripts/git-repos-update-clean | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100755 scripts/git-repos-update-clean 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"' {} \; -- 2.20.1