Add script to clean and update multiple git repos
authorHugo Villeneuve <hugo@hugovil.com>
Thu, 5 Feb 2015 04:15:32 +0000 (23:15 -0500)
committerHugo Villeneuve <hugo@hugovil.com>
Thu, 5 Feb 2015 04:26:52 +0000 (23:26 -0500)
scripts/Makefile.am
scripts/git-repos-update-clean [new file with mode: 0755]

index 43a94ca..7e069fa 100644 (file)
@@ -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 (executable)
index 0000000..3ea50c2
--- /dev/null
@@ -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"' {} \;