Files
llm-registry/tools/cleanup.sh
2025-09-27 18:26:34 +01:00

50 lines
1.4 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env bash
set -euo pipefail
# cleanup.sh - Commits, pushes, and prunes LFS files.
#
# - Detects *untracked* files (git status --porcelain), so we dont skip commits.
# - Uses 'git add --renormalize .' so new/changed .gitattributes rules convert
# existing files into LFS pointers on re-add.
# - Keeps the prune step to free local disk space after a successful push.
#
# Usage: ./tools/cleanup.sh <commit-message>
if [ "$#" -ne 1 ]; then
echo "Usage: $0 <commit-message>" >&2
exit 1
fi
COMMIT_MESSAGE="$1"
# Detect any changes, including untracked.
if [[ -z "$(git status --porcelain=v1)" ]]; then
echo "No new files or changes to commit. Skipping commit and push."
exit 0
fi
echo "Committing and pushing changes..."
# Make sure .gitattributes changes are included and normalization runs,
# so LFS filters rewrite eligible files as pointers.
git add .gitattributes || true
git add --renormalize .
# If nothing ended up staged (e.g. only ignored files changed), exit gracefully.
if git diff --cached --quiet; then
echo "No staged changes after normalization. Skipping commit and push."
exit 0
fi
git commit -m "$COMMIT_MESSAGE"
git push
# Optional but useful: ensure all LFS objects are on the remote.
# Uncomment if you want belt-and-suspenders uploads.
# git lfs push origin --all
echo "Pruning local LFS files..."
git lfs prune --force
echo "✅ Cleanup complete."