Last active
August 30, 2018 14:43
-
-
Save moisespsena/665b64ef32aad9aad3f38a642eeafe37 to your computer and use it in GitHub Desktop.
Show GIT repositories state recursively
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
#!/bin/bash | |
# Show GIT repositories state recursively | |
if [ "$1" != '' ]; then | |
cd "$1" || exit $? | |
fi | |
find `pwd` -name .git -type d | while read l; do | |
p=`dirname "$l"` | |
cd "$p" | |
sc=0 | |
if [ -n "$(git status --porcelain)" ]; then | |
# changed | |
sc=1 | |
state="CHANGED" | |
else | |
# not changed, compare local with remote branch | |
# get current branch name | |
branch_name=`git rev-parse --abbrev-ref HEAD` | |
# check if remote branch exists | |
git show-branch remotes/origin/$branch_name >/dev/null | |
if [ $? -eq 128 ]; then | |
# is local branch only | |
sc=1 | |
state="NEW BRANCH" | |
else | |
# compare local with remote | |
s=`git diff $branch_name origin/$branch_name` | |
if [ "$s" != '' ]; then | |
# changed | |
sc=1 | |
state="REMOTE CHANGED" | |
else | |
state= | |
fi | |
fi | |
fi | |
# if changed, print repo path and state | |
[ $sc -eq 1 ] && echo "$p -> $state" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment