summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorLinus Färnstrand <linus@mullvad.net>2023-05-09 15:03:16 +0200
committerLinus Färnstrand <linus@mullvad.net>2023-05-09 15:03:16 +0200
commitdca116e7c22f76e4c71e252f3ade65bd3dfac713 (patch)
tree9a1254a3361028fdfed41042298096bb1c3be1f7
parent50dd05d6437bc6b23fa8a9293261306580301f65 (diff)
parent3b0407d43b765870dc7580a1481d8ac0edcd447a (diff)
downloadmullvadvpn-dca116e7c22f76e4c71e252f3ade65bd3dfac713.tar.xz
mullvadvpn-dca116e7c22f76e4c71e252f3ade65bd3dfac713.zip
Merge branch 'add-find-stale-branches-script'
-rwxr-xr-xscripts/find-stale-remote-branches.sh37
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