workspace-manager/.workspace-ops/shared/scripts/collect-subprojects.sh

95 lines
2.2 KiB
Bash
Executable file

#!/usr/bin/env bash
set -euo pipefail
ROOT="${1:-$(pwd)}"
if [[ "$ROOT" != "/" ]]; then
ROOT="${ROOT%/}"
fi
SINCE="${2:-}"
UNTIL="${3:-}"
EXCLUDES_FILE="$ROOT/.workspace-ops/config/target-excludes.txt"
if [[ -z "$SINCE" ]]; then
SINCE="$(date +%Y-%m-%d) 00:00"
fi
normalized_excludes() {
local exclude
[[ -f "$EXCLUDES_FILE" ]] || return 0
while IFS= read -r exclude || [[ -n "$exclude" ]]; do
exclude="${exclude%%#*}"
exclude="${exclude#"${exclude%%[![:space:]]*}"}"
exclude="${exclude%"${exclude##*[![:space:]]}"}"
exclude="${exclude#./}"
exclude="${exclude#/}"
exclude="${exclude%/}"
[[ -z "$exclude" ]] && continue
printf '%s\n' "$exclude"
done < "$EXCLUDES_FILE"
}
is_excluded_repo() {
local rel="$1"
local exclude
while IFS= read -r exclude; do
if [[ "$rel" == "$exclude" || "$rel" == "$exclude/"* ]]; then
return 0
fi
done < <(normalized_excludes)
return 1
}
repo_paths() {
local -a find_args=(
"$ROOT"
-path "$ROOT/.git" -prune -o
-path "$ROOT/.workspace-ops" -prune -o
-path "$ROOT/.tmp" -prune -o
-path "$ROOT/.antigravitycli" -prune -o
-path "*/.agent-cache" -prune -o
-path "*/node_modules" -prune -o
-path "*/build" -prune -o
-path "*/dist" -prune -o
-path "*/.dart_tool" -prune -o
-path "*/coverage" -prune -o
)
local exclude
while IFS= read -r exclude; do
find_args+=(-path "$ROOT/$exclude" -prune -o)
done < <(normalized_excludes)
find_args+=(-type d -name .git -print)
find "${find_args[@]}" |
sort |
while IFS= read -r gitdir; do
repo="$(dirname "$gitdir")"
rel="${repo#$ROOT/}"
if git -C "$ROOT" check-ignore -q -- "$rel" && ! is_excluded_repo "$rel"; then
printf '%s\n' "$repo"
fi
done
}
while IFS= read -r repo; do
rel="${repo#$ROOT/}"
echo "## $rel"
git -C "$repo" status --short --branch
git -C "$repo" branch -vv
if [[ -n "$UNTIL" ]]; then
git -C "$repo" log --since="$SINCE" --until="$UNTIL" --date=iso --pretty=format:'%h | %ad | %an | %s' --shortstat
else
git -C "$repo" log --since="$SINCE" --date=iso --pretty=format:'%h | %ad | %an | %s' --shortstat
fi
echo
done < <(repo_paths)