Skip to content

Instantly share code, notes, and snippets.

@softprops
Last active October 4, 2017 04:21
Show Gist options
  • Save softprops/4bb95b2fd32656e91027c0e71dd03bb5 to your computer and use it in GitHub Desktop.
Save softprops/4bb95b2fd32656e91027c0e71dd03bb5 to your computer and use it in GitHub Desktop.
#!/bin/env bash
# git branch freshness test.
# branch-rot.sh [expiration-date-epoc-seconds]
# default expiration date is about one month ago
# seconds*minutes*hours*days*weeks*months ~ one month ago
expiration_date=$(( $(date +%s) - 60*60*24*7*4 ))
if [[ $# -eq 1 ]]; then
expiration_date=$1
fi
for branch in $(git branch -r --merged master | grep -v HEAD); do
# last commit on a branch git log with reflog date in seconds rendering only reflog date extracting unix seconds time
reflog_date=$(git log -g -n 1 --date=raw --pretty=%gd $branch -- | sed 's/.*{\(.*\) .*/\1/')
if [[ -n "$reflog_date" && "$reflog_date" -lt "$expiration_date" ]]; then
echo "stale $branch ($(date -d @$reflog_date))"
else
echo "fresh $branch ($(date -d @$reflog_date))"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment