I would strongly recommend parsing the .gitmodules
file directly is generally safer and much faster than git submodule status
. This file can be parsed using git config
to ensure that all parsing edge cases are handled appropriately -- formatting, whitespace, comments, etc:
git ls-files | grep -Fxvf <(git config --file .gitmodules --name-only --get-regexp path | cut -d '.' -f2-)
Alternatively, the file can be parsed directly so long as the regex is designed so that it won't match submodules which have been commended out via #
:
git ls-files | grep -Fxvf <(grep "^\s*\[submodule " .gitmodules | cut -d '"' -f2)
Note that git submodule status
has an output format that makes it difficult to correctly to parse via cut
. The two main drawbacks are:
the field of the filename will change depending on if the module is initialized or not
the filename is not delimited by tab \t
, and it isn't the last thing on the line, so filenames with spaces cannot be handled correctly.