#! /bin/bash

if [ -z "$1" ]
then
    echo "find_remote_build.sh branch_name"
    exit 1
fi

for git_hash in $(git log $1 -n250 --format=format:"%H")
do
    aws_hash_resp=$(aws s3 ls s3://zoox-builds/v2/$git_hash/)
    if [ $? -eq 0 ]; then
        echo "most recent remote build on $1: $git_hash"
        exit 0
    fi
done

echo "Could not find any remote builds within 250 commits of $1."
exit 2