Files
scst/scripts/source/clean-source-tree
Gleb Chesnokov 88b5653b06 scripts: Group source maintenance helpers under source/
Keep source inventory, cleanup and shell lint helpers together. Update the
Makefile, Debian packaging, scstadmin and the kernel, release and existing
checkpatch callers in the same commit so each consumer uses a valid path.

Keep run-shellcheck rooted at scripts/ after the move, preserving its
coverage of all tracked Bash helpers. Source selection and the existing
checkpatch exclusions are unchanged.
2026-10-19 10:31:32 +03:00

52 lines
904 B
Bash
Executable File

#!/usr/bin/env bash
shopt -s nullglob
usage() {
echo "Usage: $(basename "$0") [ -x <exclude> ]*"
exit 1
}
remove_empty_directories() {
find . -depth -type d |
sed 's|^\./||' |
grep -Ev '^\.$|^\.git/|^\.git$' |
while read -r d; do
for f in "$d"/{*,.*}; do
if ! [ -e "$f" ]; then
rmdir "$d"
fi
break
done
done
}
git_options=(-e TAGS)
while [ "${1#-}" != "$1" ]; do
case "$1" in
-x)
git_options+=(-e "$2")
shift; shift;;
*)
usage;;
esac
done
for d in "${@-.}"; do
(
if cd "$d"; then
if [ -e .git ] || [ -e ../.git ]; then
if ! type -p git >&/dev/null; then
echo "$0: git: not found."
exit 0
fi
git clean -f -d -x "${git_options[@]}" >/dev/null
remove_empty_directories
else
echo "$0: $d: not administered by Git."
fi
fi
)
done