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) - Get BP p.l.c. Sponsored ADR Report 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) - Get CNOOC Limited Sponsored ADR Report said it would cut capital spending by as much as 35% this year, while Chevron (CVX) - Get Chevron Corporation Report 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) - Get Exxon Mobil Corporation Report was up 3%, PetroChina (PTR) - Get PetroChina Company Limited Sponsored ADR Report gained 3.1%, Total (TOT) - Get Total SA Sponsored ADR Class B Report added 3.6%, and Schlumberger (SLB) - Get Schlumberger NV Report increased 2.9%. The Energy Select Sector SPDR ETF (XLE) - Get Energy Select Sector SPDR Fund Report climbed 2.7%.

TheStreet Recommends

Solar stocks were partaking in the energy rally, too. First Solar (FSLR) - Get First Solar, Inc. Report , SunPower (SPWR) - Get SunPower Corporation Report , JinkoSolar (JKS) - Get JinkoSolar Holding Co., Ltd. Sponsored ADR Report and Daqo New Energy (DQ) - Get Daqo New Energy Corp. Sponsored ADR Report were all spiking. Canadian Solar (CSIQ) - Get Canadian Solar Inc. Report 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) - Get ODP CORPORATION Report was up 21.5%. Earlier, The Wall Street Journal reported the companies were in discussions to merge.

Petrobras (PBR) - Get Petroleo Brasileiro SA Sponsored ADR Report 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) - Get Albertsons Cos. Inc. Report 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) - Get Walt Disney Company Report 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) - Get Chipotle Mexican Grill, Inc. Report 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) - Get Take-Two Interactive Software, Inc. Report 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.