Isometries of a product of Riemannian manifolds

Theorem. Let \((A, g_A)\) and \((B, g_B)\) be two compact Riemannian manifolds with irreducible holonomy groups. Let \((X, g):= (A \times B, g_A \oplus g_B)\). Then

\[ \operatorname{Isom}(X) = \begin{cases} \operatorname{Isom}(A) \times \operatorname{Isom}(B), \ \text{ if } A \text{ is not isometric to } B \\ \left ( \operatorname{Isom}(A) \times \operatorname{Isom}(B) \right ) \rtimes \mathbb{Z}/2\mathbb{Z}, \ \text{ otherwise } \end{cases} \]

This result seems to be a folklore, probably well known to the specialists, although it is hard to find it in the literature. The only discussion which I managed to find on Mathoverflow contains …