Nightly build only on git changes

Is there a simple way to NOT perform nightly builds if nothing has been checked into the git repo since the last build? I’m presently running this step to avoid a useless build

r=git log --name-only --since="1 day ago" -n 2; if [ “x$r” == “x” ]; then echo “No. Exiting.”; exit -1; else echo “Yes.”; fi

but it of course results in a “Failure” instead of “Success”(-ful non-execution).

This is similar to the closed topic Build only when folder is changed

Thanks in advance for any suggestions.