scripts: do more check before a git rev-parse
scripts: do more check before a git rev-parse

Handle the situation that the source tree does not contain .git .
Fix error: 'Fatal: Not a git repository'.

jinghaomiao/apollo,xiaoxq/apollo,jinghaomiao/apollo,wanglei828/apollo,ApolloAuto/apollo,wanglei828/apollo,ApolloAuto/apollo,ycool/apollo,xiaoxq/apollo,xiaoxq/apollo,ApolloAuto/apollo,ycool/apollo,ApolloAuto/apollo,wanglei828/apollo,xiaoxq/apollo,wanglei828/apollo,ycool/apollo,wanglei828/apollo,xiaoxq/apollo,jinghaomiao/apollo,ycool/apollo,jinghaomiao/apollo,jinghaomiao/apollo,ApolloAuto/apollo,wanglei828/apollo,xiaoxq/apollo,ycool/apollo,jinghaomiao/apollo,ycool/apollo,ApolloAuto/apollo