From 454b2f3d8f8a846a68a837958e2089ab70da73ee Mon Sep 17 00:00:00 2001 From: Patrick Kollitsch Date: Wed, 18 Dec 2024 10:14:14 +0700 Subject: [PATCH] bash(feat): add git_check function --- bash/_functions/git_check | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 bash/_functions/git_check diff --git a/bash/_functions/git_check b/bash/_functions/git_check new file mode 100644 index 00000000..70160df3 --- /dev/null +++ b/bash/_functions/git_check @@ -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)" +} +