Suppose that $G_1$, $G_2$, $H_1$ and $H_2$ are non-trivial groups. Under what conditions do we have $$G_1 \ast H_1 \cong G_2 \ast H_2?$$
Is it the case that if $G_1 \cong G_2$ then we only have such an isomorphism if $H_1 \cong H_2$?
This may be quite a wide and complicated question, so if a full answer is difficult, I'm most interested in the following two cases:
1) $G_1 \cong G_2$ and $H_1$, $H_2$ are both finite.
2) $G_1 \cong G_2$ and $H_1$, $H_2$ are both free.