#!/bin/bash
################################################
### Managed by someone's ansible provisioner ###
################################################
# Part of: https://git.somenet.org/root/pub/somesible.git
# 2017-2026 by someone <someone@somenet.org>
#

date -Isec > /tmp/compactGitRepos.txt
echo "------OLD------" >> /tmp/compactGitRepos.txt
find /srv/gitolite/repositories -path '*.git' -type d -print0 | sort -z | du -scm --files0-from=- >> /tmp/compactGitRepos.txt
echo "------NEW------" >> /tmp/compactGitRepos.txt
find /srv/gitolite/repositories -path '*.git/config' -type f -execdir echo "------------------------------------------" \; -execdir pwd \; -execdir git gc --prune=all \;
find /srv/gitolite/repositories -path '*.git' -type d -print0 | sort -z | du -scm --files0-from=- > /tmp/compactGitRepos.new.txt
echo "-----STATS-----"
cat /tmp/compactGitRepos.txt
cat /tmp/compactGitRepos.new.txt
echo "$(grep 'total$' /tmp/compactGitRepos.txt) before"
echo "repo count: `echo "$(cat /tmp/compactGitRepos.new.txt|wc -l)-1" | bc`"
rm -f /tmp/compactGitRepos.txt /tmp/compactGitRepos.new.txt
