Fix shallow root maintenance during fetch by kcsaul · Pull Request #6846 · libgit2/libgit2
@ethomson - Could you please have another look at this?
I believe the memory leak you'd spotted was a knock-on impact of an existing test failing due to the fix. I've updated the online::shallow::shorten_four test to reflect what git does when fetching with depth 5, and then 4 afterwards. It doesn't actually remove the original set of shallow roots, presumably because they're not traversed on the server during the subsequent fetch. It's not until git gc is run the unreachable shallow roots are removed.
Now that I've realized where to add a new test - I've added one to prove existing shallow roots will be preserved during fetch for an unrelated branch, and that they'll be removed as expected during subsequent fetches.
Outstanding/failing test appears to be one of the flaky network tests.