From d78c6111b6d742318b2e4a675c6aa443832f1666 Mon Sep 17 00:00:00 2001 From: Ian Duffy Date: Tue, 9 Jun 2026 10:51:56 +0100 Subject: [PATCH] fix: converge pre-commit before commit and never push an aborted commit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit update-bindings.sh ran `git commit` with the ruff pre-commit hook active. When ruff auto-fixed files it modified the tree and aborted the commit, but the script pushed the branch anyway — leaving the remote branch pointing at the same commit as master with the regenerated changes uncommitted. - Add run_precommit_to_convergence(): run pre-commit, re-staging and retrying until it passes (max 5 attempts) so auto-fixes are captured before commit. - Guard `git commit`: if it fails (e.g. a hook aborts it), log and exit instead of falling through to `git push`. Co-Authored-By: Claude Opus 4.8 (1M context) --- scripts/update-bindings.sh | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/scripts/update-bindings.sh b/scripts/update-bindings.sh index 87513869..8ffef4d6 100755 --- a/scripts/update-bindings.sh +++ b/scripts/update-bindings.sh @@ -144,6 +144,30 @@ generate_bindings() { fi } +run_precommit_to_convergence() { + if ! command -v pre-commit &> /dev/null; then + log_warning "pre-commit not found; skipping explicit hook run (the git commit hook, if installed, will still run)" + return 0 + fi + + log_info "Running pre-commit hooks to convergence before committing..." + + local attempt=1 + local max_attempts=5 + while ! pre-commit run --all-files; do + git add . + if [ "$attempt" -ge "$max_attempts" ]; then + log_error "pre-commit hooks did not converge after $max_attempts attempts; aborting before commit" + exit 1 + fi + attempt=$((attempt + 1)) + log_warning "pre-commit modified files; re-staging and retrying (attempt $attempt)..." + done + + git add . + log_success "pre-commit hooks passed" +} + create_and_push_branch() { local version="$1" local api_version="$2" @@ -180,15 +204,20 @@ create_and_push_branch() { return 1 fi - git commit -m "Update API bindings to version $version + run_precommit_to_convergence + + if ! git commit -m "Update API bindings to version $version Binding version: $version CloudSmith API version: $api_version - Updated package_version in scripts/common.sh - Regenerated bindings for Python, Ruby, and Java -- Ready for automated deployment via CircleCI" - +- Ready for automated deployment via CircleCI"; then + log_error "git commit failed (a pre-commit hook may have aborted it). Not pushing branch $branch_name." + exit 1 + fi + log_info "Pushing branch to origin..." if ! git push origin "$branch_name"; then log_warning "Normal push failed, trying force push..."