diff options
| author | Linus Färnstrand <faern@faern.net> | 2023-05-09 13:44:24 +0200 |
|---|---|---|
| committer | Linus Färnstrand <faern@faern.net> | 2023-05-09 15:02:42 +0200 |
| commit | 3b0407d43b765870dc7580a1481d8ac0edcd447a (patch) | |
| tree | 9a1254a3361028fdfed41042298096bb1c3be1f7 /scripts | |
| parent | 50dd05d6437bc6b23fa8a9293261306580301f65 (diff) | |
| download | mullvadvpn-3b0407d43b765870dc7580a1481d8ac0edcd447a.tar.xz mullvadvpn-3b0407d43b765870dc7580a1481d8ac0edcd447a.zip | |
Add helper script for finding potentially stale remote branches
Can be used to clean out old cruft no longer needed
Diffstat (limited to 'scripts')
| -rwxr-xr-x | scripts/find-stale-remote-branches.sh | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/scripts/find-stale-remote-branches.sh b/scripts/find-stale-remote-branches.sh new file mode 100755 index 0000000000..816db2f77c --- /dev/null +++ b/scripts/find-stale-remote-branches.sh @@ -0,0 +1,37 @@ +#!/usr/bin/env bash +# +# Find and print all remote branches not commited to in over two months. +# Prints grouped by commiter email. Used to detect stale branches that +# could potentially be removed. + +TWO_MONTHS=$((60 * 60 * 24 * 60)) + +two_months_ago=$(($(date +%s) - TWO_MONTHS)) + +all_branches=$(git branch --remote | grep -v HEAD) +old_branches=() +# Filter out branches touched recently +for branch in $all_branches; do + branch_commit_timestamp=$(git show -s --format=%at "$branch") + if [[ $branch_commit_timestamp -lt $two_months_ago ]]; then + old_branches+=("$branch") + else + echo "Skipping too new branch $branch" + fi +done + +echo "" +echo "=== Stale branches? ===" +echo "" + +authors=$(for branch in "${old_branches[@]}"; do git show -s --format="%ae" "$branch"; done | sort -u) + +for author in $authors; do + echo "# $author #" + for branch in "${old_branches[@]}"; do + if [[ $(git show -s --format="%ae" "$branch") == "$author" ]]; then + echo " $branch" + fi + done + echo "" +done |
