Buckets:

glennmatlin's picture
download
raw
2.8 kB
#!/usr/bin/env bash
set -euo pipefail
ZERO_SHA="0000000000000000000000000000000000000000"
ROOT="$(git rev-parse --show-toplevel)"
TMP_DIR="$(mktemp -d "${TMPDIR:-/tmp}/sda-pre-push.XXXXXX")"
cleanup() {
rm -rf "$TMP_DIR"
}
trap cleanup EXIT
cd "$ROOT"
select_base_for_new_ref() {
local local_sha="$1"
if git rev-parse --verify -q origin/main >/dev/null; then
git merge-base origin/main "$local_sha"
return
fi
git rev-parse --verify "$local_sha^" 2>/dev/null
}
run_ruff() {
if command -v uv >/dev/null 2>&1; then
uv run --no-sync ruff "$@"
return
fi
if [ -x "$ROOT/.venv/bin/ruff" ]; then
"$ROOT/.venv/bin/ruff" "$@"
return
fi
if command -v ruff >/dev/null 2>&1; then
ruff "$@"
return
fi
echo "pre-push: ruff is not available. Run scripts/bootstrap/setup_worktree.sh or install ruff." >&2
return 1
}
check_ref() {
local local_ref="$1"
local local_sha="$2"
local remote_ref="$3"
local remote_sha="$4"
local base="$remote_sha"
local python_files="$TMP_DIR/python-files"
local files=()
local file
if [ "$local_sha" = "$ZERO_SHA" ]; then
echo "pre-push: skipping delete of $remote_ref"
return 0
fi
if [ "$remote_sha" = "$ZERO_SHA" ] || ! git cat-file -e "$remote_sha^{commit}" 2>/dev/null; then
base="$(select_base_for_new_ref "$local_sha")"
fi
if [ -z "$base" ]; then
echo "pre-push: could not determine comparison base for $local_ref" >&2
return 1
fi
echo "pre-push: checking whitespace for $local_ref"
git diff --check "$base" "$local_sha" --
git diff --name-only -z --diff-filter=AM "$base" "$local_sha" -- "*.py" >"$python_files"
if [ ! -s "$python_files" ]; then
echo "pre-push: no Python files changed for $local_ref"
return 0
fi
while IFS= read -r -d "" file; do
files+=("$file")
done <"$python_files"
echo "pre-push: running ruff check for $local_ref"
run_ruff check -- "${files[@]}"
echo "pre-push: running ruff format --check for $local_ref"
run_ruff format --check -- "${files[@]}"
}
if [ -t 0 ]; then
current_ref="$(git symbolic-ref -q HEAD || echo HEAD)"
current_sha="$(git rev-parse HEAD)"
upstream_ref="$(git for-each-ref --format="%(upstream:short)" "$current_ref")"
upstream_sha="$ZERO_SHA"
if [ -n "$upstream_ref" ] && git rev-parse --verify -q "$upstream_ref" >/dev/null; then
upstream_sha="$(git rev-parse "$upstream_ref")"
fi
check_ref "$current_ref" "$current_sha" "$upstream_ref" "$upstream_sha"
else
while read -r local_ref local_sha remote_ref remote_sha; do
check_ref "$local_ref" "$local_sha" "$remote_ref" "$remote_sha"
done
fi

Xet Storage Details

Size:
2.8 kB
·
Xet hash:
6e7cea1d1edba680dd94483f70348eabb369a1e0937d9afe7dda4ecc5aae053a

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.