git/list[1] front-page[2] threads[3] people[4] search[5] about
 

submodule update --force

From
SZStefan Zager <szager@google.com>
Date
May 9, 2012, 23:55 UTC
Message-ID
<CAHOQ7J9xCYL=x=_nbq-3ksC2nF7L0=kxu9JX6M60xM-Bxmyfag@mail.gmail.com>
In-Reply-To
<CAHOQ7J8r4m2rz57BdkM9CADHdHE1yDFwExyF87u=DCEXjqzcqw@mail.gmail.com>

I have a situation where I have a full source tree -- top-level repository and all submodules -- generated via `git clone -n`.  So, the directory structure and .git directories are intact, but no actual source files have been checked out.

If I run `git submodule update` from the top level, some submodules get checked out, but not others.  Weird.

Root cause is in the cmd_update function in git-submodule.sh, which does essentially this:

sha1 = submodule revision as registered in top-level module subsha1 = HEAD revision in submodule checkout

if test "$subsha1" != "$sha1"
then
    git checkout $sha1
fi

In the submodule checkouts, HEAD is refs/heads/master.  In *some* of the submodules, the revision registered in the top-level repository is the same as HEAD.  So, for those submodules, `git submodule update` run from the top level is a no-op, because $sha1 = $subsha1.  That's true even though there are no actual source files checked out in the submodule.

For other submodules, $sha1 != $subsha1, and `git submodule update` checks out the source code as expected.

Confusing!
According to the docs for git-submodule:
       -f, --force
           This option is only valid for add and update commands. When
running add, allow adding an otherwise ignored
           submodule path. When running update, throw away local
changes in submodules when switching to a different
           commit.
I'd like to propose amending the documentation thusly:
According to the docs:
       -f, --force
           This option is only valid for add and update commands. When
running add, allow adding an otherwise ignored
           submodule path. When running update, throw away local
changes in submodules when switching to a different
           commit; if not switching to a different commit, a checkout
to HEAD will still be run.
... and here's the patch to implement it:
diff --git a/git-submodule.sh b/git-submodule.sh
index 64a70d6..8b045d9 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -536,7 +536,7 @@ Maybe you want to use 'update --init'?")"
                        die "$(eval_gettext "Unable to find current
revision in submodule path '\$sm_path'")"
                fi

-               if test "$subsha1" != "$sha1"
+               if test "$subsha1" != "$sha1" -o -n "$force"
                then
                        subforce=$force
                        # If we don't already have a -f flag and the
submodule has never been checked out



Thoughts?

Thanks,

Stefan
Next: Junio C Hamano
Message 1 of 12 in “submodule update --force”
  1. Stefan ZagerMay 9, 2012
  2. Junio C HamanoMay 10, 2012
  3. Junio C HamanoMay 10, 2012
  4. Stefan ZagerMay 10, 2012
  5. Junio C HamanoMay 10, 2012
  6. Heiko VoigtMay 10, 2012
  7. Phil HordMay 11, 2012
  8. Heiko VoigtMay 14, 2012
  9. Stefan ZagerMay 14, 2012
  10. Heiko VoigtMay 14, 2012
  11. Stefan ZagerMay 14, 2012
  12. Heiko VoigtMay 14, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.