Spain is threatening to oppose a deal on Britain’s withdrawal from the European Union unless it gets assurances over the disputed peninsula of Gibraltar.