Situations like that is why we have fleet replenishment ships and practice UnRep (Underway Replenishment). Same reason the Air Force has Tanker aircraft, pretty much anyway.
Yep that's why they have the USNS fleet. You can refuel, load groceries, supplies, mail, and parts. We would go to sea six months doing this. All our fueling was at sea. We also had capabilities to refuel other ships in company if needed.