Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
トピックブランチのmasterからの遅れを調べる
#!/bin/bash
REMOTE_NAME='origin'
git fetch --prune ${REMOTE_NAME}
msg=''
for remote_branch in `git branch -r | grep -v '\->'| grep ${REMOTE_NAME}/`
do
ahead=0
behind=0
for rev in `git rev-list --left-right ${remote_branch}...${REMOTE_NAME}/master`
do
if test $(echo $rev | grep -e '^<') ; then
ahead=`expr $ahead + 1`
else
behind=`expr $behind + 1`
fi
done
#本当は下記のようにしたいのだが、grep -cが何故か1しか返さず上記ループで妥協
#rev_list=`git rev-list --left-right ${remote_branch}...${REMOTE_NAME}/master`
#ahead=`echo ${rev_list} | grep -c '<'`
#behind=`echo ${rev_list} | grep -c '>'`
if test $ahead -gt 0 ; then
echo "${remote_branch} is ${behind} commit(s) behind ${REMOTE_NAME}/master"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.