NEW YORK (TheStreet) -- Oil had everyone on Wall Street excited on Tuesday. The commodity, bruised and battered for months by a supply-demand imbalance, extended gains in its longest rally since August and closed above $50 a barrel for the first time in a month. 

They took their time after a volatile start to the week but stocks finally noticed. The S&P 500 gained 1.4%, the Dow Jones Industrial Average added 1.8%, or 305 points, and the Nasdaq climbed 1%. The S&P 500 and Dow are just over 2% away from record highs.

STOCKS TO BUY: TheStreet Quant Ratings has identified a handful of stocks that can potentially TRIPLE in the next 12 months. Learn more.

West Texas Intermediate surged 6.9% to $52.98 a barrel as BP (BP joined several other oil companies in cutting capital expenditures in response to plunging oil prices. The oil giant said it would limit investment spending to $20 billion over 2015 from $22.9 billion in 2014. Earlier, China-based energy company CNOOC (CEO said it would cut capital spending by as much as 35% this year, while Chevron (CVX announced a 13% reduction to its capex budget.

But economists remain conflicted as to whether the stock market rally is one that can be sustained.

"There are competing narratives to explain the rally: bears chalk it up to a particularly violent short squeeze that will soon evaporate as the longer-term downtrend reasserts itself, while bulls point to the staggering drop in oil rig counts as a sign that supply is finally responding to the drop in price," said Matt Weller, senior technical analyst at FOREX.com.

Energy stocks lead stock market gains on Tuesday. Exxon Mobil (XOM was up 3%, PetroChina (PTR gained 3.1%, Total (TOT added 3.6%, and Schlumberger (SLB increased 2.9%. The Energy Select Sector SPDR ETF (XLE climbed 2.7%.

Solar stocks were partaking in the energy rally, too. First Solar (FSLR , SunPower (SPWR , JinkoSolar (JKS and Daqo New Energy  (DQ were all spiking. Canadian Solar (CSIQ was nearly 25% higher after striking a deal to buy solar developer Recurrent Energy from Sharp Corp. for $265 million. 

An energy rally fueled optimism across the board with all S&P 500 sectors closing the day higher. Among the best individual stock performers, Staples (SPLS shares rose 11.2% and Office Depot (ODP was up 21.5%. Earlier, The Wall Street Journal reported the companies were in discussions to merge.

Petrobras (PBR rallied more than 13%, partly due to rising oil prices but also on reports CEO Maria das Gracas Foster will resign soon in the face of the company's growing corruption investigation. Arch Coal (ACI surged 16.3% after reporting a narrower-than-expected quarterly loss. The coal miner decreased cost-per-ton expenses from a year earlier.

The surge in oil overshadowed weaker-than-expected domestic data out earlier in the morning. U.S. factory orders for December fell 3.4%, a larger drop than the 2.4% fall anticipated. A day earlier, the January ISM Index dropped to 53.5 compared to an expected reading of 54.1.

St. Louis Federal Reserve Bank President James Bullard said Tuesday that plunging oil prices had distorted inflation measures and to interpret them with a grain of salt until energy prices stabilize. Bullard reiterated his hawkish view that the central bank should raise rates sooner than later.

After the bell, Disney (DIS reported first-quarter profits of $1.27 a share, 20 cents better than expected. Revenue jumped nearly 9% as sales in its media networks climbed 11%. Shares climbed 2.8% in post-market trading.

Chipotle (CMG fell 6.1% in after-hours trading after the burrito chain guided for low- to mid-single-digit comparable restaurant sales over 2015. In its fourth quarter, comps rose 16.1%.

Take-Two Interactive (TTWO was up nearly 6% after reporting third-quarter profits of $1.87 a share, 35 cents above forecasts, and revenue up 24% from a year earlier.

--Written by Keris Alison Lahiff in New York.