#!/usr/bin/env bash # discover_git_repos — Encuentra todos los repos git dentro de root_dir. # Devuelve paths relativos (sin /.git) en stdout, uno por linea, ordenados. # Incluye el propio root_dir si tiene .git. Excluye node_modules, .venv, # cpp/vendor, cpp/build, sources, temp, subrepos e interior de .git. discover_git_repos() { local root_dir="${1:-.}" if [[ ! -d "$root_dir" ]]; then echo "discover_git_repos: directorio '$root_dir' no existe" >&2 return 1 fi # Normalizar: convertir a path absoluto para calculos consistentes local abs_root abs_root="$(cd "$root_dir" && pwd)" # Incluir el propio root si tiene .git local results=() if [[ -d "$abs_root/.git" ]]; then results+=("$abs_root") fi # Buscar .git en subdirectorios, con exclusiones. # Sin -type d: cubre tambien .git como archivo (submodulos + worktrees). while IFS= read -r git_path; do local repo_dir="${git_path%/.git}" results+=("$repo_dir") done < <(find "$abs_root" -mindepth 2 -name ".git" \ -not -path "*/.git/*" \ -not -path "*/node_modules/*" \ -not -path "*/.venv/*" \ -not -path "*/cpp/vendor/*" \ -not -path "*/cpp/build*/*" \ -not -path "*/sources/*" \ -not -path "*/temp/*" \ -not -path "*/subrepos/*" \ -not -path "*/emsdk/*" \ 2>/dev/null | sort) # Imprimir resultados ordenados (uno por linea) printf '%s\n' "${results[@]}" | sort } if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then discover_git_repos "$@" fi