From d7bd3fb198a4a7be6539cdf639dae73e0f5c32d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Soko=C5=82owski?= Date: Tue, 28 Apr 2020 23:17:02 +0200 Subject: [PATCH] github: add script for listing old branches MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jakub SokoĊ‚owski --- github/list_old_branches.sh | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100755 github/list_old_branches.sh diff --git a/github/list_old_branches.sh b/github/list_old_branches.sh new file mode 100755 index 0000000..46a6766 --- /dev/null +++ b/github/list_old_branches.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash + +function getCommitUnix() { + git show --no-patch --no-notes --pretty='%at' ${1} +} + +OLDER_THAN_DAYS="60" +CURRENT_TIME=$(date +%s) +OLDER_THAN_UNIX=$(( ${OLDER_THAN_DAYS} * 86400 )) +OLDER_THAN=$(( ${CURRENT_TIME} - ${OLDER_THAN_UNIX} )) + +REMOTE="origin" +REMOTE_BRANCHES=$(git ls-remote --heads --heads ${REMOTE} | cut -f2) + +for BRANCH in ${REMOTE_BRANCHES}; do + BRANCH_NAME="${BRANCH/#refs\/heads\/}" + COMMIT_DATE_UNIX=$(getCommitUnix remotes/origin/$BRANCH_NAME) + if [[ ${COMMIT_DATE_UNIX} < ${OLDER_THAN} ]]; then + echo "${BRANCH_NAME}" + fi +done