Corno
Corno

Reputation: 5396

how can I find out if a git submodule has new commits

We have quite a few repositories with submodules and we would like to report which submodules are candidates for upgrading because the repository they refer to has new commits. Is there a way to do this without changing the currently checked out version?

basically there are 3 different commits that we would like to know about;
1) the commit to which origin's containing repository is pointing to
2) the commit to which the local containing repository is pointing to (this might be different from 1 because of a manual pull of the submodule
3) the head of the submodule repository.

If local is behind origin we would like to do a submodule update.
If local is ahead origin, we don't want to do a submodule update because it is probably changed by the developer.
If local is behind the head of the submodule repository, we would like to get a warning.

Upvotes: 1

Views: 583

Answers (1)

twalberg
twalberg

Reputation: 62379

It's a bit verbose, but you can use awk, sed, etc. to prune it down to the pertinent information, but I would start with git submodule foreach git remote show or git submodule foreach git fetch; git submodule foreach git log master..origin/master. That should provide enough information to build a script to do the automatic updates, etc.

Upvotes: 1

Related Questions