aboutsummaryrefslogtreecommitdiff
path: root/bin/gscr.sh
diff options
context:
space:
mode:
Diffstat (limited to 'bin/gscr.sh')
-rw-r--r--bin/gscr.sh28
1 files changed, 28 insertions, 0 deletions
diff --git a/bin/gscr.sh b/bin/gscr.sh
new file mode 100644
index 00000000..2fbee05a
--- /dev/null
+++ b/bin/gscr.sh
@@ -0,0 +1,28 @@
+# Scrub and pack Git repositories
+
+# Iterate through given directories; default to the current one
+for arg in "${@:-.}" ; do (
+
+ # Note the "exit" calls here in lieu of "continue" are deliberate; we're in
+ # a subshell, so leaving it will continue the loop.
+
+ # Enter either bare repository or .git subdir
+ case $arg in
+ *.git)
+ cd -- "$arg" || exit
+ ;;
+ *)
+ cd -- "$arg"/.git || exit
+ ;;
+ esac
+
+ # Check for bad references or other integrity/sanity problems
+ git fsck || exit
+
+ # Expire dangling references
+ git reflog expire --expire=now || exit
+
+ # Remove dangling references
+ git gc --prune=now --aggressive || exit
+
+) done