Heat the oil in a frying pan, add the onions and fry gently for 10 minutes until soft and just beginning to colour. Add the garlic and sugar and fry for a further 5 minutes until golden. Take the pan off the heat, tear leaves from half the thyme over the onion and season with salt and pepper.
Roll the pastry out on a lightly floured surface and trim to a 15 × 30 cm (6 × 12 inch) rectangle, then cut into 5 cm (2 inch) squares. Transfer the squares to an oiled baking sheet, leaving a little space between them.
Brush the tops with beaten egg, then divide the onion mix between them. Cut each anchovy fillet into 2 thin strips and arrange 2 on each pastry square as a cross, then top with a halved olive.
Bake in a preheated oven, 200°C (400°F), Gas Mark 6, for 10–15 minutes until the pastry is well risen and golden. Brush the olives with a little extra oil, if liked, and sprinkle with the remaining thyme leaves. Serve warm or cold with drinks.