juanleon
juanleon

Reputation: 9380

How to know submodules in a branch without checking it out

Is there any programmatic way of finding out what submodules there are in a non-cheched-out commit? Basically, I would like to be able to do a git submodule status <commit> (sadly that option does not exist, at least in 1.9.7.5)

I can think of two alternatives; none of them seems elegant enough:

  1. git submodule summary -n 1 commit; then parse output and deduce the differences in submodules with git submodule status

  2. Get the content of the file ".gitmodules" at that specific commit, and then parse it

Any simpler solution?

Upvotes: 0

Views: 94

Answers (2)

twalberg
twalberg

Reputation: 62379

Something like this should work:

git ls-tree -r <commit> | awk '$2 == "commit"'

Although that only tells you the path to where the submodule is attached and the corresponding commit that should be checked out there. If you want to get the URL or other information, you'll probably have to parse the .gitmodules file from that commit, as you mentioned.

Upvotes: 3

Andrew C
Andrew C

Reputation: 14843

could you use a second index with GIT_INDEX_FILE and then run git submodule status --cached?

I don't use submodules so not 100% sure the syntax will work

git read-tree --index-output=$tmp_index $branch
GIT_INDEX_FILE=$tmp_index git submodule status --cached

Upvotes: 0

Related Questions