This is taken from the manual: git help submodule : foreach Evaluates an arbitrary shell command in each checked out submodule. The command has access to the variables $name, $path, $sha1 and $toplevel: $name is the name of the relevant submodule section in .
This is because of some major drawbacks around git submodules, such as being locked to a specific version of the outer repo, the lacking of effective merge management, and the general notion that the Git repository itself doesn't really know it's now a multi-module repository.
Git submodules may look powerful or cool upfront, but for all the reasons above it is a bad idea to share code using submodules, especially when the code changes frequently. It will be much worse when you have more and more developers working on the same repos.
No, you don't need to add your submodule to your . gitignore : what the parent will see from your submodule is a gitlink (a special entry, mode 160000 ). That means: any change directly made in a submodule needs to be followed by a commit in the parent directory.
Just make your command always return a 0
code like so:
git submodule foreach 'npm install || :'
This is taken from the manual: git help submodule
:
foreach
Evaluates an arbitrary shell command in each checked out submodule.
The command has access to the variables $name, $path, $sha1 and
$toplevel: $name is the name of the relevant submodule section in
.gitmodules, $path is the name of the submodule directory relative
to the superproject, $sha1 is the commit as recorded in the
superproject, and $toplevel is the absolute path to the top-level
of the superproject. Any submodules defined in the superproject but
not checked out are ignored by this command. Unless given --quiet,
foreach prints the name of each submodule before evaluating the
command. If --recursive is given, submodules are traversed
recursively (i.e. the given shell command is evaluated in nested
submodules as well). A non-zero return from the command in any
submodule causes the processing to terminate. This can be
overridden by adding || : to the end of the command.
As an example, git submodule foreach 'echo $path `git rev-parse
HEAD`' will show the path and currently checked out commit for each
submodule.
The command :
from help :
in bash
:
:: :
Null command.
No effect; the command does nothing.
Exit Status:
Always succeeds.
Always succeeds :)
You could see this topic.
I don't use GIT, but if you can locate the .gitmodules files, it may be easy to loop for each submodules :
<command to find all of your submodules>|while read; do
# ... (default use $REPLY as an item)
done
Or :
while read; do
# ...
done <<< "$(command to find all of your submodules)"
See this reminder on how to read a command output with a loop in Bash.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With