Green’s Dictionary of Slang

sugar! excl.

1. a cry of exultation after a victory, supposedly given as one stands on one leg and waves the other about.

[UK] ‘Firing Up The Chimney’ in Lummy Chaunter 80: Then Molly ask’d Jemmy his pistol to fire, [...] Up her foul flue and bring down the mire / With her heighho! / ’Twould be a rare go. / Sugar! sugar!
[US]H.L. Williams Ticket-of-Leave Man 15: While Mrs. Miles performs a very original pas seul, her liege lord expresses his extactic admiration by various ejaculations, and repeats the word ‘sugar’ with great emphasis.

2. (also sugar me!) a euph. for shit! excl. or bugger! excl.

[UK] ‘Midnight Mishaps’ in Bentley’s Misc. Aug. 203: Sugar me! You’re just agoing it nicely!
[US]‘Ned Buntline’ Mysteries and Miseries of N.Y. I 39: Oh – sugar, you know what I’m used to, what the deuce do you want to make out as if I was an angel for?
San Antono Light (TX) 24 Nov. 1/3: The usual exclamation of ‘sugar!’ or something similar, from a hundred disgusted theological students.
[Aus]Sydney Sportsman (Surry Hills, NSW) 4 May 3/5: But sugar me if it [i.e. local rainfall] could beat Sydney’s record for the last three weeks.
[US]G.W. Peck Peck’s Bad Boy Abroad 453: Oh, sugar, no; you don’t need to go.
[US]C. McKay Gingertown 15: ‘Oh, shucks and sugar!’ he said.
[Aus]West Australian (Perth) 21 Aug. 5/5: ‘Aw, sugar!’ put in Tinny.
[NZ]B. Mason Awatea (1978) 30: What’s he blown a safe for? Oh, sugar.
[Aus]N. Keesing Lily on the Dustbin 24: She would never have said ‘Shit!’. She might have said ‘shite’, however which was considered allowable, or ‘sugar’ which was a widespread substitute.
[Ire]T. Delaney Where We Sported and Played 82: Sugar, now I’m rightly stuck.
[UK]T. Blacker Kill Your Darlings 61: ‘Oh sugar.’ My wife sighed.

In phrases

sugar, cock your legs and cry

(UK Und.) an excl. of triumph or delight, accompanied by standing on one leg, cocking up the other and shouting ‘Sugar!’ .

[UK]Swell’s Night Guide 133/1: Sugar, cock your legs and cry, a way of expressing triumph or joy, by standing on one leg and shaking the other up, hooting ‘sugar’ loudly.