I've done a fair number of technical due diligence projects on acquisitions and potential partnerships, and on some project I've hired outside firms to analyze the code and figure out its origins and what licenses apply.
There are tools that will analyze a codebase and identify where chunks of varying size seem to come from. Mostly to determine if the code is encumbered by problematic licenses, but also to detect where the programmers may have borrowed code from.
If memory serves, some of these companies also have closed source codebases in their database, enabling them to detect if unpublished code has been re-used.
The times I've used this in due diligence it has rarely been a deal-breaker when we do find large chunks of code that may be problematic. For instance due to licensing terms that are not acceptable. You just make a note of it and have them rewrite the code before the transaction can take place. (Or you figure out if you can accomodate the license terms).