Detect repo more reliably