Last active
January 5, 2016 10:25
-
-
Save dccampbell/747de45e9aafca91e705 to your computer and use it in GitHub Desktop.
Scan the current sub-directories for git repositories, recursively, and return the git status for the working tree and all branches. Default max depth is 3. Ignores vendor and modman folders.
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
#!/usr/bin/env bash | |
basePath="$PWD" | |
baseDirs=$(find $basePath -mindepth 1 -maxdepth 1 -type d) | |
gitPaths=$(find $basePath -mindepth 1 -maxdepth ${1:-3} -name .git -type d -exec dirname {} \; | grep -v '/vendor/\|/.modman/') | |
unchangedDirs=() | |
for repo in $gitPaths; do | |
cd $repo | |
[[ "$2" = "-f" ]] && git fetch -q &>/dev/null | |
branch="on branch "$(git rev-parse --abbrev-ref=loose HEAD 2>/dev/null) | |
changedCount=$(git status -s | wc -l) | |
[[ $changedCount -gt 0 ]] && branch="$branch \e[0;31m[$changedCount working changes]\e[0m" | |
branches=$(git for-each-ref --format=' %(refname:short)...%(push:short) %(color:red)%(push:track)%(color:reset)' refs/heads) | |
[[ "$branch$branches" =~ "]" ]] && echo -e "$repo\n$branch\n$branches\n" || unchangedDirs+=("$repo") | |
gitDir=${repo#$basePath/} | |
baseDirs=$(printf "%s" "$baseDirs" | grep -v "${gitDir%%/*}") | |
done | |
cd $basePath | |
printf "\nNo Changes:\n" | |
printf "%s" "${unchangedDirs[*]}" | tr -s ' ' '\n' | |
printf "\n\nNon-Repo Directories:\n" | |
echo $baseDirs | tr -s ' ' '\n' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment