Download git-hooks/pre-push from Vishvam10/cloudenv: direct link, hf CLI and curl.
- Browser
- Download file 1.35 kB
-
https://huggingface.co/spaces/Vishvam10/cloudenv/resolve/main/git-hooks/pre-push
- Command line
-
hf download hf://spaces/Vishvam10/cloudenv/git-hooks/pre-push
-
curl -L -o pre-push https://huggingface.co/spaces/Vishvam10/cloudenv/resolve/main/git-hooks/pre-push
1.35 kB
| #!/bin/bash | |
| printf "\nRunning pre-push hook\n" >&2 | |
| current_branch=$(git rev-parse --abbrev-ref HEAD) | |
| # Prevent push if the branch is 'main' or 'master' | |
| if [[ "$current_branch" == "main" || "$current_branch" == "master" ]]; then | |
| echo "🔴 Pushing to '$current_branch' is not allowed!" | |
| echo "Please use a feature branch and open a pull request." | |
| exit 1 | |
| fi | |
| echo "Running Ruff linter and applying fixes ..." | |
| echo "Checking code quality ..." | |
| ruff check --config pyproject.toml | |
| if [[ $? -ne 0 ]]; then | |
| printf "\n🔴 Pre-commit hook failed due to Ruff linter errors.\n" | |
| exit 1 | |
| fi | |
| # Apply safe fixes | |
| echo "Applying safe fixes ..." | |
| ruff check --fix --config pyproject.toml | |
| if [[ $? -ne 0 ]]; then | |
| printf "\n🔴 Pre-commit hook failed while applying fixes.\n" | |
| exit 1 | |
| fi | |
| echo "Applying Ruff import sort ..." | |
| ruff_output=$(ruff check --select I --fix . --config pyproject.toml 2>&1) | |
| ruff_exit=$? | |
| echo "$ruff_output" | |
| if [[ $ruff_exit -ne 0 ]] || echo "$ruff_output" | grep -Ei "fixed|error" > /dev/null; then | |
| echo "\n🔴 Pre-commit hook failed while applying import sort\n" | |
| exit 1 | |
| fi | |
| echo "Applying Ruff formatting ..." | |
| ruff format --config pyproject.toml | |
| if [[ $? -ne 0 ]]; then | |
| printf "\n🔴 Pre-commit hook failed while applying formatting.\n" | |
| exit 1 | |
| fi | |
| printf "\n🟢 Pre-push checks passed !\n" | |
| exit 0 |