Heat olive oil in a large pot or Dutch oven over medium heat. Add onions and cook, stirring occasionally, until caramelized and golden brown, about 30-40 minutes. Add sugar, salt, and pepper during the last 10 minutes of cooking.
Deglaze the pot with sherry or white wine, scraping up any browned bits from the bottom. Cook for 2-3 minutes until the alcohol evaporates.
Add beef broth and bay leaves. Bring to a boil, then reduce heat and simmer for 20-30 minutes to allow the flavors to meld.
Preheat broiler. Place soup in oven-safe bowls. Top each bowl with a slice of baguette and a generous amount of Gruyère cheese.
Broil for 2-3 minutes, or until the cheese is melted and bubbly. Serve immediately.