Travellers to the Rock will have to show their passport twice under a new UK-EU treaty.