I would use repository.getWorktree(). That leads you directly to the directory you want (without the getParentFile()). It would also throw an appropriate exception instead of displaying wrong data when called on a bare repo.