2020-04-28 21:17:02 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2020-05-12 13:50:01 +00:00
|
|
|
# This can be easily used with something like:
|
|
|
|
# for B in $(list_old_branches.sh); do git branch --delete "${BRANCH}"; done
|
|
|
|
|
2020-04-28 21:17:02 +00:00
|
|
|
function getCommitUnix() {
|
2022-08-10 17:10:37 +00:00
|
|
|
git show --no-patch --no-notes -s --pretty='%at' "origin/${1}" 2>/dev/null
|
|
|
|
}
|
|
|
|
|
|
|
|
function getCommitAuthorName() {
|
|
|
|
git show --no-patch --no-notes -s --format='%an' "origin/${1}" 2>/dev/null
|
2020-04-28 21:17:02 +00:00
|
|
|
}
|
|
|
|
|
2021-06-10 08:16:56 +00:00
|
|
|
OLDER_THAN_DAYS="120"
|
|
|
|
if [[ ! -z "${1}" ]]; then
|
|
|
|
OLDER_THAN_DAYS="${1}"
|
|
|
|
fi
|
|
|
|
|
2020-04-28 21:17:02 +00:00
|
|
|
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\/}"
|
2022-08-10 17:10:37 +00:00
|
|
|
|
|
|
|
if [[ ${BRANCH_NAME} =~ ^(release|gh-pages).*$ ]]; then
|
2020-05-12 13:50:01 +00:00
|
|
|
continue
|
|
|
|
fi
|
2022-08-10 17:10:37 +00:00
|
|
|
|
|
|
|
COMMIT_DATE_UNIX=$(getCommitUnix $BRANCH_NAME)
|
|
|
|
AUTHOR_NAME=$(getCommitAuthorName $BRANCH_NAME)
|
|
|
|
|
|
|
|
if [[ -z "${COMMIT_DATE_UNIX}" ]]; then
|
|
|
|
continue
|
|
|
|
elif [[ ${COMMIT_DATE_UNIX} < ${OLDER_THAN} ]]; then
|
2023-01-26 06:46:16 +00:00
|
|
|
printf "%-35s %s\n" "${AUTHOR_NAME}" "${BRANCH_NAME}"
|
2020-04-28 21:17:02 +00:00
|
|
|
fi
|
|
|
|
done
|