Created
October 6, 2021 14:13
-
-
Save icorbrey/830b2c76dd35503df26a12b4d725321f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
compare='dev' | |
min_commits_ahead=5 | |
max_commits_behind=500 | |
max_time_elapsed="$((30 * 24 * 60 * 60))" | |
git fetch origin 2> /dev/null | |
branches="$(\ | |
git remote show origin \ | |
| awk '/Remote branches/ {f = 1; next} /Local branches/ {f = 0} f' \ | |
| awk '{print ($1 ~ /refs/) ? $1 : "refs/remotes/origin/"$1}' \ | |
| grep -vE /refs\/remotes\/origin\/$compare/ | |
)" | |
current_date="$(date '+%s')" | |
for branch in $branches; do | |
counts="$(git rev-list --left-right --count $compare)" | |
ahead="$(echo $counts | awk '$1')" | |
behind="$(echo $counts | awk '$2')" | |
last_commit_date="$(git show --format='%ct' $branch)" | |
time_elapsed="$(($current_date - $last_commit_date))" | |
#$ahead -lt $min_commits_ahead -a $behind -ge $max_commits_behind -o | |
if [ $time_elapsed -gt $max_time_elapsed ]; then | |
echo "$branch (-$behind, +$ahead)" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment