git submodule status shows wrong tag/branch
Asked Answered
S

1

9

When I run the command git submodule status, I see references to tags from months or even years ago. Everything else works fine (the code checks out what I expect it to, and there is no other weird behaviour).

The issue is that this one command displaying it incorrectly. Everything works fine. git submodule update always gets what I expect, and I frequently update the submodules with git add and git push.

username:~/src/main (master)$ git submodule status
 3f786850e387550fdab836ed7e6dc881de23001b module0 (old-tag-1234-g8f123456)
 89e6c98d92887913cadf06b2adb97f26cde4849b module1 (years-old-tag-4321-g12f4567890)
 2b66fd261ee5c6cfc8de7fa466bab600bcfe4f69 module2 (heads/master)
 e983f374794de9c64e3d1c1de1d490c0756eeeff module3 (heads/master)

This is strange, because ALL of my submodules have the master branch checked out. I would expect this command to show me heads/master for all 4 of the modules.

username:~/src/main/module0 (master)$ git status 
On branch master
Your branch is up to date with 'origin/master'.

...

username:~/src/main/module3 (master)$ git status 
On branch master
Your branch is up to date with 'origin/master'.

These submodules are properly referenced too - a git submodule update does not result in any changes to them. This is a repository updated dozens of times daily by dozens of people - There is zero chance that we're accidentally using code from 3 years ago, or forgot to update it.

To further emphasise: The issue is that this one command displaying it incorrectly. Everything works fine

Can anyone suggest reason's why? I suspect this might be something to do with needing to do a update-ref for everything, or some kind of stale refs in ~/src/main/.git/modules/module0/info/refs

Smew answered 26/10, 2021 at 23:28 Comment(3)
It's not wrong, it's just not what you want. (Well, we can easily define that as "wrong", and then it is wrong. 😀 But...) What git submodule status is doing is running git describe in each submodule. That's git describe, not git describe --all. So each submodule Git is not looking at any of the branch names, and won't "describe" the submodule as master, because that's a branch name and git describe uses annotated tags.Towline
There's no way to make git submodule status use git describe --all. You can however use git submodule foreach to run git describe --all in each submodule. (Based on the heads/master for two of them, git submodule status must be using --always, which falls back on branch names when there are no tags. Would be nice if one could control this easier...)Towline
Recommend converting this comment to an answer. Its a good question & answer. IMO git submodule status should behave like this answer to comply with the principal of least surprise. I have had this question and others have come to me asking the same.Grantee
M
1

I just ran into the same head scratcher after updating my clone of the Pico C/C++ SDK to the latest commits on the master branch. Here is my solution based on the suggestions from the comments.

Standard answer from git submodule status implied that the submodule btstack got downgraded by the update

$ git submodule status
 72ef1732c954d938091467961e41f4aa9b976b34 lib/btstack (v1.4-2371-g72ef1732c)
 8ef38a6d32c54f850bff8f189bdca19ded33792a lib/cyw43-driver (v1.0.1)
 239918ccc173cb2c2a62f41a40fd893f57faf1d6 lib/lwip (STABLE-2_1_0_RELEASE-548-g239918cc)
 a77287f8fa6b76f74984121fdafc8563147435c8 lib/mbedtls (v2.28.1-36-ga77287f8f)
 86c416d4c0fb38432460b3e11b08b9de76941bf5 lib/tinyusb (0.15.0)

Solution using git submodule foreach revealed the actual truth

(NOTE assumes that the reader is using a *NIX shell like bash)

$ git submodule foreach --quiet 'echo "" $(git rev-list -n1 HEAD) $sm_path $(git describe --all | sed "s,^tags/,(,;s/$/)/")'
 72ef1732c954d938091467961e41f4aa9b976b34 lib/btstack (v1.5.6.1-1-g72ef1732c)
 8ef38a6d32c54f850bff8f189bdca19ded33792a lib/cyw43-driver (v1.0.1)
 239918ccc173cb2c2a62f41a40fd893f57faf1d6 lib/lwip (STABLE-2_1_0_RELEASE-548-g239918cc)
 a77287f8fa6b76f74984121fdafc8563147435c8 lib/mbedtls (v2.28.1-36-ga77287f8f)
 86c416d4c0fb38432460b3e11b08b9de76941bf5 lib/tinyusb (0.15.0)

The addition of sed is of course only sugar coating to match the outputs of the commands.

EDIT

To save the reader from quoting hell. the same thing as git alias (SubModuleStatus) for inclusion in ~/.gitconfig:

[alias]
...
   sms = submodule foreach --quiet 'echo \"\" $(git rev-list -n1 HEAD) $sm_path $(git describe --all | sed -e s,^tags/,\\(, -e s/$/\\)/)'
...
$ git sms
 72ef1732c954d938091467961e41f4aa9b976b34 lib/btstack (v1.5.6.1-1-g72ef1732c)
 8ef38a6d32c54f850bff8f189bdca19ded33792a lib/cyw43-driver (v1.0.1)
 239918ccc173cb2c2a62f41a40fd893f57faf1d6 lib/lwip (STABLE-2_1_0_RELEASE-548-g239918cc)
 a77287f8fa6b76f74984121fdafc8563147435c8 lib/mbedtls (v2.28.1-36-ga77287f8f)
 86c416d4c0fb38432460b3e11b08b9de76941bf5 lib/tinyusb (0.15.0)
Manatarms answered 17/8, 2023 at 7:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.