Validate if its a git repository or not before triggering git commands.

closes #2883