Skip to content

Instantly share code, notes, and snippets.

@brwyatt
Created December 29, 2018 23:29
Show Gist options
  • Save brwyatt/f1ff78257de8494be56d50c3a7c6259e to your computer and use it in GitHub Desktop.
Save brwyatt/f1ff78257de8494be56d50c3a7c6259e to your computer and use it in GitHub Desktop.
Script to count the lines of Puppet code for each commit in a Git repo
#!/bin/bash
file="/tmp/count.csv"
echo "datetime,commit,lines" > "${file}"
for i in $(git log --pretty='%ct:%H'); do
d=$(echo "${i}"|cut -f1 -d':')
c=$(echo "${i}"|cut -f2 -d':')
echo "Processing ${c} @ ${d}"
git checkout "${c}" > /dev/null 2>&1
git clean -dfx > /dev/null 2>&1
l=$(find ./ -type f -name '*.pp' | xargs grep -Ev '^\s*(#.*)?$' | wc -l)
echo "${d},${c},${l}" >> "${file}"
done
# vim: ts=4 sts=4 sw=4 expandtab
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment