Add script to clean and update multiple git repos
[hvutilities.git] / scripts / git-repos-update-clean
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"' {} \;