In this patch, foreach --recursive acts depth-first, much like the default behavior described in the patch by Imram Yousuf in this post <http://marc.info/?l=git&m=121066084508631&w=2>. Changes were made so that the submodule "Entering ..." message was right next to the output generated by the command too. It also adds the --parent option for executing the command in the supermodule as well.
I began by adding a --depth option, to preserve the original --recursive behavior, and the --parent option, and trying to get that to work. However, I pretty much confused myself for a while trying to straighten that out, so I just ended up modifying the --recursive behavior. If the --recursive behavior should be preserved, I could add the --depth option back and only have --parent affect non-recursive and --depth recursive behavior. I had kind-of implemented this behavior with aliases / bash functions (posted to pastebin <http://pastebin.com/yLHe9XWy> , spurned by a question I asked in StackOverflow <http://stackoverflow.com/q/14846967/170413>), however I would always run into issues with escaping characters when passing from the bash functions to git aliases (i.e., putting "'ello" as an test commit message). I also tried out mb14's method from the StackOverflow post, but I ran into the same issues. Figured the best way to avoid that was to cut out the extra layers. I've attached a test script to generate the tree that VonC suggested with output showing the iteration.
Description: Binary data
Description: Bourne shell script