#!/usr/bin/env bash set -euo pipefail # cleanup.sh - Commits, pushes, and prunes LFS files. # # - Detects *untracked* files (git status --porcelain), so we don’t 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 if [ "$#" -ne 1 ]; then echo "Usage: $0 " >&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."