Add conditional logic after "git subodule foreach"

I am working on a script to update submodules for various projects in a CI environment. A single script has to take care of three cases:

  • A project that always needs a submodule master branch.
  • A project that references a specific branch of a submodule.
  • A project that references a specific commit of a submodule.

Is it possible to create this single script to handle updating a submodule from the parent project for all these different cases?

git submodule foreach git pull

will handle cases 1 and 2, but not 3.

git submodule foreach git pull origin master

will handle 1 as well as 3 in a sense, since it won't fail.

Is it possible to add conditional logic after the foreach so that I can update all submodules correctly? Or am I trying to fix the problem wrong? Any help would be appreciated!

+3


source to share


1 answer


You don't need to explicitly pull: you can configure the submodule to indicate the branch to update.
See " git tracking submodules of the latest ".

And you can convert the existing submodule to add this branch information.
See " git submodules: specify branch / tag ".



From there, a simple command will take care of you:

git submodule update --recursive --remote

      

+3


source







All Articles