build: fix git prereq check to not rely on being in a git directory (#21968)