Skip to content

Instantly share code, notes, and snippets.

@metalelf0
Created May 14, 2018 07:25
Show Gist options
  • Save metalelf0/98cd1c8a833bbe85e48004114691e221 to your computer and use it in GitHub Desktop.
Save metalelf0/98cd1c8a833bbe85e48004114691e221 to your computer and use it in GitHub Desktop.
Recursively check subdirectories to see git repos with pending changes
#!/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
@gcimmino
Copy link

From line 46 to 49 could be:

find -type d -depth 1 -exec bash -c 'check_update "$0"' {} \;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment