#!/usr/bin/env bash # Deploy the current commit to the Hugging Face Space (git remote "space"). # # Hugging Face rejects binary files committed directly to git, so this pushes a # deploy commit with the same code minus docs/ (images), on top of the Space's # current history. GitHub history is left untouched. set -euo pipefail cd "$(git rev-parse --show-toplevel)" if [ -n "$(git status --porcelain)" ]; then echo "Commit your changes first." >&2 exit 1 fi git fetch -q space idx="$(mktemp)" GIT_INDEX_FILE="$idx" git read-tree HEAD GIT_INDEX_FILE="$idx" git rm -q --cached -r --ignore-unmatch docs tree="$(GIT_INDEX_FILE="$idx" git write-tree)" rm -f "$idx" msg="Deploy $(git rev-parse --short HEAD): $(git log -1 --format=%s)" commit="$(git commit-tree "$tree" -p space/main -m "$msg")" git push space "${commit}:refs/heads/main" echo "Deployed $(git rev-parse --short HEAD) to the Space as ${commit:0:7}."