Fix submodule sort order during iteration

It turns out that #2205 introduced a bug where submodules were being sorted as if their name ended in a `/`. The name was fixed before the actual comparison was done, but the ordering was incorrect, so if you had a submodule named `foo` and a file named `foo-bar` the submodule was being processed after the file instead of before.

Before the PR, the iterator code checked if each "current" item was a submodule right before returning it and fixed up the `stat` data and path as needed. This is too late to ensure correct sorting.

This PR moves the submodule checks to the point where the whole directory is "entered." Upon entering a directory, now the iterator will identify all submodules, update their names (i.e. strip the trailing `/`), and re-sort the entries as needed.

Previously these checks were effectively being done in the code that #2205 eliminated, but in a way that was overly broad.