1

I have a Git super project with many submodules. I'd like to be able to go through the submodules and run git status so that I can quickly see which branch each submodule is on and whether there are uncommitted changes. However when I run git submodule foreach 'git status' it is difficult to parse and I can't tell which submodule it's reporting the status for. It appears to just spew out my %PATH% variable (I'm using msysGit on Windows). My output appears similar to that shown here:

Entering 'C:\Program Files\Git/libexec/git-core;C:\Program Files\Git\libexec\git-core;C:\Program Files\Git\libexec\git-core;C:\Program Files\Git\bin;c:\Documents and Settings\username\My Documents\LinuxHome\bin;.;C:\Program Files\Git\local\bin;C:\Program Files\Git\mingw\bin;C:\Program Files\Git\bin;c:\WINDOWS\system32;c:\WINDOWS;c:\WINDOWS\System32\Wbem;c:\WINDOWS\system32\WindowsPowerShell\v1.0;c:\WINDOWS\system32\WindowsPowerShell\v1.0;c:\Program Files\Intel\WiFi\bin\;c:\Program Files\Windows Imaging\;c:\Program Files\Microsoft SQL Server\100\Tools\Binn\;c:\Program Files\Microsoft SQL Server\100\DTS\Binn\;c:\Program Files\TortoiseSVN\bin'
# On branch My_Branch
nothing to commit (working directory clean)
Entering 'C:\Program Files\Git/libexec/git-core;C:\Program Files\Git\libexec\git-core;C:\Program Files\Git\libexec\git-core;C:\Program Files\Git\bin;c:\Documents and Settings\username\My Documents\LinuxHome\bin;.;C:\Program Files\Git\local\bin;C:\Program Files\Git\mingw\bin;C:\Program Files\Git\bin;c:\WINDOWS\system32;c:\WINDOWS;c:\WINDOWS\System32\Wbem;c:\WINDOWS\system32\WindowsPowerShell\v1.0;c:\WINDOWS\system32\WindowsPowerShell\v1.0;c:\Program Files\Intel\WiFi\bin\;c:\Program Files\Windows Imaging\;c:\Program Files\Microsoft SQL Server\100\Tools\Binn\;c:\Program Files\Microsoft SQL Server\100\DTS\Binn\;c:\Program Files\TortoiseSVN\bin'
# On branch My_Branch
# Your branch is ahead of 'FlashDrive/My_Branch' by 10 commits.
#
nothing to commit (working directory clean)
Entering 'C:\Program Files\Git/libexec/git-core;C:\Program Files\Git\libexec\git-core;C:\Program Files\Git\libexec\git-core;C:\Program Files\Git\bin;c:\Documents and Settings\username\My Documents\LinuxHome\bin;.;C:\Program Files\Git\local\bin;C:\Program Files\Git\mingw\bin;C:\Program Files\Git\bin;c:\WINDOWS\system32;c:\WINDOWS;c:\WINDOWS\System32\Wbem;c:\WINDOWS\system32\WindowsPowerShell\v1.0;c:\WINDOWS\system32\WindowsPowerShell\v1.0;c:\Program Files\Intel\WiFi\bin\;c:\Program Files\Windows Imaging\;c:\Program Files\Microsoft SQL Server\100\Tools\Binn\;c:\Program Files\Microsoft SQL Server\100\DTS\Binn\;c:\Program Files\TortoiseSVN\bin'
# On branch My_Branch
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#   modified:   MyApp/Win32/Release/MyApp.exe
#   modified:   MyApp/WinCe600 (ARMV4I)/Release/MyApp.exe
#   modified:   MyApp/WinCe600 (ARMV4I)/Release/Startup.exe
#
no changes added to commit (use "git add" and/or "git commit -a")
Entering 'C:\Program Files\Git/libexec/git-core;C:\Program Files\Git\libexec\git-core;C:\Program Files\Git\libexec\git-core;C:\Program Files\Git\bin;c:\Documents and Settings\username\My Documents\LinuxHome\bin;.;C:\Program Files\Git\local\bin;C:\Program Files\Git\mingw\bin;C:\Program Files\Git\bin;c:\WINDOWS\system32;c:\WINDOWS;c:\WINDOWS\System32\Wbem;c:\WINDOWS\system32\WindowsPowerShell\v1.0;c:\WINDOWS\system32\WindowsPowerShell\v1.0;c:\Program Files\Intel\WiFi\bin\;c:\Program Files\Windows Imaging\;c:\Program Files\Microsoft SQL Server\100\Tools\Binn\;c:\Program Files\Microsoft SQL Server\100\DTS\Binn\;c:\Program Files\TortoiseSVN\bin'
# On branch My_Branch
# Your branch is ahead of 'FlashDrive/My_Branch' by 8 commits.
#
nothing to commit (working directory clean)

As you can see, this is quite difficult to glance at (especially when the output is wrapped) and see what the output of 'git status'. In addition the name of each submodule is not shown so I have no way of knowing which submodule each section of output refers to.

Any help is appreciated! Thanks!

Rotsiser Mho
  • 551
  • 2
  • 5
  • 19

1 Answers1

3

You fail to mention exactly what it is you want shown...

 git submodule foreach -q git ls-files -m 

would go a long way at showing just the modified files, for example. Other options include

 git submodule foreach -q git diff --shortstat --staged # staged
 git submodule foreach -q git diff --shortstat          # unstaged
 git submodule foreach -q git diff --shortstat HEAD     # staged AND unstaged

You could write a silly small script in the following vein:

 #!/bin/sh
 echo "$(basename .) $(git branch)"

To show just what you want using the submodule directory name for easier identification.

In case you couldn't work it out from the above ideas: don't go and try to parse output that wasn't designed for machine consumption. Git has a very rich set of subcommands that can help you out in a better way.

GBegen
  • 6,107
  • 3
  • 31
  • 52
sehe
  • 374,641
  • 47
  • 450
  • 633
  • Turns out the %PATH% mess is a bug in msysGit that was fixed with 1.7.7. I'll take a look at those commands. Thanks! – Rotsiser Mho Nov 07 '11 at 16:44