Urinary catheters are less common during surgery than a generation ago, especially in shorter outpatient cases. These are days of cost-benefit analysis, risk management, and time optimization: inserting a Foley catheter takes a few extra minutes and carries some (low) risk of infection, hence is avoided for most kinds of surgery. Patients are often asked to void prior to transport to the O.R.
Under general anesthesia most people don’t normally lose bladder control, just as they don’t with normal sleep, either. If the bladder becomes full, however, there is an automatic voiding reflex that might kick in—without the conscious, voluntary sphincter tightening that you can do when awake.
So sometimes non-catheterized surgical patients urinate under anesthesia, either due to bladder overflow or due to coughing. The OR staff, in short order, mop up the mess and dry the patient’s skin—a procedure they’ve had to do numerous times before. Nobody says anything (it might be noted on a form somewhere in the records) because even though it’s a normal body function it might, nonetheless, cause unnecessary embarrassment to the patient if they knew, and a professional hospital staff will try to protect your modesty and dignity.
Less common, but also not rare, is—to use a term of the trade—“code brown.” Once again, the less said the better. Also, undergarments may have to be removed for a variety of reasons after you’re asleep, but then they would be returned to you in a plastic bag—unless they were hopelessly soiled or treated as some kind of bio-hazard lol.
@ilvorangeiceblocks: You said “makeshift” underwear, which makes me think disposable? When you say “go toilet” and “soil myself” I’m not sure if you mean urine or feces?
I think @john65pennington nailed it: A seven hour surgery is a long time not to hit the potty. I would guess that they catheterized you at the start of your long operation, removing & discarding underpants, then removed the catheter at the end of surgery. If you had the urge to defecate before surgery (common when apprehensive) then narcotics and other drugs during & after surgery might temporarily suppress this urge.