Skip to content

Instantly share code, notes, and snippets.

@bricss
Last active February 24, 2023 13:40
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bricss/4daffede03a4c63d3034b9aab35363bc to your computer and use it in GitHub Desktop.
Save bricss/4daffede03a4c63d3034b9aab35363bc to your computer and use it in GitHub Desktop.
Generates monthly Git reports
#!/usr/bin/env bash
# Generates monthly Git reports
# Usage: `sh git-report.sh [ample]`
author=$(git config user.name)
ample=$(expr "$1" == 'ample')
date=$(date +%Y-%m-%d)
foretime=$(date +%Y-%m-01)
fullpath="$PWD"
target=reports/report-${date}
rm -rf ${target}
mkdir -p ${target}
function report {
cname=$(git rev-parse --show-toplevel | xargs basename)
cpath=${fullpath}/${target}/${cname}-${date}
changelog=${cpath}.csv
delta=${cpath}-diff.txt
git log --all --author="$author" --date=short --no-merges --pretty=format:%h,%ae,%ad,%s, --reverse --shortstat --since=${foretime} | paste - - - | tr -d '\t' > ${changelog}
if [[ ! -s ${changelog} ]]; then
rm -f ${changelog}
else
git log --all --author="$author" --patch-with-raw --reverse --since=${foretime} > ${delta}
if which 7z &> /dev/null; then
(($ample)) \
&& git log --all --author="$author" --format='' --name-only --reverse --since=${foretime} \
| xargs -n1 | sort -u | uniq -i | xargs -r 7z a -mx -t7z ${cpath}.7z ${changelog} ${delta} \
|| 7z a -mx -t7z ${cpath}.7z ${changelog} ${delta}
else
(($ample)) \
&& git log --all --author="$author" --format='' --name-only --reverse --since=${foretime} \
| xargs -n1 | sort -u | uniq -i | xargs -r tar --ignore-failed-read -cJvf ${cpath}.tar.xz --directory ${cpath%/*} ${changelog##*/} ${delta##*/} --directory "$PWD" \
|| tar --ignore-failed-read -cJvf ${cpath}.tar.xz --directory ${cpath%/*} ${changelog##*/} ${delta##*/}
fi
fi
}
function traverse {
if [[ -d '.git' ]]; then
report
else
for dir in */; do
if [[ -d "$dir" ]]; then
pushd "$dir"
traverse
popd
fi
done
fi
}
traverse
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment