fix: stop correctly when MAX_COMMITS_TO_CHECK is reached
All checks were successful
Validate Trusted Timestamps Actions Demo / Validate (push) Successful in 11m40s

This commit is contained in:
Phil Davis
2025-06-02 14:32:23 +05:45
parent 31e44f9b70
commit 8aba6e98d1

View File

@@ -311,6 +311,11 @@ validate_commit() {
# param1: commit hash # param1: commit hash
# returns: 0 if the validation of the commit and all its ancestors succeeded # returns: 0 if the validation of the commit and all its ancestors succeeded
validate_commit_and_parents() { validate_commit_and_parents() {
NUM_COMMITS_CHECKED=${#PROCESSED_COMMIT[@]}
if [[ ${NUM_COMMITS_CHECKED} -ge ${MAX_COMMITS_TO_CHECK} ]] && [[ ${MAX_COMMITS_TO_CHECK} -ge 1 ]]; then
# enough commits have already been checked, so return early
return 0;
fi
local COMMIT_HASH="$1" local COMMIT_HASH="$1"
log "validate_commit_and_parents for $COMMIT_HASH" log "validate_commit_and_parents for $COMMIT_HASH"
@@ -321,7 +326,6 @@ validate_commit_and_parents() {
# If MAX_COMMITS_TO_CHECK is zero (or a negative number) then that is understood as "infinity". # If MAX_COMMITS_TO_CHECK is zero (or a negative number) then that is understood as "infinity".
# So perform the next commit check if we have not reached the limit, or if the limit is "infinity". # So perform the next commit check if we have not reached the limit, or if the limit is "infinity".
NUM_COMMITS_CHECKED=${#PROCESSED_COMMIT[@]} NUM_COMMITS_CHECKED=${#PROCESSED_COMMIT[@]}
if [[ ${NUM_COMMITS_CHECKED} -lt ${MAX_COMMITS_TO_CHECK} ]] || [[ ${MAX_COMMITS_TO_CHECK} -lt 1 ]]; then
local PARENTS=$(git cat-file -p "$COMMIT_HASH" | awk '/^$/{exit} /parent/ {print}' | sed 's/parent //') local PARENTS=$(git cat-file -p "$COMMIT_HASH" | awk '/^$/{exit} /parent/ {print}' | sed 's/parent //')
#iterate over all parents of commit #iterate over all parents of commit
if [ ! -z "$PARENTS" ]; then if [ ! -z "$PARENTS" ]; then
@@ -331,7 +335,6 @@ validate_commit_and_parents() {
fi fi
done <<< $(printf "%s" "$PARENTS") done <<< $(printf "%s" "$PARENTS")
fi fi
fi
if [ "$ALL_PASSED" = true ]; then if [ "$ALL_PASSED" = true ]; then
return 0 return 0
fi fi