Skip to content

Commit

Permalink
bash(feat): add git_check function
Browse files Browse the repository at this point in the history
  • Loading branch information
davidsneighbour committed Dec 18, 2024
1 parent a6f5009 commit 454b2f3
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions bash/_functions/git_check
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
function git_check() {
if [[ "$1" == "--help" ]]; then
echo "Usage: ${FUNCNAME[0]}"
echo
echo "Recursively scans the current directory for Git repositories,"
echo "checks if they are clean, and lists changes in dirty repositories."
return 0
fi
scan_directories() {
local base_dir="$1"

for dir in "${base_dir}"/*; do
if [[ -d "${dir}" ]]; then
if [[ -d "${dir}/.git" ]]; then
cd "${dir}" || continue
# Check if the repository is clean
if ! git diff --quiet || ! git diff --cached --quiet; then
echo "Dirty Git repository found: ${dir}"
echo "Changes:"
git status --short
echo "---------------------------------"
fi
cd - > /dev/null || continue
fi
scan_directories "${dir}"
fi
done
}
scan_directories "$(pwd)"
}

0 comments on commit 454b2f3

Please sign in to comment.