Paul speaks of how “those [God] foreknew he also predestined to be conformed to the image of His Son” (Rm. 8:29). If God foreknew and predestined anyone, surely He foreknew and predestined Mary. Which means that God foreknew the whole genealogy that Mary emerges from, given to us in detail in the gospel. Moreover, the genealogy God willed Mary to come from is likewise the genealogy God willed His Son to come from. This messy history, full of blasphemers, adulterers, and idolaters, is part of the human history of His Son.
To be conformed to the image of Christ is a spiritual reality, but we should never think that the messiness of our worldly existence prevents us from being like Jesus. All of us have stories, some messier than others, but all very human. We have personal histories we may not be proud of, or we may have family histories that make us blush. But this does not keep us from being like Mary or Jesus. God foreknew Mary’s family history, and yet He predestined her to be the mother of His Son, and our mother. God foreknew our own histories, both family and personal, and yet He has called us to holiness.