The above command will fail when the git tag is a hash, but it will succeed when the git tag is a branch. Cmake should be smart to detect that the tag is a hash and turn off git shallow automatically.
Indeed; CMake has no idea how Git might interpret any given string. We might be able to guess, but it is better for this to be something specified at the call site directly.