This patch series fixes issue2499. MQ currently allows managed patches to include changes to .hgsub and .hgsubstate, which allows you to royally mess up the subrepo state (as demonstrated in the test script attached to the bug report).