Created
May 14, 2018 07:25
-
-
Save metalelf0/98cd1c8a833bbe85e48004114691e221 to your computer and use it in GitHub Desktop.
Recursively check subdirectories to see git repos with pending changes
This file contains 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/zsh | |
tempfile=output | |
touch $tempfile | |
check_update () { | |
cd $1 | |
if [[ -d .git ]] | |
then | |
git fetch -q origin | |
commits_count=`git log master..origin/master --oneline | wc -l` | |
if [[ $commits_count != 0 ]] | |
then | |
echo "🔃 "$1" is "$commits_count" commit(s) behind origin/master" >> ../$tempfile | |
elif [ 'full' = "$MODE" ] | |
then | |
echo "✔️ "$1" is aligned with origin/master" >> ../$tempfile | |
fi | |
fi | |
cd .. | |
} | |
OPTS=`getopt -o m: --long mode: -n 'parse-options' -- "$@"` | |
if [ $? != 0 ] ; then echo "Failed parsing options." >&2 ; exit 1 ; fi | |
eval set -- "$OPTS" | |
MODE=full | |
while true; do | |
case "$1" in | |
-m | --mode ) | |
if [[ "$2" != 'full' && "$2" != 'only-behind' ]] | |
then | |
echo 'Valid options for -m / --mode: (full | only-behind)' | |
exit -1 | |
else | |
MODE="$2" | |
fi | |
shift; shift ;; | |
-- ) shift; break ;; | |
* ) break ;; | |
esac | |
done | |
echo 'Please wait...' | |
for dir in `ls -d */` | |
do | |
check_update "$dir" & | |
done | |
wait | |
cat $tempfile | sort | |
rm $tempfile |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
From line 46 to 49 could be:
find -type d -depth 1 -exec bash -c 'check_update "$0"' {} \;