It turns out that tree.compare_trees() never compares directory hashes when comparing two directories; it only compares their children. Also, the merge_attributes() function is old cruft, and is screwing up the directory hashes anyway in certain cases. I have a patch in progress to fix this, but it might reveal other bugs, i.e. tests that we thought were passing, but aren't. I'll be tracking this down this week.