Last active
January 30, 2024 15:46
-
-
Save pjbgf/45048d8e3688fc070c7667f4b8f10374 to your computer and use it in GitHub Desktop.
Check for local changes in any git repositories under the current working dir
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/bash | |
set -eo pipefail | |
VERBOSE="${VERBOSE:-false}" | |
dirs=$(find -mindepth 1 -maxdepth 10 -type d -name .git) | |
for dir in $dirs; do | |
dir=$(dirname $dir) | |
pushd "$dir" > /dev/null | |
prefix="⚠️" | |
if [[ "${VERBOSE}" == "true" ]]; then | |
echo "Checking Git repository in $dir:" | |
else | |
prefix="$dir:" | |
fi | |
# Check for unpushed commits | |
if [[ $(git log --branches --not --remotes) ]]; then | |
echo "${prefix} Unpushed commits ahead of remote!" | |
fi | |
# Check for dirty worktree | |
if [[ `git status --porcelain` ]]; then | |
echo "${prefix} Uncommitted changes in worktree!" | |
fi | |
popd > /dev/null | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment