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() {
|
|
|
|
git show --no-patch --no-notes --pretty='%at' ${1}
|
|
|
|
}
|
|
|
|
|
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\/}"
|
2020-05-12 13:50:01 +00:00
|
|
|
if [[ ${BRANCH_NAME} = release* ]]; then
|
|
|
|
continue
|
|
|
|
fi
|
2020-04-28 21:17:02 +00:00
|
|
|
COMMIT_DATE_UNIX=$(getCommitUnix remotes/origin/$BRANCH_NAME)
|
|
|
|
if [[ ${COMMIT_DATE_UNIX} < ${OLDER_THAN} ]]; then
|
|
|
|
echo "${BRANCH_NAME}"
|
|
|
|
fi
|
|
|
|
done
|