Last active
January 2, 2016 02:19
-
-
Save joshrp/8236604 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env bash | |
# check branches created from and merged to this branch | |
REMOTE=upstream | |
COMPAREBRANCH=develop | |
MASTER=refs/remotes/$REMOTE/$COMPAREBRANCH | |
git fetch $REMOTE | |
# for each remote branch... | |
for BRANCH in $(git for-each-ref --format='%(refname)' refs/heads/); do | |
# ...except the $MASTER branch and the current HEAD | |
[[ $BRANCH == $MASTER || $BRANCH =~ /HEAD$ ]] && continue | |
# get the hash for the head of the branch | |
BRANCH_HEAD=$(git show-ref --head --hash $BRANCH) | |
# returns the first shared commit among $MASTER and $BRANCH commits | |
BRANCH_POINT=$(fgrep -m 1 -f <(git rev-list --first-parent $BRANCH) \ | |
<(git rev-list --first-parent $MASTER)) | |
# find the best merge point | |
BRANCH_MERGE=$(git merge-base $MASTER $BRANCH) | |
# determine the type of branch | |
if [[ $BRANCH_POINT == $BRANCH_HEAD ]]; then | |
echo -e "$BRANCH: \t\t\tnew branch with 0 commits" | |
elif [[ $BRANCH_MERGE == $BRANCH_HEAD ]]; then | |
echo -e "$BRANCH: \t\tfully merged into $REMOTE/$COMPAREBRANCH" | |
else | |
echo -e "$BRANCH: \t\tbranch with changes" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment