Reputation: 167
We have a considerable quantity of submodules and we would like to go through all of them using git submodule foreach git <command>
.
What happens is that 1 or 2 of these submodules do not need these command to be used on them, so I was wondering if there could be a way to avoid looping these submodules previously specified.
Upvotes: 0
Views: 237
Reputation: 487725
... I was wondering if there could be a way to avoid looping these submodules previously specified.
No, there is not. But git submodule foreach
runs an arbitrary shell command, with some variables exported, as described in the documentation:
foreach [--recursive] <command>
Evaluates an arbitrary shell command in each checked out submodule. The command has access to the variables
$name
,$sm_path
,$displaypath
,$sha1
and$toplevel
:$name
is the name of the relevant submodule section in.gitmodules
,$sm_path
is the path of the submodule as recorded in the immediate superproject,$displaypath
contains the relative path from the current working directory to the submodules root directory,$sha1
is the commit as recorded in the immediate superproject, and$toplevel
is the absolute path to the top-level of the immediate superproject. Note that to avoid conflicts with$PATH
on Windows, the$path
variable is now a deprecated synonym of$sm_path
variable. ...
(I made some minor formatting-directive changes here but the text should match up, more or less. Your Git version may have the older $path
name rather than $sm_path
, depending on the age of your Git. Check your Git's documentation to be sure: git help submodule
will print out the above, as part of the full documentation.)
Since you have access to all of this information, use it. Pick whichever is simplest to check for the situation you have and skip executing commands that do not apply. Don't just blindly run git foo
; use if somecondition; then git foo; fi
or similar.
Upvotes: 2